Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Fix Panics in Deployments without authentication
- Fix ChaosMonkey mode
- Allow append on empty annotations
- Add annotations and labels on pod creation

## [1.0.8](https://github.com/arangodb/kube-arangodb/tree/1.0.8) (2020-09-10)
- Fix Volume rotation on AKS
Expand Down
8 changes: 8 additions & 0 deletions pkg/deployment/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ type ImageUpdatePod struct {
image string
}

func (i *ImageUpdatePod) Annotations() map[string]string {
return nil
}

func (i *ImageUpdatePod) Labels() map[string]string {
return nil
}

type ArangoDImageUpdateContainer struct {
spec api.DeploymentSpec
image string
Expand Down
16 changes: 16 additions & 0 deletions pkg/deployment/resources/pod_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,22 @@ func RenderArangoPod(deployment k8sutil.APIObject, role, id, podName string,
// Prepare basic pod
p := k8sutil.NewPod(deployment.GetName(), role, id, podName, podCreator)

for k, v := range podCreator.Annotations() {
if p.Annotations == nil {
p.Annotations = map[string]string{}
}

p.Annotations[k] = v
}

for k, v := range podCreator.Labels() {
if p.Labels == nil {
p.Labels = map[string]string{}
}

p.Labels[k] = v
}

podCreator.Init(&p)

if initContainers, err := podCreator.GetInitContainers(); err != nil {
Expand Down
10 changes: 10 additions & 0 deletions pkg/deployment/resources/pod_creator_arangod.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"math"
"os"

"github.com/arangodb/kube-arangodb/pkg/util/collection"

"github.com/arangodb/kube-arangodb/pkg/deployment/resources/inspector"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/interfaces"

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

return nil
}

func (m *MemberArangoDPod) Annotations() map[string]string {
return collection.MergeAnnotations(m.spec.Annotations, m.groupSpec.Annotations)
}

func (m *MemberArangoDPod) Labels() map[string]string {
return collection.ReservedLabels().Filter(collection.MergeAnnotations(m.spec.Labels, m.groupSpec.Labels))
}
10 changes: 10 additions & 0 deletions pkg/deployment/resources/pod_creator_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ package resources
import (
"math"

"github.com/arangodb/kube-arangodb/pkg/util/collection"

"github.com/arangodb/kube-arangodb/pkg/deployment/resources/inspector"
"github.com/arangodb/kube-arangodb/pkg/util/k8sutil/interfaces"

Expand Down Expand Up @@ -309,3 +311,11 @@ func (m *MemberSyncPod) Validate(cachedStatus inspector.Inspector) error {
func (m *MemberSyncPod) ApplyPodSpec(spec *core.PodSpec) error {
return nil
}

func (m *MemberSyncPod) Annotations() map[string]string {
return collection.MergeAnnotations(m.spec.Annotations, m.groupSpec.Annotations)
}

func (m *MemberSyncPod) Labels() map[string]string {
return collection.ReservedLabels().Filter(collection.MergeAnnotations(m.spec.Labels, m.groupSpec.Labels))
}
20 changes: 20 additions & 0 deletions pkg/util/collection/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ func NewRestrictedList(param ...string) RestrictedList {
return param
}

func ReservedLabels() RestrictedList {
l := RestrictedList{}
l = append(l, reservedLabels...)
return l
}

type RestrictedList []string

func (r RestrictedList) IsRestricted(s string) bool {
Expand All @@ -105,6 +111,20 @@ func (r RestrictedList) IsRestricted(s string) bool {
return false
}

func (r RestrictedList) Filter(m map[string]string) map[string]string {
z := map[string]string{}

for k, v := range m {
if r.IsRestricted(k) {
continue
}

z[k] = v
}

return z
}

func init() {
r, err := regexp.Compile(kubernetesAnnotationMatch)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/util/k8sutil/interfaces/pod_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ type PodCreator interface {
IsDeploymentMode() bool
Validate(cachedStatus inspector.Inspector) error

Annotations() map[string]string
Labels() map[string]string

PodModifier
}

Expand Down