From abdb003f40e7dff61d94632643c6ba24ab6d4c28 Mon Sep 17 00:00:00 2001 From: Felix Kunde Date: Fri, 16 Aug 2019 13:22:45 +0200 Subject: [PATCH] additional printer columns for CRDs (#653) * additional printer columns for CRDs --- .../templates/customrresourcedefinition.yaml | 54 ++++++++++- pkg/apis/acid.zalan.do/v1/crds.go | 93 ++++++++++++++++++- 2 files changed, 143 insertions(+), 4 deletions(-) diff --git a/charts/postgres-operator/templates/customrresourcedefinition.yaml b/charts/postgres-operator/templates/customrresourcedefinition.yaml index f021a8ced..1c6f1564e 100644 --- a/charts/postgres-operator/templates/customrresourcedefinition.yaml +++ b/charts/postgres-operator/templates/customrresourcedefinition.yaml @@ -18,6 +18,38 @@ spec: singular: postgresql shortNames: - pg + additionalPrinterColumns: + - name: Team + type: string + description: Team responsible for Postgres CLuster + JSONPath: .spec.teamId + - name: Version + type: string + description: PostgreSQL version + JSONPath: .spec.postgresql.version + - name: Pods + type: integer + description: Number of Pods per Postgres cluster + JSONPath: .spec.numberOfInstances + - name: Volume + type: string + description: Size of the bound volume + JSONPath: .spec.volume.size + - name: CPU-Request + type: string + description: Requested CPU for Postgres containers + JSONPath: .spec.resources.requests.cpu + - name: Memory-Request + type: string + description: Requested memory for Postgres containers + JSONPath: .spec.resources.requests.memory + - name: Age + type: date + JSONPath: .metadata.creationTimestamp + - name: Status + type: string + description: Current sync status of postgresql resource + JSONPath: .status.PostgresClusterStatus scope: Namespaced subresources: status: {} @@ -42,7 +74,27 @@ spec: plural: operatorconfigurations singular: operatorconfiguration shortNames: - - pgc + - opconfig + additionalPrinterColumns: + - name: Image + type: string + description: Spilo image to be used for Pods + JSONPath: .configuration.docker_image + - name: Cluster-Label + type: string + description: Label for K8s resources created by operator + JSONPath: .configuration.kubernetes.cluster_name_label + - name: Service-Account + type: string + description: Name of service account to be used + JSONPath: .configuration.kubernetes.pod_service_account_name + - name: Min-Instances + type: integer + description: Minimum number of instances per Postgres cluster + JSONPath: .configuration.min_instances + - name: Age + type: date + JSONPath: .metadata.creationTimestamp scope: Namespaced subresources: status: {} diff --git a/pkg/apis/acid.zalan.do/v1/crds.go b/pkg/apis/acid.zalan.do/v1/crds.go index a77f490f0..50833db26 100644 --- a/pkg/apis/acid.zalan.do/v1/crds.go +++ b/pkg/apis/acid.zalan.do/v1/crds.go @@ -19,7 +19,91 @@ const ( OperatorConfigCRDResourceShort = "opconfig" ) -func buildCRD(name, kind, plural, short string) *apiextv1beta1.CustomResourceDefinition { +// PostgresCRDResourceColumns definition of AdditionalPrinterColumns for postgresql CRD +var PostgresCRDResourceColumns = []apiextv1beta1.CustomResourceColumnDefinition{ + apiextv1beta1.CustomResourceColumnDefinition{ + Name: "Team", + Type: "string", + Description: "Team responsible for Postgres cluster", + JSONPath: ".spec.teamId", + }, + apiextv1beta1.CustomResourceColumnDefinition{ + Name: "Version", + Type: "string", + Description: "PostgreSQL version", + JSONPath: ".spec.postgresql.version", + }, + apiextv1beta1.CustomResourceColumnDefinition{ + Name: "Pods", + Type: "integer", + Description: "Number of Pods per Postgres cluster", + JSONPath: ".spec.numberOfInstances", + }, + apiextv1beta1.CustomResourceColumnDefinition{ + Name: "Volume", + Type: "string", + Description: "Size of the bound volume", + JSONPath: ".spec.volume.size", + }, + apiextv1beta1.CustomResourceColumnDefinition{ + Name: "CPU-Request", + Type: "string", + Description: "Requested CPU for Postgres containers", + JSONPath: ".spec.resources.requests.cpu", + }, + apiextv1beta1.CustomResourceColumnDefinition{ + Name: "Memory-Request", + Type: "string", + Description: "Requested memory for Postgres containers", + JSONPath: ".spec.resources.requests.memory", + }, + apiextv1beta1.CustomResourceColumnDefinition{ + Name: "Age", + Type: "date", + JSONPath: ".metadata.creationTimestamp", + }, + apiextv1beta1.CustomResourceColumnDefinition{ + Name: "Status", + Type: "string", + Description: "Current sync status of postgresql resource", + JSONPath: ".status.PostgresClusterStatus", + }, +} + +// OperatorConfigCRDResourceColumns definition of AdditionalPrinterColumns for OperatorConfiguration CRD +var OperatorConfigCRDResourceColumns = []apiextv1beta1.CustomResourceColumnDefinition{ + apiextv1beta1.CustomResourceColumnDefinition{ + Name: "Image", + Type: "string", + Description: "Spilo image to be used for Pods", + JSONPath: ".configuration.docker_image", + }, + apiextv1beta1.CustomResourceColumnDefinition{ + Name: "Cluster-Label", + Type: "string", + Description: "Label for K8s resources created by operator", + JSONPath: ".configuration.kubernetes.cluster_name_label", + }, + apiextv1beta1.CustomResourceColumnDefinition{ + Name: "Service-Account", + Type: "string", + Description: "Name of service account to be used", + JSONPath: ".configuration.kubernetes.pod_service_account_name", + }, + apiextv1beta1.CustomResourceColumnDefinition{ + Name: "Min-Instances", + Type: "integer", + Description: "Minimum number of instances per Postgres cluster", + JSONPath: ".configuration.min_instances", + }, + apiextv1beta1.CustomResourceColumnDefinition{ + Name: "Age", + Type: "date", + JSONPath: ".metadata.creationTimestamp", + }, +} + +func buildCRD(name, kind, plural, short string, columns []apiextv1beta1.CustomResourceColumnDefinition) *apiextv1beta1.CustomResourceDefinition { return &apiextv1beta1.CustomResourceDefinition{ ObjectMeta: metav1.ObjectMeta{ Name: name, @@ -36,6 +120,7 @@ func buildCRD(name, kind, plural, short string) *apiextv1beta1.CustomResourceDef Subresources: &apiextv1beta1.CustomResourceSubresources{ Status: &apiextv1beta1.CustomResourceSubresourceStatus{}, }, + AdditionalPrinterColumns: columns, }, } } @@ -45,7 +130,8 @@ func PostgresCRD() *apiextv1beta1.CustomResourceDefinition { return buildCRD(PostgresCRDResouceName, PostgresCRDResourceKind, PostgresCRDResourcePlural, - PostgresCRDResourceShort) + PostgresCRDResourceShort, + PostgresCRDResourceColumns) } // ConfigurationCRD returns CustomResourceDefinition built from OperatorConfigCRDResource @@ -53,5 +139,6 @@ func ConfigurationCRD() *apiextv1beta1.CustomResourceDefinition { return buildCRD(OperatorConfigCRDResourceName, OperatorConfigCRDResouceKind, OperatorConfigCRDResourcePlural, - OperatorConfigCRDResourceShort) + OperatorConfigCRDResourceShort, + OperatorConfigCRDResourceColumns) }