diff --git a/pkg/schema/v1/annotation.go b/pkg/schema/v1/annotation.go new file mode 100644 index 00000000..d0c76237 --- /dev/null +++ b/pkg/schema/v1/annotation.go @@ -0,0 +1,9 @@ +package v1 + +import "github.com/icinga/icinga-go-library/types" + +type Annotation struct { + Uuid types.UUID + Name string + Value string +} diff --git a/pkg/schema/v1/config_map.go b/pkg/schema/v1/config_map.go index 97c619c5..4d8e3960 100644 --- a/pkg/schema/v1/config_map.go +++ b/pkg/schema/v1/config_map.go @@ -13,12 +13,14 @@ import ( type ConfigMap struct { Meta - Immutable types.Bool - Yaml string - Data []Data `db:"-"` - ConfigMapsData []ConfigMapData `db:"-"` - Labels []Label `db:"-"` - ConfigMapLabels []ConfigMapLabel `db:"-"` + Immutable types.Bool + Yaml string + Data []Data `db:"-"` + ConfigMapsData []ConfigMapData `db:"-"` + Labels []Label `db:"-"` + ConfigMapLabels []ConfigMapLabel `db:"-"` + Annotations []Annotation `db:"-"` + ConfigMapAnnotations []ConfigMapAnnotation `db:"-"` } type ConfigMapData struct { @@ -31,6 +33,11 @@ type ConfigMapLabel struct { LabelUuid types.UUID } +type ConfigMapAnnotation struct { + ConfigMapUuid types.UUID + AnnotationUuid types.UUID +} + func NewConfigMap() Resource { return &ConfigMap{} } @@ -75,6 +82,19 @@ func (c *ConfigMap) Obtain(k8s kmetav1.Object) { }) } + for annotationName, annotationValue := range configMap.Annotations { + annotationUuid := NewUUID(c.Uuid, strings.ToLower(annotationName+":"+annotationValue)) + c.Annotations = append(c.Annotations, Annotation{ + Uuid: annotationUuid, + Name: annotationName, + Value: annotationValue, + }) + c.ConfigMapAnnotations = append(c.ConfigMapAnnotations, ConfigMapAnnotation{ + ConfigMapUuid: c.Uuid, + AnnotationUuid: annotationUuid, + }) + } + scheme := kruntime.NewScheme() _ = kcorev1.AddToScheme(scheme) codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kcorev1.SchemeGroupVersion) @@ -90,5 +110,7 @@ func (c *ConfigMap) Relations() []database.Relation { database.HasMany(c.ConfigMapLabels, fk), database.HasMany(c.Data, database.WithoutCascadeDelete()), database.HasMany(c.ConfigMapsData, fk), + database.HasMany(c.ConfigMapAnnotations, fk), + database.HasMany(c.Annotations, database.WithoutCascadeDelete()), } } diff --git a/pkg/schema/v1/cron_job.go b/pkg/schema/v1/cron_job.go index 6efbc2fe..ed38aea9 100644 --- a/pkg/schema/v1/cron_job.go +++ b/pkg/schema/v1/cron_job.go @@ -24,8 +24,10 @@ type CronJob struct { LastScheduleTime types.UnixMilli LastSuccessfulTime types.UnixMilli Yaml string - Labels []Label `db:"-"` - CronJobLabels []CronJobLabel `db:"-"` + Labels []Label `db:"-"` + CronJobLabels []CronJobLabel `db:"-"` + Annotations []Annotation `db:"-"` + CronJobAnnotations []CronJobAnnotation `db:"-"` } type CronJobLabel struct { @@ -33,6 +35,11 @@ type CronJobLabel struct { LabelUuid types.UUID } +type CronJobAnnotation struct { + CronJobUuid types.UUID + AnnotationUuid types.UUID +} + func NewCronJob() Resource { return &CronJob{} } @@ -92,6 +99,19 @@ func (c *CronJob) Obtain(k8s kmetav1.Object) { }) } + for annotationName, annotationValue := range cronJob.Annotations { + annotationUuid := NewUUID(c.Uuid, strings.ToLower(annotationName+":"+annotationValue)) + c.Annotations = append(c.Annotations, Annotation{ + Uuid: annotationUuid, + Name: annotationName, + Value: annotationValue, + }) + c.CronJobAnnotations = append(c.CronJobAnnotations, CronJobAnnotation{ + CronJobUuid: c.Uuid, + AnnotationUuid: annotationUuid, + }) + } + scheme := kruntime.NewScheme() _ = kbatchv1.AddToScheme(scheme) codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kbatchv1.SchemeGroupVersion) @@ -105,5 +125,7 @@ func (c *CronJob) Relations() []database.Relation { return []database.Relation{ database.HasMany(c.Labels, database.WithoutCascadeDelete()), database.HasMany(c.CronJobLabels, fk), + database.HasMany(c.CronJobAnnotations, fk), + database.HasMany(c.Annotations, database.WithoutCascadeDelete()), } } diff --git a/pkg/schema/v1/daemon_set.go b/pkg/schema/v1/daemon_set.go index d94568b3..37654d31 100644 --- a/pkg/schema/v1/daemon_set.go +++ b/pkg/schema/v1/daemon_set.go @@ -27,9 +27,11 @@ type DaemonSet struct { Yaml string IcingaState IcingaState IcingaStateReason string - Conditions []DaemonSetCondition `db:"-"` - Labels []Label `db:"-"` - DaemonSetLabels []DaemonSetLabel `db:"-"` + Conditions []DaemonSetCondition `db:"-"` + Labels []Label `db:"-"` + DaemonSetLabels []DaemonSetLabel `db:"-"` + Annotations []Annotation `db:"-"` + DaemonSetAnnotations []DaemonSetAnnotation `db:"-"` } type DaemonSetCondition struct { @@ -46,6 +48,11 @@ type DaemonSetLabel struct { LabelUuid types.UUID } +type DaemonSetAnnotation struct { + DaemonSetUuid types.UUID + AnnotationUuid types.UUID +} + func NewDaemonSet() Resource { return &DaemonSet{} } @@ -89,6 +96,20 @@ func (d *DaemonSet) Obtain(k8s kmetav1.Object) { LabelUuid: labelUuid, }) } + + for annotationName, annotationValue := range daemonSet.Annotations { + annotationUuid := NewUUID(d.Uuid, strings.ToLower(annotationName+":"+annotationValue)) + d.Annotations = append(d.Annotations, Annotation{ + Uuid: annotationUuid, + Name: annotationName, + Value: annotationValue, + }) + d.DaemonSetAnnotations = append(d.DaemonSetAnnotations, DaemonSetAnnotation{ + DaemonSetUuid: d.Uuid, + AnnotationUuid: annotationUuid, + }) + } + scheme := kruntime.NewScheme() _ = kappsv1.AddToScheme(scheme) codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kappsv1.SchemeGroupVersion) @@ -130,5 +151,7 @@ func (d *DaemonSet) Relations() []database.Relation { database.HasMany(d.Conditions, fk), database.HasMany(d.DaemonSetLabels, fk), database.HasMany(d.Labels, database.WithoutCascadeDelete()), + database.HasMany(d.DaemonSetAnnotations, fk), + database.HasMany(d.Annotations, database.WithoutCascadeDelete()), } } diff --git a/pkg/schema/v1/deployment.go b/pkg/schema/v1/deployment.go index 097ae39b..70f910f9 100644 --- a/pkg/schema/v1/deployment.go +++ b/pkg/schema/v1/deployment.go @@ -29,9 +29,11 @@ type Deployment struct { Yaml string IcingaState IcingaState IcingaStateReason string - Conditions []DeploymentCondition `db:"-"` - Labels []Label `db:"-"` - DeploymentLabels []DeploymentLabel `db:"-"` + Conditions []DeploymentCondition `db:"-"` + Labels []Label `db:"-"` + DeploymentLabels []DeploymentLabel `db:"-"` + Annotations []Annotation `db:"-"` + DeploymentAnnotations []DeploymentAnnotation `db:"-"` } type DeploymentCondition struct { @@ -49,6 +51,11 @@ type DeploymentLabel struct { LabelUuid types.UUID } +type DeploymentAnnotation struct { + DeploymentUuid types.UUID + AnnotationUuid types.UUID +} + func NewDeployment() Resource { return &Deployment{} } @@ -106,6 +113,19 @@ func (d *Deployment) Obtain(k8s kmetav1.Object) { }) } + for annotationName, annotationValue := range deployment.Annotations { + annotationUuid := NewUUID(d.Uuid, strings.ToLower(annotationName+":"+annotationValue)) + d.Annotations = append(d.Annotations, Annotation{ + Uuid: annotationUuid, + Name: annotationName, + Value: annotationValue, + }) + d.DeploymentAnnotations = append(d.DeploymentAnnotations, DeploymentAnnotation{ + DeploymentUuid: d.Uuid, + AnnotationUuid: annotationUuid, + }) + } + scheme := kruntime.NewScheme() _ = kappsv1.AddToScheme(scheme) codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kappsv1.SchemeGroupVersion) @@ -154,5 +174,7 @@ func (d *Deployment) Relations() []database.Relation { database.HasMany(d.Conditions, fk), database.HasMany(d.DeploymentLabels, fk), database.HasMany(d.Labels, database.WithoutCascadeDelete()), + database.HasMany(d.DeploymentAnnotations, fk), + database.HasMany(d.Annotations, database.WithoutCascadeDelete()), } } diff --git a/pkg/schema/v1/job.go b/pkg/schema/v1/job.go index bfee47c4..97a4fefe 100644 --- a/pkg/schema/v1/job.go +++ b/pkg/schema/v1/job.go @@ -28,9 +28,11 @@ type Job struct { Succeeded int32 Failed int32 Yaml string - Conditions []JobCondition `db:"-"` - Labels []Label `db:"-"` - JobLabels []JobLabel `db:"-"` + Conditions []JobCondition `db:"-"` + Labels []Label `db:"-"` + JobLabels []JobLabel `db:"-"` + Annotations []Annotation `db:"-"` + JobAnnotations []JobAnnotation `db:"-"` } type JobCondition struct { @@ -48,6 +50,11 @@ type JobLabel struct { LabelUuid types.UUID } +type JobAnnotation struct { + JobUuid types.UUID + AnnotationUuid types.UUID +} + func NewJob() Resource { return &Job{} } @@ -139,6 +146,19 @@ func (j *Job) Obtain(k8s kmetav1.Object) { }) } + for annotationName, annotationValue := range job.Annotations { + annotationUuid := NewUUID(j.Uuid, strings.ToLower(annotationName+":"+annotationValue)) + j.Annotations = append(j.Annotations, Annotation{ + Uuid: annotationUuid, + Name: annotationName, + Value: annotationValue, + }) + j.JobAnnotations = append(j.JobAnnotations, JobAnnotation{ + JobUuid: j.Uuid, + AnnotationUuid: annotationUuid, + }) + } + scheme := kruntime.NewScheme() _ = kbatchv1.AddToScheme(scheme) codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kbatchv1.SchemeGroupVersion) @@ -153,5 +173,7 @@ func (j *Job) Relations() []database.Relation { database.HasMany(j.Conditions, fk), database.HasMany(j.Labels, database.WithoutCascadeDelete()), database.HasMany(j.JobLabels, fk), + database.HasMany(j.JobAnnotations, fk), + database.HasMany(j.Annotations, database.WithoutCascadeDelete()), } } diff --git a/pkg/schema/v1/namespace.go b/pkg/schema/v1/namespace.go index 1a6dbc9d..d2bc2a42 100644 --- a/pkg/schema/v1/namespace.go +++ b/pkg/schema/v1/namespace.go @@ -13,11 +13,13 @@ import ( type Namespace struct { Meta - Phase string - Yaml string - Conditions []NamespaceCondition `db:"-"` - Labels []Label `db:"-"` - NamespaceLabels []NamespaceLabel `db:"-"` + Phase string + Yaml string + Conditions []NamespaceCondition `db:"-"` + Labels []Label `db:"-"` + NamespaceLabels []NamespaceLabel `db:"-"` + Annotations []Annotation `db:"-"` + NamespaceAnnotations []NamespaceAnnotation `db:"-"` } type NamespaceCondition struct { @@ -34,6 +36,11 @@ type NamespaceLabel struct { LabelUuid types.UUID } +type NamespaceAnnotation struct { + NamespaceUuid types.UUID + AnnotationUuid types.UUID +} + func NewNamespace() Resource { return &Namespace{} } @@ -69,6 +76,19 @@ func (n *Namespace) Obtain(k8s kmetav1.Object) { }) } + for annotationName, annotationValue := range namespace.Annotations { + annotationUuid := NewUUID(n.Uuid, strings.ToLower(annotationName+":"+annotationValue)) + n.Annotations = append(n.Annotations, Annotation{ + Uuid: annotationUuid, + Name: annotationName, + Value: annotationValue, + }) + n.NamespaceAnnotations = append(n.NamespaceAnnotations, NamespaceAnnotation{ + NamespaceUuid: n.Uuid, + AnnotationUuid: annotationUuid, + }) + } + scheme := kruntime.NewScheme() _ = kcorev1.AddToScheme(scheme) codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kcorev1.SchemeGroupVersion) @@ -83,5 +103,7 @@ func (n *Namespace) Relations() []database.Relation { database.HasMany(n.Conditions, fk), database.HasMany(n.NamespaceLabels, fk), database.HasMany(n.Labels, database.WithoutCascadeDelete()), + database.HasMany(n.NamespaceAnnotations, fk), + database.HasMany(n.Annotations, database.WithoutCascadeDelete()), } } diff --git a/pkg/schema/v1/node.go b/pkg/schema/v1/node.go index 9f08bf6d..c6392d0d 100644 --- a/pkg/schema/v1/node.go +++ b/pkg/schema/v1/node.go @@ -37,10 +37,12 @@ type Node struct { ContainerRuntimeVersion string KubeletVersion string KubeProxyVersion string - Conditions []NodeCondition `db:"-"` - Volumes []NodeVolume `db:"-"` - Labels []Label `db:"-"` - NodeLabels []NodeLabel `db:"-"` + Conditions []NodeCondition `db:"-"` + Volumes []NodeVolume `db:"-"` + Labels []Label `db:"-"` + NodeLabels []NodeLabel `db:"-"` + Annotations []Annotation `db:"-"` + NodeAnnotations []NodeAnnotation `db:"-"` } type NodeCondition struct { @@ -65,6 +67,11 @@ type NodeLabel struct { LabelUuid types.UUID } +type NodeAnnotation struct { + NodeUuid types.UUID + AnnotationUuid types.UUID +} + func NewNode() Resource { return &Node{} } @@ -163,6 +170,19 @@ func (n *Node) Obtain(k8s kmetav1.Object) { codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kcorev1.SchemeGroupVersion) output, _ := kruntime.Encode(codec, node) n.Yaml = string(output) + + for annotationName, annotationValue := range node.Annotations { + annotationUuid := NewUUID(n.Uuid, strings.ToLower(annotationName+":"+annotationValue)) + n.Annotations = append(n.Annotations, Annotation{ + Uuid: annotationUuid, + Name: annotationName, + Value: annotationValue, + }) + n.NodeAnnotations = append(n.NodeAnnotations, NodeAnnotation{ + NodeUuid: n.Uuid, + AnnotationUuid: annotationUuid, + }) + } } func (n *Node) Relations() []database.Relation { @@ -173,6 +193,8 @@ func (n *Node) Relations() []database.Relation { database.HasMany(n.Volumes, fk), database.HasMany(n.NodeLabels, fk), database.HasMany(n.Labels, database.WithoutCascadeDelete()), + database.HasMany(n.NodeAnnotations, fk), + database.HasMany(n.Annotations, database.WithoutCascadeDelete()), } } diff --git a/pkg/schema/v1/pod.go b/pkg/schema/v1/pod.go index 4bdf3f38..d17f6035 100644 --- a/pkg/schema/v1/pod.go +++ b/pkg/schema/v1/pod.go @@ -34,13 +34,15 @@ type Pod struct { Qos string RestartPolicy string Yaml string - Conditions []PodCondition `db:"-"` - Containers []Container `db:"-"` - Owners []PodOwner `db:"-"` - Labels []Label `db:"-"` - PodLabels []PodLabel `db:"-"` - Pvcs []PodPvc `db:"-"` - Volumes []PodVolume `db:"-"` + Conditions []PodCondition `db:"-"` + Containers []Container `db:"-"` + Owners []PodOwner `db:"-"` + Labels []Label `db:"-"` + PodLabels []PodLabel `db:"-"` + Annotations []Annotation `db:"-"` + PodAnnotations []PodAnnotation `db:"-"` + Pvcs []PodPvc `db:"-"` + Volumes []PodVolume `db:"-"` factory *PodFactory } @@ -66,6 +68,11 @@ type PodLabel struct { LabelUuid types.UUID } +type PodAnnotation struct { + PodUuid types.UUID + AnnotationUuid types.UUID +} + type PodOwner struct { PodUuid types.UUID OwnerUuid types.UUID @@ -218,6 +225,19 @@ func (p *Pod) Obtain(k8s kmetav1.Object) { }) } + for annotationName, annotationValue := range pod.Annotations { + annotationUuid := NewUUID(p.Uuid, strings.ToLower(annotationName+":"+annotationValue)) + p.Annotations = append(p.Annotations, Annotation{ + Uuid: annotationUuid, + Name: annotationName, + Value: annotationValue, + }) + p.PodAnnotations = append(p.PodAnnotations, PodAnnotation{ + PodUuid: p.Uuid, + AnnotationUuid: annotationUuid, + }) + } + for _, ownerReference := range pod.OwnerReferences { var blockOwnerDeletion, controller bool if ownerReference.BlockOwnerDeletion != nil { @@ -295,6 +315,8 @@ func (p *Pod) Relations() []database.Relation { database.HasMany(p.Owners, fk), database.HasMany(p.Labels, database.WithoutCascadeDelete()), database.HasMany(p.PodLabels, fk), + database.HasMany(p.Annotations, database.WithoutCascadeDelete()), + database.HasMany(p.PodAnnotations, fk), database.HasMany(p.Pvcs, fk), database.HasMany(p.Volumes, fk), } diff --git a/pkg/schema/v1/pvc.go b/pkg/schema/v1/pvc.go index 5f58381b..2d4263e4 100644 --- a/pkg/schema/v1/pvc.go +++ b/pkg/schema/v1/pvc.go @@ -45,9 +45,11 @@ type Pvc struct { VolumeMode sql.NullString StorageClass sql.NullString Yaml string - Conditions []PvcCondition `db:"-"` - Labels []Label `db:"-"` - PvcLabels []PvcLabel `db:"-"` + Conditions []PvcCondition `db:"-"` + Labels []Label `db:"-"` + PvcLabels []PvcLabel `db:"-"` + Annotations []Annotation `db:"-"` + PvcAnnotations []PvcAnnotation `db:"-"` } type PvcCondition struct { @@ -65,6 +67,11 @@ type PvcLabel struct { LabelUuid types.UUID } +type PvcAnnotation struct { + PvcUuid types.UUID + AnnotationUuid types.UUID +} + func NewPvc() Resource { return &Pvc{} } @@ -123,6 +130,19 @@ func (p *Pvc) Obtain(k8s kmetav1.Object) { }) } + for annotationName, annotationValue := range pvc.Annotations { + annotationUuid := NewUUID(p.Uuid, strings.ToLower(annotationName+":"+annotationValue)) + p.Annotations = append(p.Annotations, Annotation{ + Uuid: annotationUuid, + Name: annotationName, + Value: annotationValue, + }) + p.PvcAnnotations = append(p.PvcAnnotations, PvcAnnotation{ + PvcUuid: p.Uuid, + AnnotationUuid: annotationUuid, + }) + } + scheme := kruntime.NewScheme() _ = kcorev1.AddToScheme(scheme) codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kcorev1.SchemeGroupVersion) diff --git a/pkg/schema/v1/replica_set.go b/pkg/schema/v1/replica_set.go index e46100a7..11db9a27 100644 --- a/pkg/schema/v1/replica_set.go +++ b/pkg/schema/v1/replica_set.go @@ -17,19 +17,21 @@ import ( type ReplicaSet struct { Meta - DesiredReplicas int32 - MinReadySeconds int32 - ActualReplicas int32 - FullyLabeledReplicas int32 - ReadyReplicas int32 - AvailableReplicas int32 - Yaml string - IcingaState IcingaState - IcingaStateReason string - Conditions []ReplicaSetCondition `db:"-"` - Owners []ReplicaSetOwner `db:"-"` - Labels []Label `db:"-"` - ReplicaSetLabels []ReplicaSetLabel `db:"-"` + DesiredReplicas int32 + MinReadySeconds int32 + ActualReplicas int32 + FullyLabeledReplicas int32 + ReadyReplicas int32 + AvailableReplicas int32 + Yaml string + IcingaState IcingaState + IcingaStateReason string + Conditions []ReplicaSetCondition `db:"-"` + Owners []ReplicaSetOwner `db:"-"` + Labels []Label `db:"-"` + ReplicaSetLabels []ReplicaSetLabel `db:"-"` + Annotations []Annotation `db:"-"` + ReplicaSetAnnotations []ReplicaSetAnnotation `db:"-"` } type ReplicaSetCondition struct { @@ -56,6 +58,11 @@ type ReplicaSetLabel struct { LabelUuid types.UUID } +type ReplicaSetAnnotation struct { + ReplicaSetUuid types.UUID + AnnotationUuid types.UUID +} + func NewReplicaSet() Resource { return &ReplicaSet{} } @@ -126,6 +133,19 @@ func (r *ReplicaSet) Obtain(k8s kmetav1.Object) { }) } + for annotationName, annotationValue := range replicaSet.Annotations { + annotationUuid := NewUUID(r.Uuid, strings.ToLower(annotationName+":"+annotationValue)) + r.Annotations = append(r.Annotations, Annotation{ + Uuid: annotationUuid, + Name: annotationName, + Value: annotationValue, + }) + r.ReplicaSetAnnotations = append(r.ReplicaSetAnnotations, ReplicaSetAnnotation{ + ReplicaSetUuid: r.Uuid, + AnnotationUuid: annotationUuid, + }) + } + scheme := kruntime.NewScheme() _ = kappsv1.AddToScheme(scheme) codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kappsv1.SchemeGroupVersion) @@ -176,5 +196,7 @@ func (r *ReplicaSet) Relations() []database.Relation { database.HasMany(r.Owners, fk), database.HasMany(r.ReplicaSetLabels, fk), database.HasMany(r.Labels, database.WithoutCascadeDelete()), + database.HasMany(r.ReplicaSetAnnotations, fk), + database.HasMany(r.Annotations, database.WithoutCascadeDelete()), } } diff --git a/pkg/schema/v1/secret.go b/pkg/schema/v1/secret.go index 36528617..414cf1b2 100644 --- a/pkg/schema/v1/secret.go +++ b/pkg/schema/v1/secret.go @@ -14,13 +14,15 @@ import ( type Secret struct { Meta - Type string - Immutable types.Bool - Yaml string - Data []Data `db:"-"` - SecretData []SecretData `db:"-"` - Labels []Label `db:"-"` - SecretLabels []SecretLabel `db:"-"` + Type string + Immutable types.Bool + Yaml string + Data []Data `db:"-"` + SecretData []SecretData `db:"-"` + Labels []Label `db:"-"` + SecretLabels []SecretLabel `db:"-"` + Annotations []Annotation `db:"-"` + SecretAnnotations []SecretAnnotation `db:"-"` } type SecretData struct { @@ -33,6 +35,11 @@ type SecretLabel struct { LabelUuid types.UUID } +type SecretAnnotation struct { + SecretUuid types.UUID + AnnotationUuid types.UUID +} + func NewSecret() Resource { return &Secret{} } @@ -88,6 +95,19 @@ func (s *Secret) Obtain(k8s kmetav1.Object) { }) } + for annotationName, annotationValue := range secret.Annotations { + annotationUuid := NewUUID(s.Uuid, strings.ToLower(annotationName+":"+annotationValue)) + s.Annotations = append(s.Annotations, Annotation{ + Uuid: annotationUuid, + Name: annotationName, + Value: annotationValue, + }) + s.SecretAnnotations = append(s.SecretAnnotations, SecretAnnotation{ + SecretUuid: s.Uuid, + AnnotationUuid: annotationUuid, + }) + } + scheme := kruntime.NewScheme() _ = kcorev1.AddToScheme(scheme) codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kcorev1.SchemeGroupVersion) @@ -103,5 +123,7 @@ func (s *Secret) Relations() []database.Relation { database.HasMany(s.SecretLabels, fk), database.HasMany(s.Data, database.WithoutCascadeDelete()), database.HasMany(s.SecretData, fk), + database.HasMany(s.SecretAnnotations, fk), + database.HasMany(s.Annotations, database.WithoutCascadeDelete()), } } diff --git a/pkg/schema/v1/service.go b/pkg/schema/v1/service.go index 21c2042e..167cc848 100644 --- a/pkg/schema/v1/service.go +++ b/pkg/schema/v1/service.go @@ -30,12 +30,14 @@ type Service struct { LoadBalancerClass string InternalTrafficPolicy string Yaml string - Selectors []Selector `db:"-"` - ServiceSelectors []ServiceSelector `db:"-"` - Ports []ServicePort `db:"-"` - Conditions []ServiceCondition `db:"-"` - Labels []Label `db:"-"` - ServiceLabels []ServiceLabel `db:"-"` + Selectors []Selector `db:"-"` + ServiceSelectors []ServiceSelector `db:"-"` + Ports []ServicePort `db:"-"` + Conditions []ServiceCondition `db:"-"` + Labels []Label `db:"-"` + ServiceLabels []ServiceLabel `db:"-"` + Annotations []Annotation `db:"-"` + ServiceAnnotations []ServiceAnnotation `db:"-"` } type ServiceSelector struct { @@ -68,6 +70,11 @@ type ServiceLabel struct { LabelUuid types.UUID } +type ServiceAnnotation struct { + ServiceUuid types.UUID + AnnotationUuid types.UUID +} + func NewService() Resource { return &Service{} } @@ -182,6 +189,19 @@ func (s *Service) Obtain(k8s kmetav1.Object) { }) } + for annotationName, annotationValue := range service.Annotations { + annotationUuid := NewUUID(s.Uuid, strings.ToLower(annotationName+":"+annotationValue)) + s.Annotations = append(s.Annotations, Annotation{ + Uuid: annotationUuid, + Name: annotationName, + Value: annotationValue, + }) + s.ServiceAnnotations = append(s.ServiceAnnotations, ServiceAnnotation{ + ServiceUuid: s.Uuid, + AnnotationUuid: annotationUuid, + }) + } + scheme := kruntime.NewScheme() _ = kcorev1.AddToScheme(scheme) codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kcorev1.SchemeGroupVersion) @@ -199,5 +219,7 @@ func (s *Service) Relations() []database.Relation { database.HasMany(s.ServiceLabels, fk), database.HasMany(s.Selectors, database.WithoutCascadeDelete()), database.HasMany(s.ServiceSelectors, fk), + database.HasMany(s.ServiceAnnotations, fk), + database.HasMany(s.Annotations, database.WithoutCascadeDelete()), } } diff --git a/pkg/schema/v1/stateful_set.go b/pkg/schema/v1/stateful_set.go index 54a5aead..8bde846e 100644 --- a/pkg/schema/v1/stateful_set.go +++ b/pkg/schema/v1/stateful_set.go @@ -31,9 +31,11 @@ type StatefulSet struct { Yaml string IcingaState IcingaState IcingaStateReason string - Conditions []StatefulSetCondition `db:"-"` - Labels []Label `db:"-"` - StatefulSetLabels []StatefulSetLabel `db:"-"` + Conditions []StatefulSetCondition `db:"-"` + Labels []Label `db:"-"` + StatefulSetLabels []StatefulSetLabel `db:"-"` + Annotations []Annotation `db:"-"` + StatefulSetAnnotations []StatefulSetAnnotation `db:"-"` } type StatefulSetCondition struct { @@ -50,6 +52,11 @@ type StatefulSetLabel struct { LabelUuid types.UUID } +type StatefulSetAnnotation struct { + StatefulSetUuid types.UUID + AnnotationUuid types.UUID +} + func NewStatefulSet() Resource { return &StatefulSet{} } @@ -114,6 +121,19 @@ func (s *StatefulSet) Obtain(k8s kmetav1.Object) { }) } + for annotationName, annotationValue := range statefulSet.Annotations { + annotationUuid := NewUUID(s.Uuid, strings.ToLower(annotationName+":"+annotationValue)) + s.Annotations = append(s.Annotations, Annotation{ + Uuid: annotationUuid, + Name: annotationName, + Value: annotationValue, + }) + s.StatefulSetAnnotations = append(s.StatefulSetAnnotations, StatefulSetAnnotation{ + StatefulSetUuid: s.Uuid, + AnnotationUuid: annotationUuid, + }) + } + scheme := kruntime.NewScheme() _ = kappsv1.AddToScheme(scheme) codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kappsv1.SchemeGroupVersion) @@ -149,5 +169,7 @@ func (s *StatefulSet) Relations() []database.Relation { database.HasMany(s.Conditions, fk), database.HasMany(s.StatefulSetLabels, fk), database.HasMany(s.Labels, database.WithoutCascadeDelete()), + database.HasMany(s.StatefulSetAnnotations, fk), + database.HasMany(s.Annotations, database.WithoutCascadeDelete()), } } diff --git a/schema/mysql/schema.sql b/schema/mysql/schema.sql index 3abe05c2..5d4a8fa0 100644 --- a/schema/mysql/schema.sql +++ b/schema/mysql/schema.sql @@ -586,6 +586,91 @@ CREATE TABLE service_label ( PRIMARY KEY (service_uuid, label_uuid) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; +CREATE TABLE annotation ( + uuid binary(16) NOT NULL, + name varchar(63) COLLATE utf8mb4_unicode_ci NOT NULL, + value blob COLLATE utf8mb4_unicode_ci NOT NULL, + PRIMARY KEY (uuid) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +CREATE TABLE pod_annotation ( + pod_uuid binary(16) NOT NULL, + annotation_uuid binary(16) NOT NULL, + PRIMARY KEY (pod_uuid, annotation_uuid) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +CREATE TABLE replica_set_annotation ( + replica_set_uuid binary(16) NOT NULL, + annotation_uuid binary(16) NOT NULL, + PRIMARY KEY (replica_set_uuid, annotation_uuid) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +CREATE TABLE deployment_annotation ( + deployment_uuid binary(16) NOT NULL, + annotation_uuid binary(16) NOT NULL, + PRIMARY KEY (deployment_uuid, annotation_uuid) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +CREATE TABLE daemon_set_annotation ( + daemon_set_uuid binary(16) NOT NULL, + annotation_uuid binary(16) NOT NULL, + PRIMARY KEY (daemon_set_uuid, annotation_uuid) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +CREATE TABLE stateful_set_annotation ( + stateful_set_uuid binary(16) NOT NULL, + annotation_uuid binary(16) NOT NULL, + PRIMARY KEY (stateful_set_uuid, annotation_uuid) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +CREATE TABLE namespace_annotation ( + namespace_uuid binary(16) NOT NULL, + annotation_uuid binary(16) NOT NULL, + PRIMARY KEY (namespace_uuid, annotation_uuid) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +CREATE TABLE node_annotation ( + node_uuid binary(16) NOT NULL, + annotation_uuid binary(16) NOT NULL, + PRIMARY KEY (node_uuid, annotation_uuid) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +CREATE TABLE secret_annotation ( + secret_uuid binary(16) NOT NULL, + annotation_uuid binary(16) NOT NULL, + PRIMARY KEY (secret_uuid, annotation_uuid) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +CREATE TABLE config_map_annotation ( + config_map_uuid binary(16) NOT NULL, + annotation_uuid binary(16) NOT NULL, + PRIMARY KEY (config_map_uuid, annotation_uuid) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +CREATE TABLE service_annotation ( + service_uuid binary(16) NOT NULL, + annotation_uuid binary(16) NOT NULL, + PRIMARY KEY (service_uuid, annotation_uuid) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +CREATE TABLE job_annotation ( + job_uuid binary(16) NOT NULL, + annotation_uuid binary(16) NOT NULL, + PRIMARY KEY (job_uuid, annotation_uuid) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +CREATE TABLE cron_job_annotation ( + cron_job_uuid binary(16) NOT NULL, + annotation_uuid binary(16) NOT NULL, + PRIMARY KEY (cron_job_uuid, annotation_uuid) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + +CREATE TABLE pvc_annotation ( + pvc_uuid binary(16) NOT NULL, + annotation_uuid binary(16) NOT NULL, + PRIMARY KEY (pvc_uuid, annotation_uuid) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; + CREATE TABLE event ( uuid binary(16) NOT NULL, namespace varchar(63) NOT NULL,