From 647028db6a78add7cdc5d84750e5418dffa57531 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 6e40a02c..97c619c5 100644 --- a/pkg/schema/v1/config_map.go +++ b/pkg/schema/v1/config_map.go @@ -5,12 +5,16 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/database" 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" ) type ConfigMap struct { Meta Immutable types.Bool + Yaml string Data []Data `db:"-"` ConfigMapsData []ConfigMapData `db:"-"` Labels []Label `db:"-"` @@ -70,6 +74,12 @@ func (c *ConfigMap) Obtain(k8s kmetav1.Object) { LabelUuid: labelUuid, }) } + + 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 37a73be2..6efbc2fe 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/database" 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" ) @@ -20,6 +23,7 @@ type CronJob struct { Active int32 LastScheduleTime types.UnixMilli LastSuccessfulTime types.UnixMilli + Yaml string Labels []Label `db:"-"` CronJobLabels []CronJobLabel `db:"-"` } @@ -87,6 +91,12 @@ func (c *CronJob) Obtain(k8s kmetav1.Object) { LabelUuid: labelUuid, }) } + + 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 70787cf4..3a3621e2 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/strcase" 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" ) @@ -20,6 +23,7 @@ type DaemonSet struct { UpdateNumberScheduled int32 NumberAvailable int32 NumberUnavailable int32 + Yaml string Conditions []DaemonSetCondition `db:"-"` Labels []Label `db:"-"` DaemonSetLabels []DaemonSetLabel `db:"-"` @@ -81,6 +85,11 @@ func (d *DaemonSet) Obtain(k8s kmetav1.Object) { LabelUuid: labelUuid, }) } + 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 fb34e579..7ed34dc5 100644 --- a/pkg/schema/v1/deployment.go +++ b/pkg/schema/v1/deployment.go @@ -6,6 +6,9 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/strcase" 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 Deployment struct { ReadyReplicas int32 AvailableReplicas int32 UnavailableReplicas int32 + Yaml string Conditions []DeploymentCondition `db:"-"` Labels []Label `db:"-"` DeploymentLabels []DeploymentLabel `db:"-"` @@ -96,6 +100,12 @@ func (d *Deployment) Obtain(k8s kmetav1.Object) { LabelUuid: labelUuid, }) } + + 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 44930800..e6728f58 100644 --- a/pkg/schema/v1/event.go +++ b/pkg/schema/v1/event.go @@ -4,6 +4,9 @@ import ( "github.com/icinga/icinga-go-library/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 { @@ -20,6 +23,7 @@ type Event struct { FirstSeen types.UnixMilli LastSeen types.UnixMilli Count int32 + Yaml string } func NewEvent() Resource { @@ -51,6 +55,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 5652be10..2ce41643 100644 --- a/pkg/schema/v1/ingress.go +++ b/pkg/schema/v1/ingress.go @@ -6,10 +6,14 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/database" 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 + Yaml string IngressTls []IngressTls `db:"-"` IngressBackendService []IngressBackendService `db:"-"` IngressBackendResource []IngressBackendResource `db:"-"` @@ -154,6 +158,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 ffcf418a..bfee47c4 100644 --- a/pkg/schema/v1/job.go +++ b/pkg/schema/v1/job.go @@ -7,6 +7,9 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/strcase" 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" ) @@ -24,6 +27,7 @@ type Job struct { Active int32 Succeeded int32 Failed int32 + Yaml string Conditions []JobCondition `db:"-"` Labels []Label `db:"-"` JobLabels []JobLabel `db:"-"` @@ -134,6 +138,12 @@ func (j *Job) Obtain(k8s kmetav1.Object) { LabelUuid: labelUuid, }) } + + 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 71fbbc3b..1a6dbc9d 100644 --- a/pkg/schema/v1/namespace.go +++ b/pkg/schema/v1/namespace.go @@ -5,12 +5,16 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/database" 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" ) type Namespace struct { Meta Phase string + Yaml string Conditions []NamespaceCondition `db:"-"` Labels []Label `db:"-"` NamespaceLabels []NamespaceLabel `db:"-"` @@ -64,6 +68,12 @@ func (n *Namespace) Obtain(k8s kmetav1.Object) { LabelUuid: labelUuid, }) } + + 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 d13c8ed7..97ab4ec1 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" @@ -22,6 +25,7 @@ type Node struct { MemoryCapacity int64 MemoryAllocatable int64 PodCapacity int64 + Yaml string Conditions []NodeCondition `db:"-"` Volumes []NodeVolume `db:"-"` Labels []Label `db:"-"` @@ -123,6 +127,12 @@ func (n *Node) Obtain(k8s kmetav1.Object) { LabelUuid: labelUuid, }) } + + 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 48e692e5..ef352fd4 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/strcase" 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" ) @@ -22,6 +25,7 @@ type PersistentVolume struct { Phase string Reason string Message string + Yaml string Claim *PersistentVolumeClaimRef `db:"-"` } @@ -68,6 +72,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 c51bdc5c..478eb58d 100644 --- a/pkg/schema/v1/pod.go +++ b/pkg/schema/v1/pod.go @@ -7,6 +7,9 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/strcase" 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" @@ -30,6 +33,7 @@ type Pod struct { Message string Qos string RestartPolicy string + Yaml string Conditions []PodCondition `db:"-"` Containers []Container `db:"-"` Owners []PodOwner `db:"-"` @@ -40,6 +44,13 @@ type Pod struct { factory *PodFactory } +type PodYaml struct { + PodId types.Binary + Kind string + ApiVersion string + YamlData string +} + type PodCondition struct { PodUuid types.UUID Type string @@ -265,6 +276,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 430a432d..5f58381b 100644 --- a/pkg/schema/v1/pvc.go +++ b/pkg/schema/v1/pvc.go @@ -7,6 +7,9 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/strcase" 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" ) @@ -41,6 +44,7 @@ type Pvc struct { VolumeName string VolumeMode sql.NullString StorageClass sql.NullString + Yaml string Conditions []PvcCondition `db:"-"` Labels []Label `db:"-"` PvcLabels []PvcLabel `db:"-"` @@ -118,6 +122,12 @@ func (p *Pvc) Obtain(k8s kmetav1.Object) { LabelUuid: labelUuid, }) } + + 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 e0471315..277aca00 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/strcase" 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" ) @@ -18,6 +21,7 @@ type ReplicaSet struct { FullyLabeledReplicas int32 ReadyReplicas int32 AvailableReplicas int32 + Yaml string Conditions []ReplicaSetCondition `db:"-"` Owners []ReplicaSetOwner `db:"-"` Labels []Label `db:"-"` @@ -114,6 +118,12 @@ func (r *ReplicaSet) Obtain(k8s kmetav1.Object) { LabelUuid: labelUuid, }) } + + 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 396ad522..36528617 100644 --- a/pkg/schema/v1/secret.go +++ b/pkg/schema/v1/secret.go @@ -6,6 +6,9 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/database" 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" ) @@ -13,6 +16,7 @@ type Secret struct { Meta Type string Immutable types.Bool + Yaml string Data []Data `db:"-"` SecretData []SecretData `db:"-"` Labels []Label `db:"-"` @@ -83,6 +87,12 @@ func (s *Secret) Obtain(k8s kmetav1.Object) { LabelUuid: labelUuid, }) } + + 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 66da9aa1..21c2042e 100644 --- a/pkg/schema/v1/service.go +++ b/pkg/schema/v1/service.go @@ -7,6 +7,9 @@ import ( "github.com/icinga/icinga-kubernetes/pkg/strcase" 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" ) @@ -26,6 +29,7 @@ type Service struct { AllocateLoadBalancerNodePorts types.Bool LoadBalancerClass string InternalTrafficPolicy string + Yaml string Selectors []Selector `db:"-"` ServiceSelectors []ServiceSelector `db:"-"` Ports []ServicePort `db:"-"` @@ -177,6 +181,12 @@ func (s *Service) Obtain(k8s kmetav1.Object) { LabelUuid: labelUuid, }) } + + 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 96a6ad45..a560354d 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/strcase" 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" ) @@ -24,6 +27,7 @@ type StatefulSet struct { CurrentReplicas int32 UpdatedReplicas int32 AvailableReplicas int32 + Yaml string Conditions []StatefulSetCondition `db:"-"` Labels []Label `db:"-"` StatefulSetLabels []StatefulSetLabel `db:"-"` @@ -105,6 +109,12 @@ func (s *StatefulSet) Obtain(k8s kmetav1.Object) { LabelUuid: labelUuid, }) } + + 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 a4b4cf4c..a6fbf6d7 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 DEFAULT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (uuid) ) 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 DEFAULT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (uuid) ) 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 DEFAULT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (uuid) ) 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 DEFAULT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (uuid) ) 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 DEFAULT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (uuid) ) 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 DEFAULT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (uuid) ) 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 DEFAULT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (uuid) ) 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 DEFAULT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (uuid) ) 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 DEFAULT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (uuid) ) 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 DEFAULT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (uuid) ) 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 DEFAULT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (uuid) ) 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 DEFAULT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (uuid) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin; @@ -603,6 +615,7 @@ CREATE TABLE pvc ( volume_name varchar(253) 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 DEFAULT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (uuid) ) 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 DEFAULT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (uuid) ) 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 DEFAULT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (uuid) ) 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 DEFAULT NULL, created bigint unsigned NOT NULL, PRIMARY KEY (uuid) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;