From 203ae21073205d3b5c6653d58b9e981246d66422 Mon Sep 17 00:00:00 2001 From: Jonada Hoxha Date: Wed, 17 Apr 2024 13:41:07 +0200 Subject: [PATCH] Add YAML serialization --- pkg/schema/v1/config_map.go | 10 ++++++++++ pkg/schema/v1/cron_job.go | 10 ++++++++++ pkg/schema/v1/daemon_set.go | 9 +++++++++ pkg/schema/v1/deployment.go | 10 ++++++++++ pkg/schema/v1/event.go | 10 ++++++++++ pkg/schema/v1/ingress.go | 10 ++++++++++ pkg/schema/v1/job.go | 10 ++++++++++ pkg/schema/v1/namespace.go | 10 ++++++++++ pkg/schema/v1/node.go | 10 ++++++++++ pkg/schema/v1/persistent_volume.go | 10 ++++++++++ pkg/schema/v1/pod.go | 17 +++++++++++++++++ pkg/schema/v1/pvc.go | 10 ++++++++++ pkg/schema/v1/replica_set.go | 10 ++++++++++ pkg/schema/v1/secret.go | 10 ++++++++++ pkg/schema/v1/service.go | 10 ++++++++++ pkg/schema/v1/stateful_set.go | 10 ++++++++++ schema/mysql/schema.sql | 16 ++++++++++++++++ 17 files changed, 182 insertions(+) diff --git a/pkg/schema/v1/config_map.go b/pkg/schema/v1/config_map.go index 34e55166..aabd0713 100644 --- a/pkg/schema/v1/config_map.go +++ b/pkg/schema/v1/config_map.go @@ -5,6 +5,9 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/types" kcorev1 "k8s.io/api/core/v1" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kruntime "k8s.io/apimachinery/pkg/runtime" + kserializer "k8s.io/apimachinery/pkg/runtime/serializer" + kjson "k8s.io/apimachinery/pkg/runtime/serializer/json" "strings" ) @@ -12,6 +15,7 @@ type ConfigMap struct { Meta Id types.Binary Immutable types.Bool + Yaml string Data []Data `db:"-"` ConfigMapsData []ConfigMapData `db:"-"` Labels []Label `db:"-"` @@ -73,6 +77,12 @@ func (c *ConfigMap) Obtain(k8s kmetav1.Object) { LabelId: labelId, }) } + + scheme := kruntime.NewScheme() + _ = kcorev1.AddToScheme(scheme) + codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kcorev1.SchemeGroupVersion) + output, _ := kruntime.Encode(codec, configMap) + c.Yaml = string(output) } func (c *ConfigMap) Relations() []database.Relation { diff --git a/pkg/schema/v1/cron_job.go b/pkg/schema/v1/cron_job.go index fe0ed3bd..e202f9f6 100644 --- a/pkg/schema/v1/cron_job.go +++ b/pkg/schema/v1/cron_job.go @@ -5,6 +5,9 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/types" kbatchv1 "k8s.io/api/batch/v1" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kruntime "k8s.io/apimachinery/pkg/runtime" + kserializer "k8s.io/apimachinery/pkg/runtime/serializer" + kjson "k8s.io/apimachinery/pkg/runtime/serializer/json" "strings" ) @@ -21,6 +24,7 @@ type CronJob struct { Active int32 LastScheduleTime types.UnixMilli LastSuccessfulTime types.UnixMilli + Yaml string Labels []Label `db:"-"` CronJobLabels []CronJobLabel `db:"-"` } @@ -89,6 +93,12 @@ func (c *CronJob) Obtain(k8s kmetav1.Object) { LabelId: labelId, }) } + + scheme := kruntime.NewScheme() + _ = kbatchv1.AddToScheme(scheme) + codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kbatchv1.SchemeGroupVersion) + output, _ := kruntime.Encode(codec, cronJob) + c.Yaml = string(output) } func (c *CronJob) Relations() []database.Relation { diff --git a/pkg/schema/v1/daemon_set.go b/pkg/schema/v1/daemon_set.go index e3194f7e..3df39b17 100644 --- a/pkg/schema/v1/daemon_set.go +++ b/pkg/schema/v1/daemon_set.go @@ -6,6 +6,9 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/types" kappsv1 "k8s.io/api/apps/v1" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kruntime "k8s.io/apimachinery/pkg/runtime" + kserializer "k8s.io/apimachinery/pkg/runtime/serializer" + kjson "k8s.io/apimachinery/pkg/runtime/serializer/json" "strings" ) @@ -21,6 +24,7 @@ type DaemonSet struct { UpdateNumberScheduled int32 NumberAvailable int32 NumberUnavailable int32 + Yaml string Conditions []DaemonSetCondition `db:"-"` Labels []Label `db:"-"` DaemonSetLabels []DaemonSetLabel `db:"-"` @@ -83,6 +87,11 @@ func (d *DaemonSet) Obtain(k8s kmetav1.Object) { LabelId: labelId, }) } + scheme := kruntime.NewScheme() + _ = kappsv1.AddToScheme(scheme) + codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kappsv1.SchemeGroupVersion) + output, _ := kruntime.Encode(codec, daemonSet) + d.Yaml = string(output) } func (d *DaemonSet) Relations() []database.Relation { diff --git a/pkg/schema/v1/deployment.go b/pkg/schema/v1/deployment.go index b6f1b63d..f7c154e8 100644 --- a/pkg/schema/v1/deployment.go +++ b/pkg/schema/v1/deployment.go @@ -6,6 +6,9 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/types" kappsv1 "k8s.io/api/apps/v1" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kruntime "k8s.io/apimachinery/pkg/runtime" + kserializer "k8s.io/apimachinery/pkg/runtime/serializer" + kjson "k8s.io/apimachinery/pkg/runtime/serializer/json" "strings" ) @@ -22,6 +25,7 @@ type Deployment struct { ReadyReplicas int32 AvailableReplicas int32 UnavailableReplicas int32 + Yaml string Conditions []DeploymentCondition `db:"-"` Labels []Label `db:"-"` DeploymentLabels []DeploymentLabel `db:"-"` @@ -97,6 +101,12 @@ func (d *Deployment) Obtain(k8s kmetav1.Object) { LabelId: labelId, }) } + + scheme := kruntime.NewScheme() + _ = kappsv1.AddToScheme(scheme) + codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kappsv1.SchemeGroupVersion) + output, _ := kruntime.Encode(codec, deployment) + d.Yaml = string(output) } func (d *Deployment) Relations() []database.Relation { diff --git a/pkg/schema/v1/event.go b/pkg/schema/v1/event.go index 8b6fbfca..307d7698 100644 --- a/pkg/schema/v1/event.go +++ b/pkg/schema/v1/event.go @@ -4,6 +4,9 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/types" keventsv1 "k8s.io/api/events/v1" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kruntime "k8s.io/apimachinery/pkg/runtime" + kserializer "k8s.io/apimachinery/pkg/runtime/serializer" + kjson "k8s.io/apimachinery/pkg/runtime/serializer/json" ) type Event struct { @@ -21,6 +24,7 @@ type Event struct { FirstSeen types.UnixMilli LastSeen types.UnixMilli Count int32 + Yaml string } func NewEvent() Resource { @@ -53,6 +57,12 @@ func (e *Event) Obtain(k8s kmetav1.Object) { e.LastSeen = types.UnixMilli(event.DeprecatedLastTimestamp.Time) } e.Count = event.DeprecatedCount + + scheme := kruntime.NewScheme() + _ = keventsv1.AddToScheme(scheme) + codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), keventsv1.SchemeGroupVersion) + output, _ := kruntime.Encode(codec, event) + e.Yaml = string(output) // e.FirstSeen = types.UnixMilli(event.EventTime.Time) // if event.Series != nil { // e.LastSeen = types.UnixMilli(event.Series.LastObservedTime.Time) diff --git a/pkg/schema/v1/ingress.go b/pkg/schema/v1/ingress.go index 35112bad..f3c45ee6 100644 --- a/pkg/schema/v1/ingress.go +++ b/pkg/schema/v1/ingress.go @@ -6,11 +6,15 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/types" networkingv1 "k8s.io/api/networking/v1" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kruntime "k8s.io/apimachinery/pkg/runtime" + kserializer "k8s.io/apimachinery/pkg/runtime/serializer" + kjson "k8s.io/apimachinery/pkg/runtime/serializer/json" ) type Ingress struct { Meta Id types.Binary + Yaml string IngressTls []IngressTls `db:"-"` IngressBackendService []IngressBackendService `db:"-"` IngressBackendResource []IngressBackendResource `db:"-"` @@ -156,6 +160,12 @@ func (i *Ingress) Obtain(k8s kmetav1.Object) { } } + + scheme := kruntime.NewScheme() + _ = networkingv1.AddToScheme(scheme) + codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), networkingv1.SchemeGroupVersion) + output, _ := kruntime.Encode(codec, ingress) + i.Yaml = string(output) } func (i *Ingress) Relations() []database.Relation { diff --git a/pkg/schema/v1/job.go b/pkg/schema/v1/job.go index 548fee9a..2aae411e 100644 --- a/pkg/schema/v1/job.go +++ b/pkg/schema/v1/job.go @@ -7,6 +7,9 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/types" kbatchv1 "k8s.io/api/batch/v1" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kruntime "k8s.io/apimachinery/pkg/runtime" + kserializer "k8s.io/apimachinery/pkg/runtime/serializer" + kjson "k8s.io/apimachinery/pkg/runtime/serializer/json" "strings" ) @@ -25,6 +28,7 @@ type Job struct { Active int32 Succeeded int32 Failed int32 + Yaml string Conditions []JobCondition `db:"-"` Labels []Label `db:"-"` JobLabels []JobLabel `db:"-"` @@ -136,6 +140,12 @@ func (j *Job) Obtain(k8s kmetav1.Object) { LabelId: labelId, }) } + + scheme := kruntime.NewScheme() + _ = kbatchv1.AddToScheme(scheme) + codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kbatchv1.SchemeGroupVersion) + output, _ := kruntime.Encode(codec, job) + j.Yaml = string(output) } func (j *Job) Relations() []database.Relation { diff --git a/pkg/schema/v1/namespace.go b/pkg/schema/v1/namespace.go index d28067fd..44e8de37 100644 --- a/pkg/schema/v1/namespace.go +++ b/pkg/schema/v1/namespace.go @@ -5,6 +5,9 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/types" kcorev1 "k8s.io/api/core/v1" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kruntime "k8s.io/apimachinery/pkg/runtime" + kserializer "k8s.io/apimachinery/pkg/runtime/serializer" + kjson "k8s.io/apimachinery/pkg/runtime/serializer/json" "strings" ) @@ -12,6 +15,7 @@ type Namespace struct { Meta Id types.Binary Phase string + Yaml string Conditions []NamespaceCondition `db:"-"` Labels []Label `db:"-"` NamespaceLabels []NamespaceLabel `db:"-"` @@ -66,6 +70,12 @@ func (n *Namespace) Obtain(k8s kmetav1.Object) { LabelId: labelId, }) } + + scheme := kruntime.NewScheme() + _ = kcorev1.AddToScheme(scheme) + codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kcorev1.SchemeGroupVersion) + output, _ := kruntime.Encode(codec, namespace) + n.Yaml = string(output) } func (n *Namespace) Relations() []database.Relation { diff --git a/pkg/schema/v1/node.go b/pkg/schema/v1/node.go index 93a473a4..5cf551b5 100644 --- a/pkg/schema/v1/node.go +++ b/pkg/schema/v1/node.go @@ -6,6 +6,9 @@ import ( "github.com/pkg/errors" kcorev1 "k8s.io/api/core/v1" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kruntime "k8s.io/apimachinery/pkg/runtime" + kserializer "k8s.io/apimachinery/pkg/runtime/serializer" + kjson "k8s.io/apimachinery/pkg/runtime/serializer/json" knet "k8s.io/utils/net" "net" "strings" @@ -23,6 +26,7 @@ type Node struct { MemoryCapacity int64 MemoryAllocatable int64 PodCapacity int64 + Yaml string Conditions []NodeCondition `db:"-"` Volumes []NodeVolume `db:"-"` Labels []Label `db:"-"` @@ -125,6 +129,12 @@ func (n *Node) Obtain(k8s kmetav1.Object) { LabelId: labelId, }) } + + scheme := kruntime.NewScheme() + _ = kcorev1.AddToScheme(scheme) + codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kcorev1.SchemeGroupVersion) + output, _ := kruntime.Encode(codec, node) + n.Yaml = string(output) } func (n *Node) Relations() []database.Relation { diff --git a/pkg/schema/v1/persistent_volume.go b/pkg/schema/v1/persistent_volume.go index 051785b9..eba765be 100644 --- a/pkg/schema/v1/persistent_volume.go +++ b/pkg/schema/v1/persistent_volume.go @@ -7,6 +7,9 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/types" kcorev1 "k8s.io/api/core/v1" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kruntime "k8s.io/apimachinery/pkg/runtime" + kserializer "k8s.io/apimachinery/pkg/runtime/serializer" + kjson "k8s.io/apimachinery/pkg/runtime/serializer/json" ktypes "k8s.io/apimachinery/pkg/types" ) @@ -23,6 +26,7 @@ type PersistentVolume struct { Phase string Reason string Message string + Yaml string Claim *PersistentVolumeClaimRef `db:"-"` } @@ -70,6 +74,12 @@ func (p *PersistentVolume) Obtain(k8s kmetav1.Object) { Uid: persistentVolume.Spec.ClaimRef.UID, } } + + scheme := kruntime.NewScheme() + _ = kcorev1.AddToScheme(scheme) + codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kcorev1.SchemeGroupVersion) + output, _ := kruntime.Encode(codec, persistentVolume) + p.Yaml = string(output) } func (p *PersistentVolume) Relations() []database.Relation { diff --git a/pkg/schema/v1/pod.go b/pkg/schema/v1/pod.go index 3c1e6ea2..08376658 100644 --- a/pkg/schema/v1/pod.go +++ b/pkg/schema/v1/pod.go @@ -7,6 +7,9 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/types" kcorev1 "k8s.io/api/core/v1" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kruntime "k8s.io/apimachinery/pkg/runtime" + kserializer "k8s.io/apimachinery/pkg/runtime/serializer" + kjson "k8s.io/apimachinery/pkg/runtime/serializer/json" ktypes "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes" "strings" @@ -31,6 +34,7 @@ type Pod struct { Message string Qos string RestartPolicy string + Yaml string Conditions []PodCondition `db:"-"` Containers []Container `db:"-"` Owners []PodOwner `db:"-"` @@ -41,6 +45,13 @@ type Pod struct { factory *PodFactory } +type PodYaml struct { + PodId types.Binary + Kind string + ApiVersion string + YamlData string +} + type PodCondition struct { PodId types.Binary Type string @@ -267,6 +278,12 @@ func (p *Pod) Obtain(k8s kmetav1.Object) { }) } } + + scheme := kruntime.NewScheme() + _ = kcorev1.AddToScheme(scheme) + codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kcorev1.SchemeGroupVersion) + output, _ := kruntime.Encode(codec, pod) + p.Yaml = string(output) } func (p *Pod) Relations() []database.Relation { diff --git a/pkg/schema/v1/pvc.go b/pkg/schema/v1/pvc.go index 73499a0a..613fd185 100644 --- a/pkg/schema/v1/pvc.go +++ b/pkg/schema/v1/pvc.go @@ -7,6 +7,9 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/types" kcorev1 "k8s.io/api/core/v1" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kruntime "k8s.io/apimachinery/pkg/runtime" + kserializer "k8s.io/apimachinery/pkg/runtime/serializer" + kjson "k8s.io/apimachinery/pkg/runtime/serializer/json" "strings" ) @@ -42,6 +45,7 @@ type Pvc struct { VolumeName string VolumeMode sql.NullString StorageClass sql.NullString + Yaml string Conditions []PvcCondition `db:"-"` Labels []Label `db:"-"` PvcLabels []PvcLabel `db:"-"` @@ -120,6 +124,12 @@ func (p *Pvc) Obtain(k8s kmetav1.Object) { LabelId: labelId, }) } + + scheme := kruntime.NewScheme() + _ = kcorev1.AddToScheme(scheme) + codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kcorev1.SchemeGroupVersion) + output, _ := kruntime.Encode(codec, pvc) + p.Yaml = string(output) } func (p *Pvc) Relations() []database.Relation { diff --git a/pkg/schema/v1/replica_set.go b/pkg/schema/v1/replica_set.go index 670201aa..73cbab61 100644 --- a/pkg/schema/v1/replica_set.go +++ b/pkg/schema/v1/replica_set.go @@ -6,6 +6,9 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/types" kappsv1 "k8s.io/api/apps/v1" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kruntime "k8s.io/apimachinery/pkg/runtime" + kserializer "k8s.io/apimachinery/pkg/runtime/serializer" + kjson "k8s.io/apimachinery/pkg/runtime/serializer/json" ktypes "k8s.io/apimachinery/pkg/types" "strings" ) @@ -19,6 +22,7 @@ type ReplicaSet struct { FullyLabeledReplicas int32 ReadyReplicas int32 AvailableReplicas int32 + Yaml string Conditions []ReplicaSetCondition `db:"-"` Owners []ReplicaSetOwner `db:"-"` Labels []Label `db:"-"` @@ -116,6 +120,12 @@ func (r *ReplicaSet) Obtain(k8s kmetav1.Object) { LabelId: labelId, }) } + + scheme := kruntime.NewScheme() + _ = kappsv1.AddToScheme(scheme) + codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kappsv1.SchemeGroupVersion) + output, _ := kruntime.Encode(codec, replicaSet) + r.Yaml = string(output) } func (r *ReplicaSet) Relations() []database.Relation { diff --git a/pkg/schema/v1/secret.go b/pkg/schema/v1/secret.go index 175688e3..f45b0d8e 100644 --- a/pkg/schema/v1/secret.go +++ b/pkg/schema/v1/secret.go @@ -6,6 +6,9 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/types" kcorev1 "k8s.io/api/core/v1" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kruntime "k8s.io/apimachinery/pkg/runtime" + kserializer "k8s.io/apimachinery/pkg/runtime/serializer" + kjson "k8s.io/apimachinery/pkg/runtime/serializer/json" "strings" ) @@ -14,6 +17,7 @@ type Secret struct { Id types.Binary Type string Immutable types.Bool + Yaml string Data []Data `db:"-"` SecretData []SecretData `db:"-"` Labels []Label `db:"-"` @@ -85,6 +89,12 @@ func (s *Secret) Obtain(k8s kmetav1.Object) { LabelId: labelId, }) } + + scheme := kruntime.NewScheme() + _ = kcorev1.AddToScheme(scheme) + codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kcorev1.SchemeGroupVersion) + output, _ := kruntime.Encode(codec, secret) + s.Yaml = string(output) } func (s *Secret) Relations() []database.Relation { diff --git a/pkg/schema/v1/service.go b/pkg/schema/v1/service.go index baa486a8..4d1bb0a7 100644 --- a/pkg/schema/v1/service.go +++ b/pkg/schema/v1/service.go @@ -7,6 +7,9 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/types" kcorev1 "k8s.io/api/core/v1" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kruntime "k8s.io/apimachinery/pkg/runtime" + kserializer "k8s.io/apimachinery/pkg/runtime/serializer" + kjson "k8s.io/apimachinery/pkg/runtime/serializer/json" "strings" ) @@ -27,6 +30,7 @@ type Service struct { AllocateLoadBalancerNodePorts types.Bool LoadBalancerClass string InternalTrafficPolicy string + Yaml string Selectors []Selector `db:"-"` ServiceSelectors []ServiceSelector `db:"-"` Ports []ServicePort `db:"-"` @@ -179,6 +183,12 @@ func (s *Service) Obtain(k8s kmetav1.Object) { LabelId: labelId, }) } + + scheme := kruntime.NewScheme() + _ = kcorev1.AddToScheme(scheme) + codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kcorev1.SchemeGroupVersion) + output, _ := kruntime.Encode(codec, service) + s.Yaml = string(output) } func (s *Service) Relations() []database.Relation { diff --git a/pkg/schema/v1/stateful_set.go b/pkg/schema/v1/stateful_set.go index 21fa0b41..c9813df6 100644 --- a/pkg/schema/v1/stateful_set.go +++ b/pkg/schema/v1/stateful_set.go @@ -6,6 +6,9 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/types" kappsv1 "k8s.io/api/apps/v1" kmetav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + kruntime "k8s.io/apimachinery/pkg/runtime" + kserializer "k8s.io/apimachinery/pkg/runtime/serializer" + kjson "k8s.io/apimachinery/pkg/runtime/serializer/json" "strings" ) @@ -25,6 +28,7 @@ type StatefulSet struct { CurrentReplicas int32 UpdatedReplicas int32 AvailableReplicas int32 + Yaml string Conditions []StatefulSetCondition `db:"-"` Labels []Label `db:"-"` StatefulSetLabels []StatefulSetLabel `db:"-"` @@ -106,6 +110,12 @@ func (s *StatefulSet) Obtain(k8s kmetav1.Object) { LabelId: labelId, }) } + + scheme := kruntime.NewScheme() + _ = kappsv1.AddToScheme(scheme) + codec := kserializer.NewCodecFactory(scheme).EncoderForVersion(kjson.NewYAMLSerializer(kjson.DefaultMetaFactory, scheme, scheme), kappsv1.SchemeGroupVersion) + output, _ := kruntime.Encode(codec, statefulSet) + s.Yaml = string(output) } func (s *StatefulSet) Relations() []database.Relation { diff --git a/schema/mysql/schema.sql b/schema/mysql/schema.sql index 9f8c0229..a6bddee1 100644 --- a/schema/mysql/schema.sql +++ b/schema/mysql/schema.sql @@ -5,6 +5,7 @@ CREATE TABLE namespace ( uid varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, resource_version varchar(255) NOT NULL, phase enum('active', 'terminating') COLLATE utf8mb4_unicode_ci NOT NULL, + yaml mediumblob NOT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; @@ -34,6 +35,7 @@ CREATE TABLE node ( memory_capacity bigint unsigned NOT NULL, memory_allocatable bigint unsigned NOT NULL, pod_capacity int unsigned NOT NULL, + yaml mediumblob not null, created bigint unsigned NOT NULL, PRIMARY KEY (namespace, name) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; @@ -75,6 +77,7 @@ CREATE TABLE pod ( reason varchar(255) NULL DEFAULT NULL, message varchar(255) NULL DEFAULT NULL, qos enum('guaranteed', 'burstable', 'best_effort') COLLATE utf8mb4_unicode_ci NOT NULL, + yaml mediumblob not null, created bigint unsigned NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; @@ -176,6 +179,7 @@ CREATE TABLE deployment ( ready_replicas int unsigned NOT NULL, available_replicas int unsigned NOT NULL, unavailable_replicas int unsigned NOT NULL, + yaml mediumblob NOT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; @@ -211,6 +215,7 @@ CREATE TABLE service ( allocate_load_balancer_node_ports enum('n', 'y') COLLATE utf8mb4_unicode_ci NOT NULL, load_balancer_class varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, internal_traffic_policy enum('cluster', 'local') COLLATE utf8mb4_unicode_ci NOT NULL, + yaml mediumblob NOT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; @@ -300,6 +305,7 @@ CREATE TABLE ingress ( name varchar(63) COLLATE utf8mb4_unicode_ci NOT NULL, uid varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, resource_version varchar(255) NOT NULL, + yaml mediumblob NOT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; @@ -353,6 +359,7 @@ CREATE TABLE replica_set ( fully_labeled_replicas int unsigned NOT NULL, ready_replicas int unsigned NOT NULL, available_replicas int unsigned NOT NULL, + yaml mediumblob NOT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; @@ -392,6 +399,7 @@ CREATE TABLE daemon_set ( update_number_scheduled int unsigned NOT NULL, number_available int unsigned NOT NULL, number_unavailable int unsigned NOT NULL, + yaml mediumblob NOT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; @@ -425,6 +433,7 @@ CREATE TABLE stateful_set ( current_replicas int unsigned NOT NULL, updated_replicas int unsigned NOT NULL, available_replicas int unsigned NOT NULL, + yaml mediumblob NOT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; @@ -447,6 +456,7 @@ CREATE TABLE secret ( resource_version varchar(255) NOT NULL, type varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, immutable enum('n', 'y') COLLATE utf8mb4_unicode_ci NOT NULL, + yaml mediumblob NOT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; @@ -458,6 +468,7 @@ CREATE TABLE config_map ( uid varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, resource_version varchar(255) NOT NULL, immutable enum('n', 'y') COLLATE utf8mb4_unicode_ci NOT NULL, + yaml mediumblob NOT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; @@ -572,6 +583,7 @@ CREATE TABLE event ( first_seen bigint unsigned NOT NULL, last_seen bigint unsigned NOT NULL, count int unsigned NOT NULL, + yaml mediumblob NOT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; @@ -603,6 +615,7 @@ CREATE TABLE pvc ( volume_name varchar(63) COLLATE utf8mb4_unicode_ci NOT NULL, volume_mode enum('block', 'filesystem') COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL, storage_class varchar(255) COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL, + yaml mediumblob NOT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; @@ -634,6 +647,7 @@ CREATE TABLE persistent_volume ( storage_class varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL, volume_source longtext NOT NULL, reclaim_policy enum('recycle', 'delete', 'retain') COLLATE utf8mb4_unicode_ci NOT NULL, + yaml mediumblob NOT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; @@ -664,6 +678,7 @@ CREATE TABLE job ( active int unsigned NOT NULL, succeeded int unsigned NOT NULL, failed int unsigned NOT NULL, + yaml mediumblob NOT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; @@ -701,6 +716,7 @@ CREATE TABLE cron_job ( failed_jobs_history_limit int unsigned NOT NULL, last_schedule_time bigint unsigned NULL DEFAULT NULL, last_successful_time bigint unsigned NULL DEFAULT NULL, + yaml mediumblob NOT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;