-
Notifications
You must be signed in to change notification settings - Fork 974
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
base: master
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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" | ||||||
|
@@ -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 ConditionType string | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
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 { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this be changed to PostgresqlCondition? This aligns with other K8s resources. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, changed to |
||||||
Type ConditionType `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"` | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why use an extra type and not just metav1.Time? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mostly to avoid semantic check inequality with |
||||||
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 | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,16 +255,20 @@ func (c *Cluster) Create() (err error) { | |
ss *appsv1.StatefulSet | ||
) | ||
|
||
//Even though its possible to propogate other CR labels to the pods, picking the default label here since its propogated to all the pods by default. But this means that in order for the scale subresource to work properly, user must set the "cluster-name" key in their CRs with value matching the CR name. | ||
labelstring := fmt.Sprintf("%s=%s", "cluster-name", c.Postgresql.ObjectMeta.Labels["cluster-name"]) //TODO: make this configurable. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Labels we propagate to all child resources are configurable with ClusterLabels and ClusterNameLabel. We should use the latter, I think and not hard code it here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have changed it, using |
||
|
||
defer func() { | ||
var ( | ||
pgUpdatedStatus *acidv1.Postgresql | ||
errStatus error | ||
) | ||
existingConditions := c.Postgresql.Status.Conditions | ||
if err == nil { | ||
pgUpdatedStatus, errStatus = c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusRunning) //TODO: are you sure it's running? | ||
pgUpdatedStatus, errStatus = c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusRunning, c.Postgresql.Spec.NumberOfInstances, labelstring, c.Postgresql.Generation, existingConditions, "") //TODO: are you sure it's running? | ||
} else { | ||
c.logger.Warningf("cluster created failed: %v", err) | ||
pgUpdatedStatus, errStatus = c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusAddFailed) | ||
pgUpdatedStatus, errStatus = c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusAddFailed, 0, labelstring, 0, existingConditions, err.Error()) | ||
} | ||
if errStatus != nil { | ||
c.logger.Warningf("could not set cluster status: %v", errStatus) | ||
|
@@ -274,7 +278,8 @@ func (c *Cluster) Create() (err error) { | |
} | ||
}() | ||
|
||
pgCreateStatus, err = c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusCreating) | ||
existingConditions := c.Postgresql.Status.Conditions | ||
pgCreateStatus, err = c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusCreating, 0, labelstring, 0, existingConditions, "") | ||
if err != nil { | ||
return fmt.Errorf("could not set cluster status: %v", err) | ||
} | ||
|
@@ -927,7 +932,9 @@ func (c *Cluster) Update(oldSpec, newSpec *acidv1.Postgresql) error { | |
c.mu.Lock() | ||
defer c.mu.Unlock() | ||
|
||
c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusUpdating) | ||
labelstring := fmt.Sprintf("%s=%s", "cluster-name", c.Postgresql.ObjectMeta.Labels["cluster-name"]) | ||
existingConditions := c.Postgresql.Status.Conditions | ||
c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusUpdating, c.Postgresql.Status.NumberOfInstances, labelstring, c.Postgresql.Status.ObservedGeneration, existingConditions, "") | ||
c.setSpec(newSpec) | ||
|
||
defer func() { | ||
|
@@ -936,9 +943,9 @@ func (c *Cluster) Update(oldSpec, newSpec *acidv1.Postgresql) error { | |
err error | ||
) | ||
if updateFailed { | ||
pgUpdatedStatus, err = c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusUpdateFailed) | ||
pgUpdatedStatus, err = c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusUpdateFailed, c.Postgresql.Status.NumberOfInstances, labelstring, c.Postgresql.Status.ObservedGeneration, existingConditions, err.Error()) | ||
} else { | ||
pgUpdatedStatus, err = c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusRunning) | ||
pgUpdatedStatus, err = c.KubeClient.SetPostgresCRDStatus(c.clusterName(), acidv1.ClusterStatusRunning, newSpec.Spec.NumberOfInstances, labelstring, c.Postgresql.Generation, existingConditions, "") | ||
} | ||
if err != nil { | ||
c.logger.Warningf("could not set cluster status: %v", err) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these not
const
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to
const