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

Issue 538: Support of customized pod annotation for Pravega pods #543

Merged
merged 7 commits into from
May 10, 2021
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,11 @@ spec:
type: string
description: Annotations to be added to the external service
type: object
controllerPodAnnotations:
additionalProperties:
type: string
description: Annotations to be added to controller pods
type: object
controllerPodLabels:
additionalProperties:
type: string
Expand Down Expand Up @@ -1997,6 +2002,11 @@ spec:
type: string
description: Annotations to be added to the external service
type: object
segmentStorePodAnnotations:
additionalProperties:
type: string
description: Annotations to be added to the SegmentStore pods
type: object
segmentStorePodLabels:
additionalProperties:
type: string
Expand Down Expand Up @@ -2835,11 +2845,6 @@ spec:
type: string
description: Annotations to be added to the external service
type: object
controllerPodLabels:
additionalProperties:
type: string
description: Labels to be added to the Controller Pods
type: object
controllerjvmOptions:
description: ControllerJvmOptions is the JVM options for controller.
It will be passed to the JVM for performance tuning. If this
Expand Down Expand Up @@ -2935,11 +2940,6 @@ spec:
type: string
description: Annotations to be added to the external service
type: object
segmentStorePodLabels:
additionalProperties:
type: string
description: Labels to be added to the SegmentStore Pods
type: object
tier2:
description: Tier2 is the configuration of Pravega's tier 2 storage.
If no configuration is provided, it will assume that a PersistentVolumeClaim
Expand Down
10 changes: 6 additions & 4 deletions charts/pravega/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,26 +135,28 @@ The following table lists the configurable parameters of the pravega chart and t
| `controller.service.type` | Override the controller service type, if external access is enabled (LoadBalancer/NodePort) | |
| `controller.service.annotations` | Annotations to add to the controller service, if external access is enabled | `{}` |
| `controller.labels` | Labels to add to the controller pods | `{}` |
| `controller.annotations` | Annotations to add to the controller pods | `{}` |
| `controller.jvmOptions` | JVM Options for controller | `["-Xmx2g", "-XX:MaxDirectMemorySize=2g"]` |
| `controller.svcNameSuffix` | suffix for controller service name | `pravega-controller` |
| `segmentStore.replicas` | Number of segmentStore replicas | `1` |
| `segmentStore.maxUnavailableReplicas` | Maximum number of unavailable replicas possible for segmentstore pdb | |
| `segmentStore.maxUnavailableReplicas` | Maximum number of unavailable replicas possible for segmentStore pdb | |
| `segmentStore.secret` | Secret configuration for the segmentStore | `{}` |
| `segmentStore.env` | Name of configmap containing environment variables to be added to the segmentStore | |
| `segmentStore.resources.requests.cpu` | CPU requests for segmentStore | `1000m` |
| `segmentStore.resources.requests.memory` | Memory requests for segmentStore | `4Gi` |
| `segmentStore.resources.limits.cpu` | CPU limits for segmentStore | `2000m` |
| `segmentStore.resources.limits.memory` | Memory limits for segmentStore | `4Gi` |
| `segmentStore.securityContext` | Holds pod-level security attributes and common container settings for segmentStore | `{}` |
| `segmentStore.affinity | Specifies scheduling constraints on segmentstore pods | `{}` |
| `segmentStore.affinity | Specifies scheduling constraints on segmentStore pods | `{}` |
| `segmentStore.service.type` | Override the segmentStore service type, if external access is enabled (LoadBalancer/NodePort) | |
| `segmentStore.service.annotations` | Annotations to add to the segmentStore service, if external access is enabled | `{}` |
| `segmentStore.service.loadBalancerIP` | It is used to provide a LoadBalancerIP for the segmentStore service | |
| `segmentStore.service.externalTrafficPolicy` | It is used to provide ExternalTrafficPolicy for the segmentStore service | |
| `segmentStore.jvmOptions` | JVM Options for segmentStore | `[]` |
| `segmentStore.stsNameSuffix` | suffix for segmentstore sts name | `pravega-segment-store` |
| `segmentStore.headlessSvcNameSuffix` | suffix for segmentsdtore headless service name | `pravega-segmentstore-headless` |
| `segmentStore.stsNameSuffix` | suffix for segmentStore sts name | `pravega-segment-store` |
| `segmentStore.headlessSvcNameSuffix` | suffix for segmentStore headless service name | `pravega-segmentstore-headless` |
| `segmentStore.labels` | Labels to add to the segmentStore pods | `{}` |
| `segmentStore.annotations` | Annotations to add to the segmentStore pods | `{}` |
| `storage.longtermStorage.type` | Type of long term storage backend to be used (filesystem/ecs/hdfs) | `filesystem` |
| `storage.longtermStorage.filesystem.pvc` | Name of the pre-created PVC, if long term storage type is filesystem | `pravega-tier2` |
| `storage.longtermStorage.ecs` | Configuration to use a Dell EMC ECS system, if long term storage type is ecs | `{}` |
Expand Down
18 changes: 15 additions & 3 deletions charts/pravega/templates/pravega.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,30 @@ spec:
{{- if .Values.controller.service.annotations }}
controllerSvcAnnotations:
{{ toYaml .Values.controller.service.annotations | indent 6 }}
controllerPodLabels:
{{ toYaml .Values.controller.labels | indent 6 }}
{{- end }}
{{- if .Values.segmentStore.service.type }}
segmentStoreExtServiceType: {{ .Values.segmentStore.service.type }}
{{- end }}
{{- if .Values.segmentStore.service.annotations }}
segmentStoreSvcAnnotations:
{{ toYaml .Values.segmentStore.service.annotations | indent 6 }}
{{ toYaml .Values.segmentStore.service.annotations | indent 6 }}
{{- end }}
{{- end }}
{{- if .Values.controller.labels }}
controllerPodLabels:
{{ toYaml .Values.controller.labels | indent 6 }}
{{- end }}
{{- if .Values.controller.annotations }}
controllerPodAnnotations:
{{ toYaml .Values.controller.annotations | indent 6 }}
{{- end }}
{{- if .Values.segmentStore.labels }}
segmentStorePodLabels:
{{ toYaml .Values.segmentStore.labels | indent 6 }}
{{- end }}
{{- if .Values.segmentStore.annotations }}
segmentStorePodAnnotations:
{{ toYaml .Values.segmentStore.annotations | indent 6 }}
{{- end }}
image:
repository: {{ .Values.image.repository }}
Expand Down
2 changes: 2 additions & 0 deletions charts/pravega/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ controller:
annotations: {}
jvmOptions: []
labels: {}
annotations: {}

