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

ObservedGeneration and condition save updates #751

Merged
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
3 changes: 3 additions & 0 deletions apis/bases/client.openstack.org_openstackclients.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ spec:
- type
type: object
type: array
observedGeneration:
format: int64
type: integer
podName:
type: string
type: object
Expand Down
3 changes: 3 additions & 0 deletions apis/bases/core.openstack.org_openstackcontrolplanes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17400,6 +17400,9 @@ spec:
type: string
deployedVersion:
type: string
observedGeneration:
format: int64
type: integer
tls:
properties:
caBundleSecretName:
Expand Down
3 changes: 3 additions & 0 deletions apis/bases/core.openstack.org_openstackversions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,9 @@ spec:
type: object
deployedVersion:
type: string
observedGeneration:
format: int64
type: integer
type: object
type: object
served: true
Expand Down
3 changes: 3 additions & 0 deletions apis/client/v1beta1/openstackclient_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ type OpenStackClientStatus struct {

// Conditions
Conditions condition.Conditions `json:"conditions,omitempty" optional:"true"`

//ObservedGeneration - the most recent generation observed for this object.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
3 changes: 3 additions & 0 deletions apis/core/v1beta1/openstackcontrolplane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,9 @@ type OpenStackControlPlaneStatus struct {

// ContainerImages
ContainerImages ContainerImages `json:"containerImages,omitempty"`

//ObservedGeneration - the most recent generation observed for this object.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

// TLSStatus defines the observed state of TLS
Expand Down
3 changes: 3 additions & 0 deletions apis/core/v1beta1/openstackversion_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ type OpenStackVersionStatus struct {

// where we keep track of the container images for previous versions
ContainerImageVersionDefaults map[string]*ContainerDefaults `json:"containerImageVersionDefaults,omitempty"`

//ObservedGeneration - the most recent generation observed for this object.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/client.openstack.org_openstackclients.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ spec:
- type
type: object
type: array
observedGeneration:
format: int64
type: integer
podName:
type: string
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17400,6 +17400,9 @@ spec:
type: string
deployedVersion:
type: string
observedGeneration:
format: int64
type: integer
tls:
properties:
caBundleSecretName:
Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/core.openstack.org_openstackversions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,9 @@ spec:
type: object
deployedVersion:
type: string
observedGeneration:
format: int64
type: integer
type: object
type: object
served: true
Expand Down
33 changes: 23 additions & 10 deletions controllers/client/openstackclient_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,6 @@ func (r *OpenStackClientReconciler) Reconcile(ctx context.Context, req ctrl.Requ
}
Log.Info("OpenStackClient CR values", "Name", instance.Name, "Namespace", instance.Namespace, "Secret", instance.Spec.OpenStackConfigSecret, "Image", instance.Spec.ContainerImage)

instance.Status.Conditions = condition.Conditions{}
cl := condition.CreateList(
condition.UnknownCondition(clientv1.OpenStackClientReadyCondition, condition.InitReason, clientv1.OpenStackClientReadyInitMessage),
// service account, role, rolebinding conditions
condition.UnknownCondition(condition.ServiceAccountReadyCondition, condition.InitReason, condition.ServiceAccountReadyInitMessage),
condition.UnknownCondition(condition.RoleReadyCondition, condition.InitReason, condition.RoleReadyInitMessage),
condition.UnknownCondition(condition.RoleBindingReadyCondition, condition.InitReason, condition.RoleBindingReadyInitMessage),
)
instance.Status.Conditions.Init(&cl)

helper, err := helper.NewHelper(
instance,
r.Client,
Expand All @@ -120,8 +110,21 @@ func (r *OpenStackClientReconciler) Reconcile(ctx context.Context, req ctrl.Requ
return ctrl.Result{}, err
}

//
// initialize status
//
isNewInstance := instance.Status.Conditions == nil
if isNewInstance {
instance.Status.Conditions = condition.Conditions{}
}

// Save a copy of the condtions so that we can restore the LastTransitionTime
// when a condition's state doesn't change.
savedConditions := instance.Status.Conditions.DeepCopy()

// Always patch the instance status when exiting this function so we can persist any changes.
defer func() {
condition.RestoreLastTransitionTimes(&instance.Status.Conditions, savedConditions)
// update the Ready condition based on the sub conditions
if instance.Status.Conditions.AllSubConditionIsTrue() {
instance.Status.Conditions.MarkTrue(
Expand All @@ -141,6 +144,16 @@ func (r *OpenStackClientReconciler) Reconcile(ctx context.Context, req ctrl.Requ
}
}()

cl := condition.CreateList(
condition.UnknownCondition(clientv1.OpenStackClientReadyCondition, condition.InitReason, clientv1.OpenStackClientReadyInitMessage),
// service account, role, rolebinding conditions
condition.UnknownCondition(condition.ServiceAccountReadyCondition, condition.InitReason, condition.ServiceAccountReadyInitMessage),
condition.UnknownCondition(condition.RoleReadyCondition, condition.InitReason, condition.RoleReadyInitMessage),
condition.UnknownCondition(condition.RoleBindingReadyCondition, condition.InitReason, condition.RoleBindingReadyInitMessage),
)
instance.Status.Conditions.Init(&cl)
instance.Status.ObservedGeneration = instance.Generation

// Service account, role, binding
rbacRules := []rbacv1.PolicyRule{
{
Expand Down
12 changes: 12 additions & 0 deletions controllers/core/openstackcontrolplane_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,20 @@ func (r *OpenStackControlPlaneReconciler) Reconcile(ctx context.Context, req ctr
Log.Error(err, "unable to acquire helper for OpenStackControlPlane")
return ctrl.Result{}, err
}
//
// initialize Conditions
//
if instance.Status.Conditions == nil {
instance.Status.Conditions = condition.Conditions{}
}

// Save a copy of the condtions so that we can restore the LastTransitionTime
// when a condition's state doesn't change.
savedConditions := instance.Status.Conditions.DeepCopy()

// Always patch the instance status when exiting this function so we can persist any changes.
defer func() {
condition.RestoreLastTransitionTimes(&instance.Status.Conditions, savedConditions)
// update the Ready condition based on the sub conditions
if instance.Status.Conditions.AllSubConditionIsTrue() {
instance.Status.Conditions.MarkTrue(
Expand All @@ -173,6 +184,7 @@ func (r *OpenStackControlPlaneReconciler) Reconcile(ctx context.Context, req ctr
}()

instance.InitConditions()
instance.Status.ObservedGeneration = instance.Generation

Log.Info("Looking up the current OpenStackVersion")
ctrlResult, version, err := openstack.ReconcileVersion(ctx, instance, helper)
Expand Down
2 changes: 2 additions & 0 deletions controllers/core/openstackversion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ func (r *OpenStackVersionReconciler) Reconcile(ctx context.Context, req ctrl.Req
//condition.UnknownCondition(corev1beta1.OpenStackVersionMinorUpdateDataplane, condition.InitReason, string(corev1beta1.OpenStackVersionMinorUpdateInitMessage)))
}
instance.Status.Conditions.Init(&cl)
instance.Status.ObservedGeneration = instance.Generation

if isNewInstance {
// Register overall status immediately to have an early feedback e.g. in the cli
return ctrl.Result{}, nil
Expand Down
Loading