Skip to content

Commit 9181c00

Browse files
authored
[Feature] Create annotations on pod creation (#646)
1 parent ac5456d commit 9181c00

File tree

7 files changed

+68
-0
lines changed

7 files changed

+68
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- Fix Panics in Deployments without authentication
99
- Fix ChaosMonkey mode
1010
- Allow append on empty annotations
11+
- Add annotations and labels on pod creation
1112

1213
## [1.0.8](https://github.com/arangodb/kube-arangodb/tree/1.0.8) (2020-09-10)
1314
- Fix Volume rotation on AKS

pkg/deployment/images.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ type ImageUpdatePod struct {
5555
image string
5656
}
5757

58+
func (i *ImageUpdatePod) Annotations() map[string]string {
59+
return nil
60+
}
61+
62+
func (i *ImageUpdatePod) Labels() map[string]string {
63+
return nil
64+
}
65+
5866
type ArangoDImageUpdateContainer struct {
5967
spec api.DeploymentSpec
6068
image string

pkg/deployment/resources/pod_creator.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,22 @@ func RenderArangoPod(deployment k8sutil.APIObject, role, id, podName string,
539539
// Prepare basic pod
540540
p := k8sutil.NewPod(deployment.GetName(), role, id, podName, podCreator)
541541

542+
for k, v := range podCreator.Annotations() {
543+
if p.Annotations == nil {
544+
p.Annotations = map[string]string{}
545+
}
546+
547+
p.Annotations[k] = v
548+
}
549+
550+
for k, v := range podCreator.Labels() {
551+
if p.Labels == nil {
552+
p.Labels = map[string]string{}
553+
}
554+
555+
p.Labels[k] = v
556+
}
557+
542558
podCreator.Init(&p)
543559

544560
if initContainers, err := podCreator.GetInitContainers(); err != nil {

pkg/deployment/resources/pod_creator_arangod.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import (
2727
"math"
2828
"os"
2929

30+
"github.com/arangodb/kube-arangodb/pkg/util/collection"
31+
3032
"github.com/arangodb/kube-arangodb/pkg/deployment/resources/inspector"
3133
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/interfaces"
3234

@@ -476,3 +478,11 @@ func (m *MemberArangoDPod) ApplyPodSpec(p *core.PodSpec) error {
476478

477479
return nil
478480
}
481+
482+
func (m *MemberArangoDPod) Annotations() map[string]string {
483+
return collection.MergeAnnotations(m.spec.Annotations, m.groupSpec.Annotations)
484+
}
485+
486+
func (m *MemberArangoDPod) Labels() map[string]string {
487+
return collection.ReservedLabels().Filter(collection.MergeAnnotations(m.spec.Labels, m.groupSpec.Labels))
488+
}

pkg/deployment/resources/pod_creator_sync.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ package resources
2525
import (
2626
"math"
2727

28+
"github.com/arangodb/kube-arangodb/pkg/util/collection"
29+
2830
"github.com/arangodb/kube-arangodb/pkg/deployment/resources/inspector"
2931
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/interfaces"
3032

@@ -309,3 +311,11 @@ func (m *MemberSyncPod) Validate(cachedStatus inspector.Inspector) error {
309311
func (m *MemberSyncPod) ApplyPodSpec(spec *core.PodSpec) error {
310312
return nil
311313
}
314+
315+
func (m *MemberSyncPod) Annotations() map[string]string {
316+
return collection.MergeAnnotations(m.spec.Annotations, m.groupSpec.Annotations)
317+
}
318+
319+
func (m *MemberSyncPod) Labels() map[string]string {
320+
return collection.ReservedLabels().Filter(collection.MergeAnnotations(m.spec.Labels, m.groupSpec.Labels))
321+
}

pkg/util/collection/map.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ func NewRestrictedList(param ...string) RestrictedList {
8787
return param
8888
}
8989

90+
func ReservedLabels() RestrictedList {
91+
l := RestrictedList{}
92+
l = append(l, reservedLabels...)
93+
return l
94+
}
95+
9096
type RestrictedList []string
9197

9298
func (r RestrictedList) IsRestricted(s string) bool {
@@ -105,6 +111,20 @@ func (r RestrictedList) IsRestricted(s string) bool {
105111
return false
106112
}
107113

114+
func (r RestrictedList) Filter(m map[string]string) map[string]string {
115+
z := map[string]string{}
116+
117+
for k, v := range m {
118+
if r.IsRestricted(k) {
119+
continue
120+
}
121+
122+
z[k] = v
123+
}
124+
125+
return z
126+
}
127+
108128
func init() {
109129
r, err := regexp.Compile(kubernetesAnnotationMatch)
110130
if err != nil {

pkg/util/k8sutil/interfaces/pod_creator.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ type PodCreator interface {
5050
IsDeploymentMode() bool
5151
Validate(cachedStatus inspector.Inspector) error
5252

53+
Annotations() map[string]string
54+
Labels() map[string]string
55+
5356
PodModifier
5457
}
5558

0 commit comments

Comments
 (0)