segmentStore:
replicas: 1
Expand Down Expand Up @@ -91,6 +92,7 @@ segmentStore:
externalTrafficPolicy:
jvmOptions: ["-Xmx2g", "-XX:MaxDirectMemorySize=2g"]
labels: {}
annotations: {}
stsNameSuffix:
headlessSvcNameSuffix:

Expand Down
20 changes: 10 additions & 10 deletions deploy/crds/pravega.pravega.io_pravegaclusters_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,11 @@ spec:
type: string
description: Annotations to be added to the external service
type: object
controllerPodAnnotations:
additionalProperties:
type: string
description: Annotations to be added to controller pods
type: object
controllerPodLabels:
additionalProperties:
type: string
Expand Down Expand Up @@ -1985,6 +1990,11 @@ spec:
type: string
description: Annotations to be added to the external service
type: object
segmentStorePodAnnotations:
additionalProperties:
type: string
description: Annotations to be added to the SegmentStore pods
type: object
segmentStorePodLabels:
additionalProperties:
type: string
Expand Down Expand Up @@ -2823,11 +2833,6 @@ spec:
type: string
description: Annotations to be added to the external service
type: object
controllerPodLabels:
additionalProperties:
type: string
description: Labels to be added to the Controller Pods
type: object
controllerjvmOptions:
description: ControllerJvmOptions is the JVM options for controller.
It will be passed to the JVM for performance tuning. If this
Expand Down Expand Up @@ -2923,11 +2928,6 @@ spec:
type: string
description: Annotations to be added to the external service
type: object
segmentStorePodLabels:
additionalProperties:
type: string
description: Labels to be added to the SegmentStore Pods
type: object
tier2:
description: Tier2 is the configuration of Pravega's tier 2 storage.
If no configuration is provided, it will assume that a PersistentVolumeClaim
Expand Down
16 changes: 15 additions & 1 deletion pkg/apis/pravega/v1beta1/pravega.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ type PravegaSpec struct {
// +optional
ControllerPodLabels map[string]string `json:"controllerPodLabels"`

// Annotations to be added to controller pods
// +optonal
ControllerPodAnnotations map[string]string `json:"controllerPodAnnotations"`
// Type specifies the service type to achieve external access.
// Options are "LoadBalancer" and "NodePort".
// By default, if external access is enabled, it will use "LoadBalancer"
Expand All @@ -183,6 +186,10 @@ type PravegaSpec struct {
// +optional
SegmentStorePodLabels map[string]string `json:"segmentStorePodLabels"`

// Annotations to be added to the SegmentStore pods
// +optional
SegmentStorePodAnnotations map[string]string `json:"segmentStorePodAnnotations"`

// Specifying this IP would ensure we use same IP address for all the ss services
SegmentStoreLoadBalancerIP string `json:"segmentStoreLoadBalancerIP,omitempty"`

Expand Down Expand Up @@ -340,7 +347,14 @@ func (s *PravegaSpec) withDefaults() (changed bool) {
changed = true
s.SegmentStoreStsNameSuffix = "pravega-segment-store"
}

if s.ControllerPodAnnotations == nil {
changed = true
s.ControllerPodAnnotations = map[string]string{}
}
if s.SegmentStorePodAnnotations == nil {
changed = true
s.SegmentStorePodAnnotations = map[string]string{}
}
return changed
}

Expand Down
20 changes: 20 additions & 0 deletions pkg/apis/pravega/v1beta1/pravegacluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,26 @@ func (p *PravegaCluster) LabelsForSegmentStore() map[string]string {
return labels
}

func (p *PravegaCluster) AnnotationsForController() map[string]string {
annotations := map[string]string{"pravega.version": p.Spec.Version}
if p.Spec.Pravega != nil && p.Spec.Pravega.ControllerPodAnnotations != nil {
for k, v := range p.Spec.Pravega.ControllerPodAnnotations {
annotations[k] = v
}
}
return annotations
}

func (p *PravegaCluster) AnnotationsForSegmentStore() map[string]string {
annotations := map[string]string{"pravega.version": p.Spec.Version}
if p.Spec.Pravega != nil && p.Spec.Pravega.SegmentStorePodAnnotations != nil {
for k, v := range p.Spec.Pravega.SegmentStorePodAnnotations {
annotations[k] = v
}
}
return annotations
}

func (pravegaCluster *PravegaCluster) LabelsForPravegaCluster() map[string]string {
return map[string]string{
"app": "pravega-cluster",
Expand Down
21 changes: 20 additions & 1 deletion pkg/apis/pravega/v1beta1/pravegacluster_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,10 @@ var _ = Describe("PravegaCluster Types Spec", func() {
p.Spec.Version = "0.6.0"
p.WithDefaults()
})
annotationsMap := map[string]string{
"annotations": "test",
"labels": "test",
}
It("should set volume claim template", func() {
Ω(p.Spec.Pravega.CacheVolumeClaimTemplate).ShouldNot(BeNil())
})
Expand All @@ -364,19 +368,34 @@ var _ = Describe("PravegaCluster Types Spec", func() {
Ω(name).ShouldNot(BeNil())
})

p.Spec.Pravega.ControllerPodLabels = annotationsMap
labels := p.LabelsForController()

It("Should return controller labels", func() {
Ω(labels).ShouldNot(BeNil())
})

p.Spec.Pravega.SegmentStorePodLabels = annotationsMap
labels = p.LabelsForSegmentStore()
It("Should return segmentstore labels", func() {
Ω(labels).ShouldNot(BeNil())
})

p.Spec.Pravega.ControllerPodAnnotations = annotationsMap
annotations := p.AnnotationsForController()
It("Should return controller annotations", func() {
Ω(annotations).ShouldNot(BeNil())
})

p.Spec.Pravega.SegmentStorePodAnnotations = annotationsMap
annotations = p.AnnotationsForSegmentStore()
It("Should return segmentstore annotations", func() {
Ω(annotations).ShouldNot(BeNil())
})

labels = p.LabelsForPravegaCluster()
It("Should return pravega labels", func() {
Ω(name).ShouldNot(BeNil())
Ω(labels).ShouldNot(BeNil())
})

name = p.PdbNameForController()
Expand Down
14 changes: 14 additions & 0 deletions pkg/apis/pravega/v1beta1/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion pkg/controller/pravega/pravega_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func MakeControllerPodTemplate(p *api.PravegaCluster) corev1.PodTemplateSpec {
return corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: p.LabelsForController(),
Annotations: map[string]string{"pravega.version": p.Spec.Version},
Annotations: p.AnnotationsForController(),
},
Spec: *makeControllerPodSpec(p),
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/pravega/pravega_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ var _ = Describe("Controller", func() {
SegmentStoreResources: customReq,
ControllerServiceAnnotations: annotationsMap,
ControllerPodLabels: annotationsMap,
ControllerPodAnnotations: annotationsMap,
SegmentStoreServiceAnnotations: annotationsMap,
SegmentStorePodLabels: annotationsMap,
Image: &v1beta1.ImageSpec{
Expand Down Expand Up @@ -164,6 +165,8 @@ var _ = Describe("Controller", func() {
It("should have runAsUser value as 0", func() {
podTemplate := pravega.MakeControllerPodTemplate(p)
Ω(fmt.Sprintf("%v", *podTemplate.Spec.SecurityContext.RunAsUser)).To(Equal("0"))
Ω(podTemplate.Annotations["service.beta.kubernetes.io/aws-load-balancer-type"]).To(Equal("nlb"))
Ω(podTemplate.Labels["service.beta.kubernetes.io/aws-load-balancer-type"]).To(Equal("nlb"))
})
})
Context("Controller with external service type empty", func() {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/pravega/pravega_segmentstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func MakeSegmentStorePodTemplate(p *api.PravegaCluster) corev1.PodTemplateSpec {
return corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: p.LabelsForSegmentStore(),
Annotations: map[string]string{"pravega.version": p.Spec.Version},
Annotations: p.AnnotationsForSegmentStore(),
},
Spec: makeSegmentstorePodSpec(p),
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/pravega/pravega_segmentstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ var _ = Describe("PravegaSegmentstore", func() {
ControllerPodLabels: annotationsMap,
SegmentStoreServiceAnnotations: annotationsMap,
SegmentStorePodLabels: annotationsMap,
SegmentStorePodAnnotations: annotationsMap,
SegmentStoreEnvVars: "SEG_CONFIG_MAP",
SegmentStoreSecret: &v1beta1.SegmentStoreSecret{
Secret: "seg-secret",
Expand Down Expand Up @@ -180,6 +181,9 @@ var _ = Describe("PravegaSegmentstore", func() {
It("should have runAsUser value as 0", func() {
podTemplate := pravega.MakeSegmentStorePodTemplate(p)
Ω(fmt.Sprintf("%v", *podTemplate.Spec.SecurityContext.RunAsUser)).To(Equal("0"))
Ω(podTemplate.Annotations["service.beta.kubernetes.io/aws-load-balancer-type"]).To(Equal("nlb"))
Ω(podTemplate.Labels["service.beta.kubernetes.io/aws-load-balancer-type"]).To(Equal("nlb"))

})
})
})
Expand Down
Loading