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

Improving Postgres CR Status with Additional Details #2714

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions manifests/minimal-postgres-manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ apiVersion: "acid.zalan.do/v1"
kind: postgresql
metadata:
name: acid-minimal-cluster
labels:
cluster-name: acid-minimal-cluster
spec:
teamId: "acid"
volume:
Expand Down
35 changes: 32 additions & 3 deletions manifests/postgresql.crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ spec:
storage: true
subresources:
status: {}
scale:
specReplicasPath: .spec.numberOfInstances
statusReplicasPath: .status.numberOfInstances
labelSelectorPath: .status.labelSelector
additionalPrinterColumns:
- name: Team
type: string
Expand Down Expand Up @@ -51,7 +55,7 @@ spec:
- name: Status
type: string
description: Current sync status of postgresql resource
jsonPath: .status.PostgresClusterStatus
jsonPath: .status.postgresClusterStatus
schema:
openAPIV3Schema:
type: object
Expand Down Expand Up @@ -677,5 +681,30 @@ spec:
type: integer
status:
type: object
additionalProperties:
type: string
properties:
postgresClusterStatus:
type: string
numberOfInstances:
format: int32
type: integer
labelSelector:
type: string
observedGeneration:
format: int64
type: integer
conditions:
type: array
items:
type: object
properties:
type:
type: string
status:
type: string
lastTransitionTime:
type: string
format: date-time
reason:
type: string
message:
type: string
64 changes: 58 additions & 6 deletions pkg/apis/acid.zalan.do/v1/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ const (
OperatorConfigCRDResourceList = OperatorConfigCRDResouceKind + "List"
OperatorConfigCRDResourceName = OperatorConfigCRDResourcePlural + "." + acidzalando.GroupName
OperatorConfigCRDResourceShort = "opconfig"

specReplicasPath = ".spec.numberOfInstances"
statusReplicasPath = ".status.numberOfInstances"
labelSelectorPath = ".status.labelSelector"
)

// PostgresCRDResourceColumns definition of AdditionalPrinterColumns for postgresql CRD
Expand Down Expand Up @@ -72,7 +76,7 @@ var PostgresCRDResourceColumns = []apiextv1.CustomResourceColumnDefinition{
Name: "Status",
Type: "string",
Description: "Current sync status of postgresql resource",
JSONPath: ".status.PostgresClusterStatus",
JSONPath: ".status.postgresClusterStatus",
},
}

