You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ho...@apache.org on 2021/02/17 16:38:09 UTC
[lucene-solr-operator] branch main updated: Allow the definition of
multiple imagePullSecrets. (#216)
This is an automated email from the ASF dual-hosted git repository.
houston pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene-solr-operator.git
The following commit(s) were added to refs/heads/main by this push:
new 7cc1221 Allow the definition of multiple imagePullSecrets. (#216)
7cc1221 is described below
commit 7cc12213b45928efe03cdfd96d9f47756ac41204
Author: Jacob Ward <53...@users.noreply.github.com>
AuthorDate: Wed Feb 17 16:37:46 2021 +0000
Allow the definition of multiple imagePullSecrets. (#216)
---
api/v1beta1/common_types.go | 6 ++++++
config/crd/bases/solr.apache.org_solrclouds.yaml | 10 ++++++++++
.../solr.apache.org_solrprometheusexporters.yaml | 10 ++++++++++
controllers/controller_utils_test.go | 9 +++++++--
controllers/solrcloud_controller_test.go | 5 +++++
.../solrprometheusexporter_controller_test.go | 5 +++++
controllers/util/prometheus_exporter_util.go | 11 ++++++++---
controllers/util/solr_util.go | 15 ++++++++++++---
go.sum | 1 +
helm/solr-operator/crds/crds.yaml | 20 ++++++++++++++++++++
10 files changed, 84 insertions(+), 8 deletions(-)
diff --git a/api/v1beta1/common_types.go b/api/v1beta1/common_types.go
index 30df9a7..053d262 100644
--- a/api/v1beta1/common_types.go
+++ b/api/v1beta1/common_types.go
@@ -118,6 +118,12 @@ type PodOptions struct {
// These will run along with the init container that sets up the "solr.xml".
// +optional
InitContainers []corev1.Container `json:"initContainers,omitempty"`
+
+ // ImagePullSecrets to apply to the pod.
+ // These are for init/sidecarContainers in addition to the imagePullSecret defined for the
+ // solr image.
+ // +optional
+ ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"`
}
// ServiceOptions defines custom options for services
diff --git a/config/crd/bases/solr.apache.org_solrclouds.yaml b/config/crd/bases/solr.apache.org_solrclouds.yaml
index 2deb76f..91f117e 100644
--- a/config/crd/bases/solr.apache.org_solrclouds.yaml
+++ b/config/crd/bases/solr.apache.org_solrclouds.yaml
@@ -580,6 +580,16 @@ spec:
- name
type: object
type: array
+ imagePullSecrets:
+ description: ImagePullSecrets to apply to the pod. These are for init/sidecarContainers in addition to the imagePullSecret defined for the solr image.
+ items:
+ description: LocalObjectReference contains enough information to let you locate the referenced object inside the same namespace.
+ properties:
+ name:
+ description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?'
+ type: string
+ type: object
+ type: array
initContainers:
description: Additional init containers to run in the pod. These will run along with the init container that sets up the "solr.xml".
items:
diff --git a/config/crd/bases/solr.apache.org_solrprometheusexporters.yaml b/config/crd/bases/solr.apache.org_solrprometheusexporters.yaml
index de0572b..0c18854 100644
--- a/config/crd/bases/solr.apache.org_solrprometheusexporters.yaml
+++ b/config/crd/bases/solr.apache.org_solrprometheusexporters.yaml
@@ -509,6 +509,16 @@ spec:
- name
type: object
type: array
+ imagePullSecrets:
+ description: ImagePullSecrets to apply to the pod. These are for init/sidecarContainers in addition to the imagePullSecret defined for the solr image.
+ items:
+ description: LocalObjectReference contains enough information to let you locate the referenced object inside the same namespace.
+ properties:
+ name:
+ description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?'
+ type: string
+ type: object
+ type: array
initContainers:
description: Additional init containers to run in the pod. These will run along with the init container that sets up the "solr.xml".
items:
diff --git a/controllers/controller_utils_test.go b/controllers/controller_utils_test.go
index 1be3e71..3f87b68 100644
--- a/controllers/controller_utils_test.go
+++ b/controllers/controller_utils_test.go
@@ -531,8 +531,13 @@ var (
Operator: "Exists",
},
}
- testPriorityClass = "p4"
- extraVars = []corev1.EnvVar{
+ testPriorityClass = "p4"
+ testImagePullSecretName = "MAIN_SECRET"
+ testAdditionalImagePullSecrets = []corev1.LocalObjectReference{
+ {Name: "ADDITIONAL_SECRET_1"},
+ {Name: "ADDITIONAL_SECRET_2"},
+ }
+ extraVars = []corev1.EnvVar{
{
Name: "VAR_1",
Value: "VAL_1",
diff --git a/controllers/solrcloud_controller_test.go b/controllers/solrcloud_controller_test.go
index 1a8f2e8..340b5a3 100644
--- a/controllers/solrcloud_controller_test.go
+++ b/controllers/solrcloud_controller_test.go
@@ -174,6 +174,9 @@ func TestCustomKubeOptionsCloudReconcile(t *testing.T) {
Labels: map[string]string{"base": "here"},
},
Spec: solr.SolrCloudSpec{
+ SolrImage: &solr.ContainerImage{
+ ImagePullSecret: testImagePullSecretName,
+ },
Replicas: &replicas,
ZookeeperRef: &solr.ZookeeperRef{
ConnectionInfo: &solr.ZookeeperConnectionInfo{
@@ -194,6 +197,7 @@ func TestCustomKubeOptionsCloudReconcile(t *testing.T) {
ReadinessProbe: testProbeReadinessNonDefaults,
StartupProbe: testProbeStartup,
PriorityClassName: testPriorityClass,
+ ImagePullSecrets: testAdditionalImagePullSecrets,
},
StatefulSetOptions: &solr.StatefulSetOptions{
Annotations: testSSAnnotations,
@@ -278,6 +282,7 @@ func TestCustomKubeOptionsCloudReconcile(t *testing.T) {
assert.Equal(t, []string{"solr", "stop", "-p", "8983"}, statefulSet.Spec.Template.Spec.Containers[0].Lifecycle.PreStop.Exec.Command, "Incorrect pre-stop command")
testPodTolerations(t, testTolerations, statefulSet.Spec.Template.Spec.Tolerations)
assert.EqualValues(t, testPriorityClass, statefulSet.Spec.Template.Spec.PriorityClassName, "Incorrect Priority class name for Pod Spec")
+ assert.ElementsMatch(t, append(testAdditionalImagePullSecrets, corev1.LocalObjectReference{Name: testImagePullSecretName}), statefulSet.Spec.Template.Spec.ImagePullSecrets, "Incorrect imagePullSecrets")
// Check the update strategy
assert.EqualValues(t, appsv1.RollingUpdateStatefulSetStrategyType, statefulSet.Spec.UpdateStrategy.Type, "Incorrect statefulset update strategy")
diff --git a/controllers/solrprometheusexporter_controller_test.go b/controllers/solrprometheusexporter_controller_test.go
index ed9939e..9ad40e8 100644
--- a/controllers/solrprometheusexporter_controller_test.go
+++ b/controllers/solrprometheusexporter_controller_test.go
@@ -63,9 +63,13 @@ func TestMetricsReconcileWithoutExporterConfig(t *testing.T) {
Resources: resources,
SidecarContainers: extraContainers2,
InitContainers: extraContainers1,
+ ImagePullSecrets: testAdditionalImagePullSecrets,
},
},
ExporterEntrypoint: "/test/entry-point",
+ Image: &solr.ContainerImage{
+ ImagePullSecret: testImagePullSecretName,
+ },
},
}
@@ -124,6 +128,7 @@ func TestMetricsReconcileWithoutExporterConfig(t *testing.T) {
assert.Equal(t, len(extraVolumes), len(deployment.Spec.Template.Spec.Volumes), "Pod has wrong number of volumes")
assert.Equal(t, extraVolumes[0].Name, deployment.Spec.Template.Spec.Volumes[0].Name, "Additional Volume from podOptions not loaded into pod properly.")
assert.Equal(t, extraVolumes[0].Source, deployment.Spec.Template.Spec.Volumes[0].VolumeSource, "Additional Volume from podOptions not loaded into pod properly.")
+ assert.ElementsMatch(t, append(testAdditionalImagePullSecrets, corev1.LocalObjectReference{Name: testImagePullSecretName}), deployment.Spec.Template.Spec.ImagePullSecrets, "Incorrect imagePullSecrets")
service := expectService(t, g, requests, expectedMetricsRequest, metricsSKey, deployment.Spec.Template.Labels)
assert.Equal(t, "true", service.Annotations["prometheus.io/scrape"], "Metrics Service Prometheus scraping is not enabled.")
diff --git a/controllers/util/prometheus_exporter_util.go b/controllers/util/prometheus_exporter_util.go
index 6a846e2..a191e99 100644
--- a/controllers/util/prometheus_exporter_util.go
+++ b/controllers/util/prometheus_exporter_util.go
@@ -69,6 +69,7 @@ func GenerateSolrPrometheusExporterDeployment(solrPrometheusExporter *solr.SolrP
podLabels := labels
var podAnnotations map[string]string
+ var imagePullSecrets []corev1.LocalObjectReference
customDeploymentOptions := solrPrometheusExporter.Spec.CustomKubeOptions.DeploymentOptions
if nil != customDeploymentOptions {
@@ -80,6 +81,7 @@ func GenerateSolrPrometheusExporterDeployment(solrPrometheusExporter *solr.SolrP
if nil != customPodOptions {
podLabels = MergeLabelsOrAnnotations(podLabels, customPodOptions.Labels)
podAnnotations = customPodOptions.Annotations
+ imagePullSecrets = customPodOptions.ImagePullSecrets
}
var envVars []corev1.EnvVar
@@ -274,11 +276,14 @@ func GenerateSolrPrometheusExporterDeployment(solrPrometheusExporter *solr.SolrP
}
if solrPrometheusExporter.Spec.Image.ImagePullSecret != "" {
- deployment.Spec.Template.Spec.ImagePullSecrets = []corev1.LocalObjectReference{
- {Name: solrPrometheusExporter.Spec.Image.ImagePullSecret},
- }
+ imagePullSecrets = append(
+ imagePullSecrets,
+ corev1.LocalObjectReference{Name: solrPrometheusExporter.Spec.Image.ImagePullSecret},
+ )
}
+ deployment.Spec.Template.Spec.ImagePullSecrets = imagePullSecrets
+
if nil != customPodOptions {
if customPodOptions.Affinity != nil {
deployment.Spec.Template.Spec.Affinity = customPodOptions.Affinity
diff --git a/controllers/util/solr_util.go b/controllers/util/solr_util.go
index e124048..6821832 100644
--- a/controllers/util/solr_util.go
+++ b/controllers/util/solr_util.go
@@ -519,12 +519,21 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl
},
}
+ var imagePullSecrets []corev1.LocalObjectReference
+
+ if customPodOptions != nil {
+ imagePullSecrets = customPodOptions.ImagePullSecrets
+ }
+
if solrCloud.Spec.SolrImage.ImagePullSecret != "" {
- stateful.Spec.Template.Spec.ImagePullSecrets = []corev1.LocalObjectReference{
- {Name: solrCloud.Spec.SolrImage.ImagePullSecret},
- }
+ imagePullSecrets = append(
+ imagePullSecrets,
+ corev1.LocalObjectReference{Name: solrCloud.Spec.SolrImage.ImagePullSecret},
+ )
}
+ stateful.Spec.Template.Spec.ImagePullSecrets = imagePullSecrets
+
if nil != customPodOptions {
if customPodOptions.Affinity != nil {
stateful.Spec.Template.Spec.Affinity = customPodOptions.Affinity
diff --git a/go.sum b/go.sum
index 3a5014a..84dc1a9 100644
--- a/go.sum
+++ b/go.sum
@@ -408,6 +408,7 @@ github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkU
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
+github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8=
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
diff --git a/helm/solr-operator/crds/crds.yaml b/helm/solr-operator/crds/crds.yaml
index 9dd135b..a757e46 100644
--- a/helm/solr-operator/crds/crds.yaml
+++ b/helm/solr-operator/crds/crds.yaml
@@ -1721,6 +1721,16 @@ spec:
- name
type: object
type: array
+ imagePullSecrets:
+ description: ImagePullSecrets to apply to the pod. These are for init/sidecarContainers in addition to the imagePullSecret defined for the solr image.
+ items:
+ description: LocalObjectReference contains enough information to let you locate the referenced object inside the same namespace.
+ properties:
+ name:
+ description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?'
+ type: string
+ type: object
+ type: array
initContainers:
description: Additional init containers to run in the pod. These will run along with the init container that sets up the "solr.xml".
items:
@@ -6938,6 +6948,16 @@ spec:
- name
type: object
type: array
+ imagePullSecrets:
+ description: ImagePullSecrets to apply to the pod. These are for init/sidecarContainers in addition to the imagePullSecret defined for the solr image.
+ items:
+ description: LocalObjectReference contains enough information to let you locate the referenced object inside the same namespace.
+ properties:
+ name:
+ description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names TODO: Add other useful fields. apiVersion, kind, uid?'
+ type: string
+ type: object
+ type: array
initContainers:
description: Additional init containers to run in the pod. These will run along with the init container that sets up the "solr.xml".
items: