Skip to content

Commit

Permalink
Add optionalFields into OperandConfig, to conditionally prune fields …
Browse files Browse the repository at this point in the history
…based on matchExpressions (#1085)

Signed-off-by: Daniel Fan <[email protected]>
  • Loading branch information
Daniel-Fan authored Sep 30, 2024
1 parent f611358 commit c1be25c
Show file tree
Hide file tree
Showing 10 changed files with 889 additions and 11 deletions.
75 changes: 75 additions & 0 deletions api/v1alpha1/operandconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,61 @@ type ConfigResource struct {
// OwnerReferences is the list of owner references.
// +optional
OwnerReferences []OwnerReference `json:"ownerReferences,omitempty"`
// OptionalFields is the list of fields that could be updated additionally.
// +optional
OptionalFields []OptionalField `json:"optionalFields,omitempty"`
}

// +kubebuilder:pruning:PreserveUnknownFields
// OptionalField defines the optional field for the resource.
type OptionalField struct {
// Path is the json path of the field.
Path string `json:"path"`
// Operation is the operation of the field.
Operation Operation `json:"operation"`
// MatchExpressions is the match expression of the field.
// +optional
MatchExpressions []MatchExpression `json:"matchExpressions,omitempty"`
// ValueFrom is the field value from the object
// +optional
ValueFrom *ValueFrom `json:"valueFrom,omitempty"`
}

// +kubebuilder:pruning:PreserveUnknownFields
// MatchExpression defines the match expression of the field.
type MatchExpression struct {
// Key is the key of the field.
Key string `json:"key"`
// Operator is the operator of the field.
Operator ExpressionOperator `json:"operator"`
// Values is the values of the field.
// +optional
Values []string `json:"values"`
// ObjectRef is the reference of the object.
// +optional
ObjectRef *ObjectRef `json:"objectRef,omitempty"`
}

// ObjectRef defines the reference of the object.
type ObjectRef struct {
// APIVersion is the version of the object.
APIVersion string `json:"apiVersion"`
// Kind is the kind of the object.
Kind string `json:"kind"`
// Name is the name of the object.
Name string `json:"name"`
// Namespace is the namespace of the object.
// +optional
Namespace string `json:"namespace"`
}

// ValueFrom defines the field value from the object.
type ValueFrom struct {
// Path is the json path of the field.
Path string `json:"path"`
// ObjectRef is the reference of the object.
// +optional
ObjectRef *ObjectRef `json:"objectRef,omitempty"`
}

type OwnerReference struct {
Expand Down Expand Up @@ -161,6 +216,26 @@ const (
ServiceNone ServicePhase = ""
)

// Operation defines the operation of the field.
type Operation string

// Operation type.
const (
OperationAdd Operation = "add"
OperationRemove Operation = "remove"
)

// Operator defines the operator type.
type ExpressionOperator string

// Operator type.
const (
OperatorIn ExpressionOperator = "In"
OperatorNotIn ExpressionOperator = "NotIn"
OperatorExists ExpressionOperator = "Exists"
OperatorDoesNotExist ExpressionOperator = "DoesNotExist"
)

// GetService obtains the service definition with the operand name.
func (r *OperandConfig) GetService(operandName string) *ConfigService {
for _, s := range r.Spec.Services {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ metadata:
categories: Developer Tools, Monitoring, Logging & Tracing, Security
certified: "false"
containerImage: icr.io/cpopen/odlm:latest
createdAt: "2024-08-27T18:18:40Z"
createdAt: "2024-09-28T19:55:35Z"
description: The Operand Deployment Lifecycle Manager provides a Kubernetes CRD-based API to manage the lifecycle of operands.
nss.operator.ibm.com/managed-operators: ibm-odlm
olm.skipRange: '>=1.2.0 <4.3.6'
Expand Down Expand Up @@ -568,6 +568,12 @@ spec:
spec:
clusterPermissions:
- rules:
- apiGroups:
- apiextensions.k8s.io
resources:
- customresourcedefinitions
verbs:
- get
- apiGroups:
- operator.ibm.com
resources:
Expand Down
100 changes: 100 additions & 0 deletions bundle/manifests/operator.ibm.com_operandconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,106 @@ spec:
namespace:
description: Namespace is the namespace of the resource.
type: string
optionalFields:
description: OptionalFields is the list of fields that
could be updated additionally.
items:
description: OptionalField defines the optional field
for the resource.
properties:
matchExpressions:
description: MatchExpressions is the match expression
of the field.
items:
description: MatchExpression defines the match
expression of the field.
properties:
key:
description: Key is the key of the field.
type: string
objectRef:
description: ObjectRef is the reference of
the object.
properties:
apiVersion:
description: APIVersion is the version
of the object.
type: string
kind:
description: Kind is the kind of the object.
type: string
name:
description: Name is the name of the object.
type: string
namespace:
description: Namespace is the namespace
of the object.
type: string
required:
- apiVersion
- kind
- name
type: object
operator:
description: Operator is the operator of the
field.
type: string
values:
description: Values is the values of the field.
items:
type: string
type: array
required:
- key
- operator
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
operation:
description: Operation is the operation of the field.
type: string
path:
description: Path is the json path of the field.
type: string
valueFrom:
description: ValueFrom is the field value from the
object
properties:
objectRef:
description: ObjectRef is the reference of the
object.
properties:
apiVersion:
description: APIVersion is the version of
the object.
type: string
kind:
description: Kind is the kind of the object.
type: string
name:
description: Name is the name of the object.
type: string
namespace:
description: Namespace is the namespace
of the object.
type: string
required:
- apiVersion
- kind
- name
type: object
path:
description: Path is the json path of the field.
type: string
required:
- path
type: object
required:
- operation
- path
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
ownerReferences:
description: OwnerReferences is the list of owner references.
items:
Expand Down
100 changes: 100 additions & 0 deletions config/crd/bases/operator.ibm.com_operandconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,106 @@ spec:
namespace:
description: Namespace is the namespace of the resource.
type: string
optionalFields:
description: OptionalFields is the list of fields that
could be updated additionally.
items:
description: OptionalField defines the optional field
for the resource.
properties:
matchExpressions:
description: MatchExpressions is the match expression
of the field.
items:
description: MatchExpression defines the match
expression of the field.
properties:
key:
description: Key is the key of the field.
type: string
objectRef:
description: ObjectRef is the reference of
the object.
properties:
apiVersion:
description: APIVersion is the version
of the object.
type: string
kind:
description: Kind is the kind of the object.
type: string
name:
description: Name is the name of the object.
type: string
namespace:
description: Namespace is the namespace
of the object.
type: string
required:
- apiVersion
- kind
- name
type: object
operator:
description: Operator is the operator of the
field.
type: string
values:
description: Values is the values of the field.
items:
type: string
type: array
required:
- key
- operator
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
operation:
description: Operation is the operation of the field.
type: string
path:
description: Path is the json path of the field.
type: string
valueFrom:
description: ValueFrom is the field value from the
object
properties:
objectRef:
description: ObjectRef is the reference of the
object.
properties:
apiVersion:
description: APIVersion is the version of
the object.
type: string
kind:
description: Kind is the kind of the object.
type: string
name:
description: Name is the name of the object.
type: string
namespace:
description: Namespace is the namespace
of the object.
type: string
required:
- apiVersion
- kind
- name
type: object
path:
description: Path is the json path of the field.
type: string
required:
- path
type: object
required:
- operation
- path
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
ownerReferences:
description: OwnerReferences is the list of owner references.
items:
Expand Down
6 changes: 6 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ kind: ClusterRole
metadata:
name: operand-deployment-lifecycle-manager
rules:
- apiGroups:
- apiextensions.k8s.io
resources:
- customresourcedefinitions
verbs:
- get
- apiGroups:
- operator.ibm.com
resources:
Expand Down
1 change: 1 addition & 0 deletions controllers/operandrequest/operandrequest_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type clusterObjects struct {

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

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

0 comments on commit c1be25c

Please sign in to comment.