diff --git a/charts/opensearch-cluster/values.yaml b/charts/opensearch-cluster/values.yaml index dfb7e783e..c7e478bb6 100644 --- a/charts/opensearch-cluster/values.yaml +++ b/charts/opensearch-cluster/values.yaml @@ -121,6 +121,9 @@ cluster: # -- bootstrap pod affinity rules affinity: {} + # -- bootstrap pod annotations + annotations: {} + # -- bootstrap pod jvm options. If jvm is not provided then the java heap size will be set to half of resources.requests.memory which is the recommend value for data nodes. # If jvm is not provided and resources.requests.memory does not exist then value will be -Xmx512M -Xms512M jvm: "" @@ -243,6 +246,8 @@ cluster: # -- Opensearch nodes configuration nodePools: - component: masters + # -- node pool pod annotations + annotations: {} diskSize: "30Gi" replicas: 3 roles: diff --git a/charts/opensearch-operator/files/opensearch.opster.io_opensearchclusters.yaml b/charts/opensearch-operator/files/opensearch.opster.io_opensearchclusters.yaml index 13385cd89..4adb48004 100644 --- a/charts/opensearch-operator/files/opensearch.opster.io_opensearchclusters.yaml +++ b/charts/opensearch-operator/files/opensearch.opster.io_opensearchclusters.yaml @@ -987,6 +987,10 @@ spec: x-kubernetes-list-type: atomic type: object type: object + annotations: + additionalProperties: + type: string + type: object jvm: type: string keystore: diff --git a/opensearch-operator/api/v1/opensearch_types.go b/opensearch-operator/api/v1/opensearch_types.go index e044660d4..ffd9898d8 100644 --- a/opensearch-operator/api/v1/opensearch_types.go +++ b/opensearch-operator/api/v1/opensearch_types.go @@ -173,6 +173,7 @@ type BootstrapConfig struct { Jvm string `json:"jvm,omitempty"` // Extra items to add to the opensearch.yml, defaults to General.AdditionalConfig AdditionalConfig map[string]string `json:"additionalConfig,omitempty"` + Annotations map[string]string `json:"annotations,omitempty"` PluginsList []string `json:"pluginsList,omitempty"` Keystore []KeystoreValue `json:"keystore,omitempty"` } diff --git a/opensearch-operator/api/v1/zz_generated.deepcopy.go b/opensearch-operator/api/v1/zz_generated.deepcopy.go index 6594972f7..9ec864174 100644 --- a/opensearch-operator/api/v1/zz_generated.deepcopy.go +++ b/opensearch-operator/api/v1/zz_generated.deepcopy.go @@ -295,6 +295,13 @@ func (in *BootstrapConfig) DeepCopyInto(out *BootstrapConfig) { (*out)[key] = val } } + if in.Annotations != nil { + in, out := &in.Annotations, &out.Annotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } if in.PluginsList != nil { in, out := &in.PluginsList, &out.PluginsList *out = make([]string, len(*in)) diff --git a/opensearch-operator/config/crd/bases/opensearch.opster.io_opensearchclusters.yaml b/opensearch-operator/config/crd/bases/opensearch.opster.io_opensearchclusters.yaml index 13385cd89..4adb48004 100644 --- a/opensearch-operator/config/crd/bases/opensearch.opster.io_opensearchclusters.yaml +++ b/opensearch-operator/config/crd/bases/opensearch.opster.io_opensearchclusters.yaml @@ -987,6 +987,10 @@ spec: x-kubernetes-list-type: atomic type: object type: object + annotations: + additionalProperties: + type: string + type: object jvm: type: string keystore: diff --git a/opensearch-operator/opensearch-gateway/services/os_client.go b/opensearch-operator/opensearch-gateway/services/os_client.go index 2ec30c5d8..57f8cc230 100644 --- a/opensearch-operator/opensearch-gateway/services/os_client.go +++ b/opensearch-operator/opensearch-gateway/services/os_client.go @@ -100,6 +100,8 @@ func NewOsClusterClientFromConfig(config opensearch.Config) (*OsClusterClient, e client, err := opensearch.NewClient(config) if err == nil { service.client = client + } else { + return nil, err } pingReq := opensearchapi.PingRequest{} pingRes, err := pingReq.Do(context.Background(), client) diff --git a/opensearch-operator/pkg/builders/cluster.go b/opensearch-operator/pkg/builders/cluster.go index 4b1992cd7..d7098c6bf 100644 --- a/opensearch-operator/pkg/builders/cluster.go +++ b/opensearch-operator/pkg/builders/cluster.go @@ -990,9 +990,10 @@ func NewBootstrapPod( mainCommand := helpers.BuildMainCommand("./bin/opensearch-plugin", pluginslist, true, startUpCommand) pod := &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ - Name: BootstrapPodName(cr), - Namespace: cr.Namespace, - Labels: labels, + Name: BootstrapPodName(cr), + Namespace: cr.Namespace, + Labels: labels, + Annotations: cr.Spec.Bootstrap.Annotations, }, Spec: corev1.PodSpec{ Containers: []corev1.Container{ diff --git a/opensearch-operator/pkg/builders/cluster_test.go b/opensearch-operator/pkg/builders/cluster_test.go index d92243ded..61e532049 100644 --- a/opensearch-operator/pkg/builders/cluster_test.go +++ b/opensearch-operator/pkg/builders/cluster_test.go @@ -466,6 +466,19 @@ var _ = Describe("Builders", func() { })) }) + It("should apply bootstrap pod annotations", func() { + clusterObject := ClusterDescWithVersion("2.2.1") + expectedAnnotations := map[string]string{ + "custom-annotation": "custom-value", + "another-annotation": "another-value", + } + clusterObject.Spec.Bootstrap.Annotations = expectedAnnotations + + result := NewBootstrapPod(&clusterObject, nil, nil) + + Expect(result.ObjectMeta.Annotations).To(Equal(expectedAnnotations)) + }) + It("should overwrite the General.AdditionalConfig with Bootstrap.AdditionalConfig when set", func() { mockKey1 := "server.basePath" mockKey2 := "server.rewriteBasePath"