Expand Down Expand Up @@ -1106,10 +1110,47 @@ var PostgresCRDResourceValidation = apiextv1.CustomResourceValidation{
},
"status": {
Type: "object",
AdditionalProperties: &apiextv1.JSONSchemaPropsOrBool{
Schema: &apiextv1.JSONSchemaProps{
Properties: map[string]apiextv1.JSONSchemaProps{
"postgresClusterStatus": {
Type: "string",
},
"numberOfInstances": {
Type: "integer",
Format: "int32",
},
"labelSelector": {
Type: "string",
},
"observedGeneration": {
Type: "integer",
Format: "int64",
},
"conditions": {
Type: "array",
Items: &apiextv1.JSONSchemaPropsOrArray{
Schema: &apiextv1.JSONSchemaProps{
Type: "object",
Properties: map[string]apiextv1.JSONSchemaProps{
"type": {
Type: "string",
},
"status": {
Type: "string",
},
"lastTransitionTime": {
Type: "string",
Format: "date-time",
},
"reason": {
Type: "string",
},
"message": {
Type: "string",
},
},
},
},
},
},
},
},
Expand Down Expand Up @@ -1983,7 +2024,7 @@ var OperatorConfigCRDResourceValidation = apiextv1.CustomResourceValidation{
func buildCRD(name, kind, plural, list, short string,
categories []string,
columns []apiextv1.CustomResourceColumnDefinition,
validation apiextv1.CustomResourceValidation) *apiextv1.CustomResourceDefinition {
validation apiextv1.CustomResourceValidation, specReplicasPath string, statusReplicasPath string, labelSelectorPath string) *apiextv1.CustomResourceDefinition {
return &apiextv1.CustomResourceDefinition{
TypeMeta: metav1.TypeMeta{
APIVersion: fmt.Sprintf("%s/%s", apiextv1.GroupName, apiextv1.SchemeGroupVersion.Version),
Expand All @@ -2010,6 +2051,11 @@ func buildCRD(name, kind, plural, list, short string,
Storage: true,
Subresources: &apiextv1.CustomResourceSubresources{
Status: &apiextv1.CustomResourceSubresourceStatus{},
Scale: &apiextv1.CustomResourceSubresourceScale{
SpecReplicasPath: specReplicasPath,
StatusReplicasPath: statusReplicasPath,
LabelSelectorPath: &labelSelectorPath,
},
},
AdditionalPrinterColumns: columns,
Schema: &validation,
Expand All @@ -2028,7 +2074,10 @@ func PostgresCRD(crdCategories []string) *apiextv1.CustomResourceDefinition {
PostgresCRDResourceShort,
crdCategories,
PostgresCRDResourceColumns,
PostgresCRDResourceValidation)
PostgresCRDResourceValidation,
specReplicasPath,
statusReplicasPath,
labelSelectorPath)
}

// ConfigurationCRD returns CustomResourceDefinition built from OperatorConfigCRDResource
Expand All @@ -2040,5 +2089,8 @@ func ConfigurationCRD(crdCategories []string) *apiextv1.CustomResourceDefinition
OperatorConfigCRDResourceShort,
crdCategories,
OperatorConfigCRDResourceColumns,
OperatorConfigCRDResourceValidation)
OperatorConfigCRDResourceValidation,
specReplicasPath,
statusReplicasPath,
labelSelectorPath)
}
42 changes: 41 additions & 1 deletion pkg/apis/acid.zalan.do/v1/postgresql_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v1
// Postgres CRD definition, please use CamelCase for field names.

import (
"k8s.io/apimachinery/pkg/api/equality"
"time"

v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -225,9 +226,48 @@ type Sidecar struct {
// UserFlags defines flags (such as superuser, nologin) that could be assigned to individual users
type UserFlags []string

type Conditions []Condition

type PostgresqlConditionType string
type VolatileTime struct {
Inner metav1.Time `json:",inline"`
}

// MarshalJSON implements the json.Marshaler interface.
func (t VolatileTime) MarshalJSON() ([]byte, error) {
return t.Inner.MarshalJSON()
}

// UnmarshalJSON implements the json.Unmarshaller interface.
func (t *VolatileTime) UnmarshalJSON(b []byte) error {
return t.Inner.UnmarshalJSON(b)
}

func init() {
equality.Semantic.AddFunc(
// Always treat VolatileTime fields as equivalent.
func(VolatileTime, VolatileTime) bool {
return true
},
)
}

// Condition contains the conditions of the PostgreSQL cluster
type Condition struct {
RavinaChidambaram marked this conversation as resolved.
Show resolved Hide resolved
Type PostgresqlConditionType `json:"type" description:"type of status condition"`
Status v1.ConditionStatus `json:"status" description:"status of the condition, one of True, False, Unknown"`
LastTransitionTime VolatileTime `json:"lastTransitionTime,omitempty" description:"last time the condition transit from one status to another"`
Reason string `json:"reason,omitempty" description:"one-word CamelCase reason for the condition's last transition"`
Message string `json:"message,omitempty" description:"human-readable message indicating details about last transition"`
}

// PostgresStatus contains status of the PostgreSQL cluster (running, creation failed etc.)
type PostgresStatus struct {
PostgresClusterStatus string `json:"PostgresClusterStatus"`
PostgresClusterStatus string `json:"postgresClusterStatus"`
NumberOfInstances int32 `json:"numberOfInstances"`
LabelSelector string `json:"labelSelector"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
Conditions Conditions `json:"conditions,omitempty"`
}

// ConnectionPooler Options for connection pooler
Expand Down
4 changes: 0 additions & 4 deletions pkg/apis/acid.zalan.do/v1/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,3 @@ func (postgresStatus PostgresStatus) Running() bool {
func (postgresStatus PostgresStatus) Creating() bool {
return postgresStatus.PostgresClusterStatus == ClusterStatusCreating
}

func (postgresStatus PostgresStatus) String() string {
return postgresStatus.PostgresClusterStatus
}
65 changes: 64 additions & 1 deletion pkg/apis/acid.zalan.do/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading