additional printer columns for CRDs (#653)
* additional printer columns for CRDs
This commit is contained in:
		
							parent
							
								
									7715e58da0
								
							
						
					
					
						commit
						abdb003f40
					
				| 
						 | 
				
			
			@ -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: {}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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)
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue