Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Add field to NooBaa's CR to override environment variables of pods #1510

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
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
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ TIME ?= time -p
ARCH ?= $(shell uname -m)

VERSION ?= $(shell go run cmd/version/main.go)
IMAGE ?= noobaa/noobaa-operator:$(VERSION)
IMAGE ?= nooverflow/noobaa-operator:$(VERSION)
DEV_IMAGE ?= noobaa/noobaa-operator-dev:$(VERSION)
REPO ?= github.com/noobaa/noobaa-operator
CATALOG_IMAGE ?= noobaa/noobaa-operator-catalog:$(VERSION)
CATALOG_IMAGE ?= nooverflow/noobaa-operator-catalog:$(VERSION)
BUNDLE_IMAGE ?= noobaa/noobaa-operator-bundle:$(VERSION)
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -279,7 +279,7 @@ test-util: vendor
@echo "✅ test-util"
.PHONY: test-util

test-validations:
test-validations:
ginkgo -v pkg/validations
@echo "✅ test-validations"
.PHONY: test-validations
Expand Down
20 changes: 20 additions & 0 deletions deploy/crds/noobaa.io_noobaas.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1573,6 +1573,26 @@ spec:
type: object
type: object
type: object
envVariablesOverride:
description: Override variables for all pods managed by NooBaa's operator
type: object
properties:
core:
description: List of environment variables to set in the Core statefulset containers.
items:
description: EnvVar represents an environment variable present in a Container.
x-kubernetes-preserve-unknown-fields: true
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
endpoint:
description: List of environment variables to set in the Endpoint deployment containers.
items:
description: EnvVar represents an environment variable present in a Container.
x-kubernetes-preserve-unknown-fields: true
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
externalPgSSLRequired:
description: ExternalPgSSLRequired (optional) holds an optional boolean
to force ssl connections to the external Postgres DB
Expand Down
16 changes: 16 additions & 0 deletions pkg/apis/noobaa/v1alpha1/noobaa_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ type NooBaaSpec struct {
// +kubebuilder:validation:Enum=postgres
DBType DBTypes `json:"dbType,omitempty"`

// EnvVariablesOverride (optional) overrides the environment variables for all NooBaa's pods
// Can be used for exemple to add CONFIG_JS_ variables to modify core pod behaviour
// +optional
EnvVariablesOverride *EnvVariablesOverrideSpec `json:"envVariablesOverride,omitempty"`

// CoreResources (optional) overrides the default resource requirements for the server container
// +optional
CoreResources *corev1.ResourceRequirements `json:"coreResources,omitempty"`
Expand Down Expand Up @@ -245,6 +250,17 @@ type AutoscalerSpec struct {
PrometheusNamespace string `json:"prometheusNamespace,omitempty"`
}

// EnvVariablesOverrideSpec defines the env override structure for each component deploying pods (ex: StatefulSet)
type EnvVariablesOverrideSpec struct {
// Variables override for core statefulset
Core []corev1.EnvVar `json:"core,omitempty"`

// Variables override for endpoint deployment
Endpoint []corev1.EnvVar `json:"endpoint,omitempty"`
}



// BucketLoggingSpec defines the bucket logging configuration
type BucketLoggingSpec struct {
// LoggingType specifies the type of logging for the bucket
Expand Down
22 changes: 21 additions & 1 deletion pkg/bundle/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ spec:
status: {}
`

const Sha256_deploy_crds_noobaa_io_noobaas_yaml = "e862d263d097ed43f774784eaaf9a616967746b67608fadbe4ca71d93b220ab6"
const Sha256_deploy_crds_noobaa_io_noobaas_yaml = "db1c4c18af61b965669cff3e76227bbcbd8519ea9a9fdd41ad39fdc318806110"

const File_deploy_crds_noobaa_io_noobaas_yaml = `---
apiVersion: apiextensions.k8s.io/v1
Expand Down Expand Up @@ -3000,6 +3000,26 @@ spec:
type: object
type: object
type: object
envVariablesOverride:
description: Override variables for all pods managed by NooBaa's operator
type: object
properties:
core:
description: "List of environment variables to set in the Core statefulset containers."
items:
description: EnvVar represents an environment variable present in a Container.
x-kubernetes-preserve-unknown-fields: true
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
endpoint:
description: "List of environment variables to set in the Endpoint deployment containers."
items:
description: EnvVar represents an environment variable present in a Container.
x-kubernetes-preserve-unknown-fields: true
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
externalPgSSLRequired:
description: ExternalPgSSLRequired (optional) holds an optional boolean
to force ssl connections to the external Postgres DB
Expand Down
2 changes: 1 addition & 1 deletion pkg/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var Namespace = "noobaa"

// OperatorImage is the container image url built from https://github.com/noobaa/noobaa-operator
// it can be overridden for testing or different registry locations.
var OperatorImage = "noobaa/noobaa-operator:" + version.Version
var OperatorImage = "nooverflow/noobaa-operator:" + version.Version

// CosiSideCarImage is the container image url built from https://github.com/kubernetes-sigs/container-object-storage-interface-provisioner-sidecar
var CosiSideCarImage = "gcr.io/k8s-staging-sig-storage/objectstorage-sidecar/objectstorage-sidecar:v20221117-v0.1.0-22-g0e67387"
Expand Down
9 changes: 8 additions & 1 deletion pkg/system/phase2_creating.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ func (r *Reconciler) setDesiredCoreEnv(c *corev1.Container) {
}
util.MergeEnvArrays(&c.Env, &[]corev1.EnvVar{envVar});
}

}

// SetDesiredCoreApp updates the CoreApp as desired for reconciling
Expand Down Expand Up @@ -616,6 +615,14 @@ func (r *Reconciler) SetDesiredCoreApp() error {
util.MergeVolumeMountList(&c.VolumeMounts, &configMapVolumeMounts)
}
}

if r.NooBaa.Spec.EnvVariablesOverride != nil && r.NooBaa.Spec.EnvVariablesOverride.Core != nil {
// util.MergeEnvArrays will keep variables of the first array provided in
// arguments in case of a conflict, so we provide the override array first
// and then set the container Env array to the resulting merged array
util.MergeEnvArrays(&r.NooBaa.Spec.EnvVariablesOverride.Core, &c.Env);
c.Env = r.NooBaa.Spec.EnvVariablesOverride.Core;
}
}
if r.NooBaa.Spec.ImagePullSecret == nil {
podSpec.ImagePullSecrets =
Expand Down
7 changes: 7 additions & 0 deletions pkg/system/phase4_configuring.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,13 @@ func (r *Reconciler) SetDesiredDeploymentEndpoint() error {

r.DeploymentEndpoint.Spec.Template.Annotations["noobaa.io/configmap-hash"] = r.CoreAppConfig.Annotations["noobaa.io/configmap-hash"]

if r.NooBaa.Spec.EnvVariablesOverride != nil && r.NooBaa.Spec.EnvVariablesOverride.Endpoint != nil {
// util.MergeEnvArrays will keep variables of the first array provided in
// arguments in case of a conflict, so we provide the override array first
// and then set the container Env array to the resulting merged array
util.MergeEnvArrays(&r.NooBaa.Spec.EnvVariablesOverride.Endpoint, &c.Env);
c.Env = r.NooBaa.Spec.EnvVariablesOverride.Endpoint;
}
return r.setDesiredEndpointMounts(podSpec, c)
}
}
Expand Down