diff --git a/apis/druid/v1alpha1/druid_types.go b/apis/druid/v1alpha1/druid_types.go index fed134f1..36c122f7 100644 --- a/apis/druid/v1alpha1/druid_types.go +++ b/apis/druid/v1alpha1/druid_types.go @@ -180,6 +180,11 @@ type DruidSpec struct { // +optional PodAnnotations map[string]string `json:"podAnnotations,omitempty"` + // WorkloadAnnotations annotations to be populated in StatefulSet or Deployment spec. + // if the same key is specified at both the DruidNodeSpec level and DruidSpec level, the DruidNodeSpec WorkloadAnnotations will take precedence. + // +optional + WorkloadAnnotations map[string]string `json:"workloadAnnotations,omitempty"` + // PodManagementPolicy // +optional // +kubebuilder:default:="Parallel" @@ -433,6 +438,10 @@ type DruidNodeSpec struct { // +optional IngressAnnotations map[string]string `json:"ingressAnnotations,omitempty"` + // WorkloadAnnotations annotations to be populated in StatefulSet or Deployment spec. + // +optional + WorkloadAnnotations map[string]string `json:"workloadAnnotations,omitempty"` + // Ingress Kubernetes Native `Ingress` specification. // +optional Ingress *networkingv1.IngressSpec `json:"ingress,omitempty"` diff --git a/apis/druid/v1alpha1/zz_generated.deepcopy.go b/apis/druid/v1alpha1/zz_generated.deepcopy.go index 607be70b..adb8d8f7 100644 --- a/apis/druid/v1alpha1/zz_generated.deepcopy.go +++ b/apis/druid/v1alpha1/zz_generated.deepcopy.go @@ -456,6 +456,13 @@ func (in *DruidNodeSpec) DeepCopyInto(out *DruidNodeSpec) { (*out)[key] = val } } + if in.WorkloadAnnotations != nil { + in, out := &in.WorkloadAnnotations, &out.WorkloadAnnotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } if in.Ingress != nil { in, out := &in.Ingress, &out.Ingress *out = new(networkingv1.IngressSpec) @@ -611,6 +618,13 @@ func (in *DruidSpec) DeepCopyInto(out *DruidSpec) { (*out)[key] = val } } + if in.WorkloadAnnotations != nil { + in, out := &in.WorkloadAnnotations, &out.WorkloadAnnotations + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } if in.PodLabels != nil { in, out := &in.PodLabels, &out.PodLabels *out = make(map[string]string, len(*in)) diff --git a/chart/templates/crds/druid.apache.org_druids.yaml b/chart/templates/crds/druid.apache.org_druids.yaml index 07eb83a6..589ddd03 100644 --- a/chart/templates/crds/druid.apache.org_druids.yaml +++ b/chart/templates/crds/druid.apache.org_druids.yaml @@ -9025,6 +9025,12 @@ spec: - name type: object type: array + workloadAnnotations: + additionalProperties: + type: string + description: WorkloadAnnotations annotations to be populated + in StatefulSet or Deployment spec. + type: object required: - druid.port - nodeConfigMountPath @@ -12094,6 +12100,14 @@ spec: - name type: object type: array + workloadAnnotations: + additionalProperties: + type: string + description: WorkloadAnnotations annotations to be populated in StatefulSet + or Deployment spec. if the same key is specified at both the DruidNodeSpec + level and DruidSpec level, the DruidNodeSpec WorkloadAnnotations + will take precedence. + type: object zookeeper: description: 'Zookeeper IGNORED (Future API): In order to make Druid dependency setup extensible from within Druid operator.' diff --git a/config/crd/bases/druid.apache.org_druids.yaml b/config/crd/bases/druid.apache.org_druids.yaml index 07eb83a6..589ddd03 100644 --- a/config/crd/bases/druid.apache.org_druids.yaml +++ b/config/crd/bases/druid.apache.org_druids.yaml @@ -9025,6 +9025,12 @@ spec: - name type: object type: array + workloadAnnotations: + additionalProperties: + type: string + description: WorkloadAnnotations annotations to be populated + in StatefulSet or Deployment spec. + type: object required: - druid.port - nodeConfigMountPath @@ -12094,6 +12100,14 @@ spec: - name type: object type: array + workloadAnnotations: + additionalProperties: + type: string + description: WorkloadAnnotations annotations to be populated in StatefulSet + or Deployment spec. if the same key is specified at both the DruidNodeSpec + level and DruidSpec level, the DruidNodeSpec WorkloadAnnotations + will take precedence. + type: object zookeeper: description: 'Zookeeper IGNORED (Future API): In order to make Druid dependency setup extensible from within Druid operator.' diff --git a/controllers/druid/handler.go b/controllers/druid/handler.go index 9c480465..e01e1804 100644 --- a/controllers/druid/handler.go +++ b/controllers/druid/handler.go @@ -998,9 +998,10 @@ func makeStatefulSet(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid, ls map APIVersion: "apps/v1", }, ObjectMeta: metav1.ObjectMeta{ - Name: fmt.Sprintf("%s", nodeSpecUniqueStr), - Namespace: m.Namespace, - Labels: ls, + Name: fmt.Sprintf("%s", nodeSpecUniqueStr), + Annotations: makeAnnotationsForWorkload(nodeSpec, m), + Namespace: m.Namespace, + Labels: ls, }, Spec: makeStatefulSetSpec(nodeSpec, m, ls, nodeSpecUniqueStr, configMapSHA, serviceName), }, nil @@ -1022,9 +1023,10 @@ func makeDeployment(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid, ls map[ APIVersion: "apps/v1", }, ObjectMeta: metav1.ObjectMeta{ - Name: fmt.Sprintf("%s", nodeSpecUniqueStr), - Namespace: m.Namespace, - Labels: ls, + Name: fmt.Sprintf("%s", nodeSpecUniqueStr), + Annotations: makeAnnotationsForWorkload(nodeSpec, m), + Namespace: m.Namespace, + Labels: ls, }, Spec: makeDeploymentSpec(nodeSpec, m, ls, nodeSpecUniqueStr, configMapSHA, serviceName), }, nil @@ -1287,6 +1289,22 @@ func makeLabelsForNodeSpec(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid, return labels } +// makeAnnotationsForWorkload returns the annotations for a Deployment or StatefulSet +// If a given key is set in both the DruidSpec and DruidNodeSpec, the node-scoped value will take precedence. +func makeAnnotationsForWorkload(nodeSpec *v1alpha1.DruidNodeSpec, m *v1alpha1.Druid) map[string]string { + var annotations = map[string]string{} + + if m.Spec.WorkloadAnnotations != nil { + annotations = m.Spec.WorkloadAnnotations + } + + for k, v := range nodeSpec.WorkloadAnnotations { + annotations[k] = v + } + + return annotations +} + // addOwnerRefToObject appends the desired OwnerReference to the object func addOwnerRefToObject(obj metav1.Object, ownerRef metav1.OwnerReference) { obj.SetOwnerReferences(append(obj.GetOwnerReferences(), ownerRef)) diff --git a/controllers/druid/testdata/broker-deployment.yaml b/controllers/druid/testdata/broker-deployment.yaml index 173815de..cee83c27 100644 --- a/controllers/druid/testdata/broker-deployment.yaml +++ b/controllers/druid/testdata/broker-deployment.yaml @@ -9,7 +9,10 @@ metadata: nodeSpecUniqueStr: druid-druid-test-brokers component: broker annotations: - druidOpResourceHash: DYdfEwwDlLKgjTSZeuJb5nloe/w= + druidOpResourceHash: nQv/LmxctTSRsI5dtBe3jvN5WM8= + kubernetes.io/cluster-scoped-annotation: "cluster" + kubernetes.io/node-scoped-annotation: "broker" + kubernetes.io/override-annotation: "node-scoped-annotation" spec: replicas: 2 selector: diff --git a/controllers/druid/testdata/broker-statefulset.yaml b/controllers/druid/testdata/broker-statefulset.yaml index c4b6db88..15613483 100644 --- a/controllers/druid/testdata/broker-statefulset.yaml +++ b/controllers/druid/testdata/broker-statefulset.yaml @@ -9,7 +9,10 @@ metadata: nodeSpecUniqueStr: druid-druid-test-brokers component: broker annotations: - druidOpResourceHash: lTyDduvMnbQ7O2Glf57R9c5bFtA= + druidOpResourceHash: LXsKmbxQkX+94LkevlKDy4wemRQ= + kubernetes.io/cluster-scoped-annotation: "cluster" + kubernetes.io/node-scoped-annotation: "broker" + kubernetes.io/override-annotation: "node-scoped-annotation" spec: podManagementPolicy: Parallel replicas: 2 diff --git a/controllers/druid/testdata/druid-test-cr.yaml b/controllers/druid/testdata/druid-test-cr.yaml index 04227657..d3197408 100644 --- a/controllers/druid/testdata/druid-test-cr.yaml +++ b/controllers/druid/testdata/druid-test-cr.yaml @@ -7,6 +7,9 @@ spec: image: himanshu01/druid:druid-0.12.0-1 defaultProbes: true priorityClassName: high-priority + workloadAnnotations: + kubernetes.io/cluster-scoped-annotation: "cluster" + kubernetes.io/override-annotation: "cluster-scoped-annotation" podAnnotations: key1: value1 key2: value2 @@ -109,6 +112,9 @@ spec: nodes: brokers: nodeType: "broker" + workloadAnnotations: + kubernetes.io/node-scoped-annotation: "broker" + kubernetes.io/override-annotation: "node-scoped-annotation" services: - spec: type: ClusterIP diff --git a/docs/api_specifications/druid.md b/docs/api_specifications/druid.md index 0e173eab..fd57ded3 100644 --- a/docs/api_specifications/druid.md +++ b/docs/api_specifications/druid.md @@ -173,6 +173,56 @@ Kubernetes core/v1.ResourceRequirements +
+(Appears on: +DruidIngestionSpec) +
+Field | +Description | +
---|---|
+type + + +AuthType + + + |
++ | +
+secretRef + + +Kubernetes core/v1.SecretReference + + + |
++ | +
string
alias)+(Appears on: +Auth) +
@@ -559,6 +609,19 @@ map[string]string
workloadAnnotations
WorkloadAnnotations annotations to be populated in StatefulSet or Deployment spec. +if the same key is specified at both the DruidNodeSpec level and DruidSpec level, the DruidNodeSpec WorkloadAnnotations will take precedence.
+podManagementPolicy
Ingestion is the Schema for the Ingestion API
+Field | +Description | +||||||||
---|---|---|---|---|---|---|---|---|---|
+metadata + + +Kubernetes meta/v1.ObjectMeta + + + |
+
+Refer to the Kubernetes API documentation for the fields of the
+metadata field.
+ |
+||||||||
+spec + + +DruidIngestionSpec + + + |
+
+ + +
|
+||||||||
+status + + +DruidIngestionStatus + + + |
++ | +
string
alias)+(Appears on: +IngestionSpec) +
++(Appears on: +DruidIngestion) +
+Field | +Description | +
---|---|
+suspend + +bool + + |
++(Optional) + | +
+druidCluster + +string + + |
++ | +
+ingestion + + +IngestionSpec + + + |
++ | +
+auth + + +Auth + + + |
++(Optional) + | +
+(Appears on: +DruidIngestion) +
+Field | +Description | +
---|---|
+taskId + +string + + |
++ | +
+type + +string + + |
++ | +
+status + + +Kubernetes core/v1.ConditionStatus + + + |
++ | +
+reason + +string + + |
++ | +
+message + +string + + |
++ | +
+lastUpdateTime + + +Kubernetes meta/v1.Time + + + |
++ | +
+currentIngestionSpec.json + +string + + |
++ | +
string
alias)@@ -1472,6 +1806,18 @@ map[string]string
workloadAnnotations
WorkloadAnnotations annotations to be populated in StatefulSet or Deployment spec.
+ingress
workloadAnnotations
WorkloadAnnotations annotations to be populated in StatefulSet or Deployment spec. +if the same key is specified at both the DruidNodeSpec level and DruidSpec level, the DruidNodeSpec WorkloadAnnotations will take precedence.
+podManagementPolicy
+(Appears on: +DruidIngestionSpec) +
+Field | +Description | +
---|---|
+type + + +DruidIngestionMethod + + + |
++ | +
+spec + +string + + |
+
+ + + |
+
diff --git a/e2e/configs/druid-cr.yaml b/e2e/configs/druid-cr.yaml index 0aa8d986..fcf4a896 100644 --- a/e2e/configs/druid-cr.yaml +++ b/e2e/configs/druid-cr.yaml @@ -13,6 +13,8 @@ spec: release: alpha podAnnotations: dummy: k8s_extn_needs_atleast_one_annotation + workloadAnnotations: + kubernetes.io/cluster-scoped-annotation: "cluster" readinessProbe: httpGet: path: /status/health @@ -129,6 +131,8 @@ spec: # imagePullSecrets: # - name: tutu priorityClassName: system-cluster-critical + workloadAnnotations: + kubernetes.io/node-scoped-annotation: "broker" druid.port: 8088 services: - spec: