-
Notifications
You must be signed in to change notification settings - Fork 492
/
resources.go
31 lines (25 loc) · 919 Bytes
/
resources.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Copyright 2020 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package utils
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
k8stypes "k8s.io/apimachinery/pkg/types"
"github.com/juju/juju/caas/kubernetes/provider/constants"
)
// PurifyResource purifies read only fields before creating/updating the resource.
func PurifyResource(resource interface{ SetResourceVersion(string) }) {
resource.SetResourceVersion("")
}
func NewUIDPreconditions(uid k8stypes.UID) *metav1.Preconditions {
if uid == "" {
return nil
}
return &metav1.Preconditions{UID: &uid}
}
func NewPreconditionDeleteOptions(uid k8stypes.UID) metav1.DeleteOptions {
// TODO(caas): refactor all deleting single resource operation has this UID ensured precondition.
return metav1.DeleteOptions{
Preconditions: NewUIDPreconditions(uid),
PropagationPolicy: constants.DefaultPropagationPolicy(),
}
}