mirror of
https://github.com/arangodb/kube-arangodb.git
synced 2024-12-14 11:57:37 +00:00
[Feature] Create annotations on pod creation (#646)
This commit is contained in:
parent
ac5456dbad
commit
9181c00ce0
7 changed files with 68 additions and 0 deletions
|
@ -8,6 +8,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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -539,6 +539,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 {
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
|
|
@ -50,6 +50,9 @@ type PodCreator interface {
|
|||
IsDeploymentMode() bool
|
||||
Validate(cachedStatus inspector.Inspector) error
|
||||
|
||||
Annotations() map[string]string
|
||||
Labels() map[string]string
|
||||
|
||||
PodModifier
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue