Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions api/bases/operator.openstack.org_openstacks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,72 @@ spec:
properties:
controllerManager:
properties:
env:
items:
properties:
name:
type: string
value:
type: string
valueFrom:
properties:
configMapKeyRef:
properties:
key:
type: string
name:
default: ""
type: string
optional:
type: boolean
required:
- key
type: object
x-kubernetes-map-type: atomic
fieldRef:
properties:
apiVersion:
type: string
fieldPath:
type: string
required:
- fieldPath
type: object
x-kubernetes-map-type: atomic
resourceFieldRef:
properties:
containerName:
type: string
divisor:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
resource:
type: string
required:
- resource
type: object
x-kubernetes-map-type: atomic
secretKeyRef:
properties:
key:
type: string
name:
default: ""
type: string
optional:
type: boolean
required:
- key
type: object
x-kubernetes-map-type: atomic
type: object
required:
- name
type: object
type: array
resources:
properties:
claims:
Expand Down
4 changes: 4 additions & 0 deletions api/operator/v1beta1/openstack_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ type ContainerSpec struct {
// Resources - Compute Resources for the service operator controller manager
// https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
Resources corev1.ResourceRequirements `json:"resources,omitempty"`

// +kubebuilder:validation:Optional
// Env - Environment variables for the container
Env []corev1.EnvVar `json:"env,omitempty"`
}

// OpenStackStatus defines the observed state of OpenStack
Expand Down
7 changes: 7 additions & 0 deletions api/operator/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions bindata/operator/rabbit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,26 @@ spec:
fieldPath: metadata.namespace
{{- range .RabbitmqOperator.Deployment.Manager.Env }}
- name: '{{ .Name }}'
{{- if .Value }}
value: '{{ .Value }}'
{{- end }}
{{- if .ValueFrom }}
valueFrom:
{{- if .ValueFrom.FieldRef }}
fieldRef:
fieldPath: '{{ .ValueFrom.FieldRef.FieldPath }}'
{{- end }}
{{- if .ValueFrom.ConfigMapKeyRef }}
configMapKeyRef:
name: '{{ .ValueFrom.ConfigMapKeyRef.Name }}'
key: '{{ .ValueFrom.ConfigMapKeyRef.Key }}'
{{- end }}
{{- if .ValueFrom.SecretKeyRef }}
secretKeyRef:
name: '{{ .ValueFrom.SecretKeyRef.Name }}'
key: '{{ .ValueFrom.SecretKeyRef.Key }}'
{{- end }}
{{- end }}
{{- end }}
image: {{ .RabbitmqOperator.Deployment.Manager.Image }}
name: operator
Expand Down
66 changes: 66 additions & 0 deletions config/crd/bases/operator.openstack.org_openstacks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,72 @@ spec:
properties:
controllerManager:
properties:
env:
items:
properties:
name:
type: string
value:
type: string
valueFrom:
properties:
configMapKeyRef:
properties:
key:
type: string
name:
default: ""
type: string
optional:
type: boolean
required:
- key
type: object
x-kubernetes-map-type: atomic
fieldRef:
properties:
apiVersion:
type: string
fieldPath:
type: string
required:
- fieldPath
type: object
x-kubernetes-map-type: atomic
resourceFieldRef:
properties:
containerName:
type: string
divisor:
anyOf:
- type: integer
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
resource:
type: string
required:
- resource
type: object
x-kubernetes-map-type: atomic
secretKeyRef:
properties:
key:
type: string
name:
default: ""
type: string
optional:
type: boolean
required:
- key
type: object
x-kubernetes-map-type: atomic
type: object
required:
- name
type: object
type: array
resources:
properties:
claims:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,13 @@ spec:
- description: TLS - overrides tls parameters for public endpoint
displayName: TLS
path: telemetry.aodhApiOverride.tls
- description: CloudKittyAPIOverride, provides the ability to override the generated
manifest of several child resources.
displayName: Cloud Kitty APIOverride
path: telemetry.cloudKittyApiOverride
- description: TLS - overrides tls parameters for public endpoint
displayName: TLS
path: telemetry.cloudKittyApiOverride.tls
- description: Enabled - Whether OpenStack Telemetry services should be deployed
and managed
displayName: Enabled
Expand Down
19 changes: 19 additions & 0 deletions config/operator/rabbit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,26 @@ spec:
fieldPath: metadata.namespace
{{- range .RabbitmqOperator.Deployment.Manager.Env }}
- name: '{{ .Name }}'
{{- if .Value }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we want the same in config/operator/managers.yaml for the other operator deployments?

value: '{{ .Value }}'
{{- end }}
{{- if .ValueFrom }}
valueFrom:
{{- if .ValueFrom.FieldRef }}
fieldRef:
fieldPath: '{{ .ValueFrom.FieldRef.FieldPath }}'
{{- end }}
{{- if .ValueFrom.ConfigMapKeyRef }}
configMapKeyRef:
name: '{{ .ValueFrom.ConfigMapKeyRef.Name }}'
key: '{{ .ValueFrom.ConfigMapKeyRef.Key }}'
{{- end }}
{{- if .ValueFrom.SecretKeyRef }}
secretKeyRef:
name: '{{ .ValueFrom.SecretKeyRef.Name }}'
key: '{{ .ValueFrom.SecretKeyRef.Key }}'
{{- end }}
{{- end }}
{{- end }}
image: {{ .RabbitmqOperator.Deployment.Manager.Image }}
name: operator
Expand Down
31 changes: 31 additions & 0 deletions internal/operator/override.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,42 @@ func SetOverrides(opOvr operatorv1beta1.OperatorSpec, op *Operator) {
op.Deployment.Manager.Resources.Requests.Memory = opOvr.ControllerManager.Resources.Requests.Memory().String()
}
}
if len(opOvr.ControllerManager.Env) > 0 {
op.Deployment.Manager.Env = mergeEnvVars(op.Deployment.Manager.Env, opOvr.ControllerManager.Env)
}
if len(opOvr.Tolerations) > 0 {
op.Deployment.Tolerations = mergeTolerations(op.Deployment.Tolerations, opOvr.Tolerations)
}
}

// mergeEnvVars merges custom environment variables with default environment variables.
// If a custom env var has the same name as a default one, it overrides the default.
// Otherwise, the custom env var is added to the list.
func mergeEnvVars(defaults, custom []corev1.EnvVar) []corev1.EnvVar {
if len(custom) == 0 {
return defaults
}

// Start with a copy of defaults
merged := make([]corev1.EnvVar, len(defaults))
copy(merged, defaults)

// For each custom env var, check if it should override a default one
for _, customEnv := range custom {
f := func(c corev1.EnvVar) bool {
return c.Name == customEnv.Name
}
idx := slices.IndexFunc(merged, f)
if idx >= 0 {
merged[idx] = customEnv
} else {
merged = append(merged, customEnv)
}
}

return merged
}

// mergeTolerations merges custom tolerations with default tolerations.
// If a custom toleration has the same key as a default one, it overrides the default.
// Otherwise, the custom toleration is added to the list.
Expand Down
Loading