Skip to content

Commit c1be25c

Browse files
authored
Add optionalFields into OperandConfig, to conditionally prune fields based on matchExpressions (#1085)
Signed-off-by: Daniel Fan <[email protected]>
1 parent f611358 commit c1be25c

10 files changed

+889
-11
lines changed

api/v1alpha1/operandconfig_types.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,61 @@ type ConfigResource struct {
7979
// OwnerReferences is the list of owner references.
8080
// +optional
8181
OwnerReferences []OwnerReference `json:"ownerReferences,omitempty"`
82+
// OptionalFields is the list of fields that could be updated additionally.
83+
// +optional
84+
OptionalFields []OptionalField `json:"optionalFields,omitempty"`
85+
}
86+
87+
// +kubebuilder:pruning:PreserveUnknownFields
88+
// OptionalField defines the optional field for the resource.
89+
type OptionalField struct {
90+
// Path is the json path of the field.
91+
Path string `json:"path"`
92+
// Operation is the operation of the field.
93+
Operation Operation `json:"operation"`
94+
// MatchExpressions is the match expression of the field.
95+
// +optional
96+
MatchExpressions []MatchExpression `json:"matchExpressions,omitempty"`
97+
// ValueFrom is the field value from the object
98+
// +optional
99+
ValueFrom *ValueFrom `json:"valueFrom,omitempty"`
100+
}
101+
102+
// +kubebuilder:pruning:PreserveUnknownFields
103+
// MatchExpression defines the match expression of the field.
104+
type MatchExpression struct {
105+
// Key is the key of the field.
106+
Key string `json:"key"`
107+
// Operator is the operator of the field.
108+
Operator ExpressionOperator `json:"operator"`
109+
// Values is the values of the field.
110+
// +optional
111+
Values []string `json:"values"`
112+
// ObjectRef is the reference of the object.
113+
// +optional
114+
ObjectRef *ObjectRef `json:"objectRef,omitempty"`
115+
}
116+
117+
// ObjectRef defines the reference of the object.
118+
type ObjectRef struct {
119+
// APIVersion is the version of the object.
120+
APIVersion string `json:"apiVersion"`
121+
// Kind is the kind of the object.
122+
Kind string `json:"kind"`
123+
// Name is the name of the object.
124+
Name string `json:"name"`
125+
// Namespace is the namespace of the object.
126+
// +optional
127+
Namespace string `json:"namespace"`
128+
}
129+
130+
// ValueFrom defines the field value from the object.
131+
type ValueFrom struct {
132+
// Path is the json path of the field.
133+
Path string `json:"path"`
134+
// ObjectRef is the reference of the object.
135+
// +optional
136+
ObjectRef *ObjectRef `json:"objectRef,omitempty"`
82137
}
83138

84139
type OwnerReference struct {
@@ -161,6 +216,26 @@ const (
161216
ServiceNone ServicePhase = ""
162217
)
163218

219+
// Operation defines the operation of the field.
220+
type Operation string
221+
222+
// Operation type.
223+
const (
224+
OperationAdd Operation = "add"
225+
OperationRemove Operation = "remove"
226+
)
227+
228+
// Operator defines the operator type.
229+
type ExpressionOperator string
230+
231+
// Operator type.
232+
const (
233+
OperatorIn ExpressionOperator = "In"
234+
OperatorNotIn ExpressionOperator = "NotIn"
235+
OperatorExists ExpressionOperator = "Exists"
236+
OperatorDoesNotExist ExpressionOperator = "DoesNotExist"
237+
)
238+
164239
// GetService obtains the service definition with the operand name.
165240
func (r *OperandConfig) GetService(operandName string) *ConfigService {
166241
for _, s := range r.Spec.Services {

bundle/manifests/operand-deployment-lifecycle-manager.clusterserviceversion.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ metadata:
129129
categories: Developer Tools, Monitoring, Logging & Tracing, Security
130130
certified: "false"
131131
containerImage: icr.io/cpopen/odlm:latest
132-
createdAt: "2024-08-27T18:18:40Z"
132+
createdAt: "2024-09-28T19:55:35Z"
133133
description: The Operand Deployment Lifecycle Manager provides a Kubernetes CRD-based API to manage the lifecycle of operands.
134134
nss.operator.ibm.com/managed-operators: ibm-odlm
135135
olm.skipRange: '>=1.2.0 <4.3.6'
@@ -568,6 +568,12 @@ spec:
568568
spec:
569569
clusterPermissions:
570570
- rules:
571+
- apiGroups:
572+
- apiextensions.k8s.io
573+
resources:
574+
- customresourcedefinitions
575+
verbs:
576+
- get
571577
- apiGroups:
572578
- operator.ibm.com
573579
resources:

bundle/manifests/operator.ibm.com_operandconfigs.yaml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,106 @@ spec:
109109
namespace:
110110
description: Namespace is the namespace of the resource.
111111
type: string
112+
optionalFields:
113+
description: OptionalFields is the list of fields that
114+
could be updated additionally.
115+
items:
116+
description: OptionalField defines the optional field
117+
for the resource.
118+
properties:
119+
matchExpressions:
120+
description: MatchExpressions is the match expression
121+
of the field.
122+
items:
123+
description: MatchExpression defines the match
124+
expression of the field.
125+
properties:
126+
key:
127+
description: Key is the key of the field.
128+
type: string
129+
objectRef:
130+
description: ObjectRef is the reference of
131+
the object.
132+
properties:
133+
apiVersion:
134+
description: APIVersion is the version
135+
of the object.
136+
type: string
137+
kind:
138+
description: Kind is the kind of the object.
139+
type: string
140+
name:
141+
description: Name is the name of the object.
142+
type: string
143+
namespace:
144+
description: Namespace is the namespace
145+
of the object.
146+
type: string
147+
required:
148+
- apiVersion
149+
- kind
150+
- name
151+
type: object
152+
operator:
153+
description: Operator is the operator of the
154+
field.
155+
type: string
156+
values:
157+
description: Values is the values of the field.
158+
items:
159+
type: string
160+
type: array
161+
required:
162+
- key
163+
- operator
164+
type: object
165+
x-kubernetes-preserve-unknown-fields: true
166+
type: array
167+
operation:
168+
description: Operation is the operation of the field.
169+
type: string
170+
path:
171+
description: Path is the json path of the field.
172+
type: string
173+
valueFrom:
174+
description: ValueFrom is the field value from the
175+
object
176+
properties:
177+
objectRef:
178+
description: ObjectRef is the reference of the
179+
object.
180+
properties:
181+
apiVersion:
182+
description: APIVersion is the version of
183+
the object.
184+
type: string
185+
kind:
186+
description: Kind is the kind of the object.
187+
type: string
188+
name:
189+
description: Name is the name of the object.
190+
type: string
191+
namespace:
192+
description: Namespace is the namespace
193+
of the object.
194+
type: string
195+
required:
196+
- apiVersion
197+
- kind
198+
- name
199+
type: object
200+
path:
201+
description: Path is the json path of the field.
202+
type: string
203+
required:
204+
- path
205+
type: object
206+
required:
207+
- operation
208+
- path
209+
type: object
210+
x-kubernetes-preserve-unknown-fields: true
211+
type: array
112212
ownerReferences:
113213
description: OwnerReferences is the list of owner references.
114214
items:

config/crd/bases/operator.ibm.com_operandconfigs.yaml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,106 @@ spec:
105105
namespace:
106106
description: Namespace is the namespace of the resource.
107107
type: string
108+
optionalFields:
109+
description: OptionalFields is the list of fields that
110+
could be updated additionally.
111+
items:
112+
description: OptionalField defines the optional field
113+
for the resource.
114+
properties:
115+
matchExpressions:
116+
description: MatchExpressions is the match expression
117+
of the field.
118+
items:
119+
description: MatchExpression defines the match
120+
expression of the field.
121+
properties:
122+
key:
123+
description: Key is the key of the field.
124+
type: string
125+
objectRef:
126+
description: ObjectRef is the reference of
127+
the object.
128+
properties:
129+
apiVersion:
130+
description: APIVersion is the version
131+
of the object.
132+
type: string
133+
kind:
134+
description: Kind is the kind of the object.
135+
type: string
136+
name:
137+
description: Name is the name of the object.
138+
type: string
139+
namespace:
140+
description: Namespace is the namespace
141+
of the object.
142+
type: string
143+
required:
144+
- apiVersion
145+
- kind
146+
- name
147+
type: object
148+
operator:
149+
description: Operator is the operator of the
150+
field.
151+
type: string
152+
values:
153+
description: Values is the values of the field.
154+
items:
155+
type: string
156+
type: array
157+
required:
158+
- key
159+
- operator
160+
type: object
161+
x-kubernetes-preserve-unknown-fields: true
162+
type: array
163+
operation:
164+
description: Operation is the operation of the field.
165+
type: string
166+
path:
167+
description: Path is the json path of the field.
168+
type: string
169+
valueFrom:
170+
description: ValueFrom is the field value from the
171+
object
172+
properties:
173+
objectRef:
174+
description: ObjectRef is the reference of the
175+
object.
176+
properties:
177+
apiVersion:
178+
description: APIVersion is the version of
179+
the object.
180+
type: string
181+
kind:
182+
description: Kind is the kind of the object.
183+
type: string
184+
name:
185+
description: Name is the name of the object.
186+
type: string
187+
namespace:
188+
description: Namespace is the namespace
189+
of the object.
190+
type: string
191+
required:
192+
- apiVersion
193+
- kind
194+
- name
195+
type: object
196+
path:
197+
description: Path is the json path of the field.
198+
type: string
199+
required:
200+
- path
201+
type: object
202+
required:
203+
- operation
204+
- path
205+
type: object
206+
x-kubernetes-preserve-unknown-fields: true
207+
type: array
108208
ownerReferences:
109209
description: OwnerReferences is the list of owner references.
110210
items:

config/rbac/role.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ kind: ClusterRole
44
metadata:
55
name: operand-deployment-lifecycle-manager
66
rules:
7+
- apiGroups:
8+
- apiextensions.k8s.io
9+
resources:
10+
- customresourcedefinitions
11+
verbs:
12+
- get
713
- apiGroups:
814
- operator.ibm.com
915
resources:

controllers/operandrequest/operandrequest_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type clusterObjects struct {
6363

6464
//+kubebuilder:rbac:groups=operator.ibm.com,resources=certmanagers;auditloggings,verbs=get;delete
6565
//+kubebuilder:rbac:groups=operators.coreos.com,resources=catalogsources,verbs=get
66+
//+kubebuilder:rbac:groups=apiextensions.k8s.io,resources=customresourcedefinitions,verbs=get
6667

6768
//+kubebuilder:rbac:groups=*,namespace="placeholder",resources=*,verbs=create;delete;get;list;patch;update;watch
6869
//+kubebuilder:rbac:groups=operator.ibm.com,namespace="placeholder",resources=operandrequests;operandrequests/status;operandrequests/finalizers,verbs=get;list;watch;create;update;patch;delete

0 commit comments

Comments
 (0)