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

Sync annotations #83

Merged
merged 1 commit into from
Jun 3, 2024
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
9 changes: 9 additions & 0 deletions pkg/schema/v1/annotation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package v1

import "github.com/icinga/icinga-go-library/types"

type Annotation struct {
Uuid types.UUID
Name string
Value string
}
34 changes: 28 additions & 6 deletions pkg/schema/v1/config_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -31,6 +33,11 @@ type ConfigMapLabel struct {
LabelUuid types.UUID
}

type ConfigMapAnnotation struct {
ConfigMapUuid types.UUID
AnnotationUuid types.UUID
}

func NewConfigMap() Resource {
return &ConfigMap{}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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()),
}
}
26 changes: 24 additions & 2 deletions pkg/schema/v1/cron_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,22 @@ 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 {
CronJobUuid types.UUID
LabelUuid types.UUID
}

type CronJobAnnotation struct {
CronJobUuid types.UUID
AnnotationUuid types.UUID
}

func NewCronJob() Resource {
return &CronJob{}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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()),
}
}
29 changes: 26 additions & 3 deletions pkg/schema/v1/daemon_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -46,6 +48,11 @@ type DaemonSetLabel struct {
LabelUuid types.UUID
}

type DaemonSetAnnotation struct {
DaemonSetUuid types.UUID
AnnotationUuid types.UUID
}

func NewDaemonSet() Resource {
return &DaemonSet{}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()),
}
}
28 changes: 25 additions & 3 deletions pkg/schema/v1/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -49,6 +51,11 @@ type DeploymentLabel struct {
LabelUuid types.UUID
}

type DeploymentAnnotation struct {
DeploymentUuid types.UUID
AnnotationUuid types.UUID
}

func NewDeployment() Resource {
return &Deployment{}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()),
}
}
28 changes: 25 additions & 3 deletions pkg/schema/v1/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -48,6 +50,11 @@ type JobLabel struct {
LabelUuid types.UUID
}

type JobAnnotation struct {
JobUuid types.UUID
AnnotationUuid types.UUID
}

func NewJob() Resource {
return &Job{}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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()),
}
}
32 changes: 27 additions & 5 deletions pkg/schema/v1/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -34,6 +36,11 @@ type NamespaceLabel struct {
LabelUuid types.UUID
}

type NamespaceAnnotation struct {
NamespaceUuid types.UUID
AnnotationUuid types.UUID
}

func NewNamespace() Resource {
return &Namespace{}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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()),
}
}
Loading
Loading