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

✨ Add support for the ObservedGeneration in HelmChartProxy Status field #145

Merged
merged 1 commit into from
Feb 5, 2024
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 api/v1alpha1/condition_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ const (
// meaning that the HelmReleaseProxies are created/updated, value template parsing succeeded, and the orphaned HelmReleaseProxies are deleted.
HelmReleaseProxySpecsUpToDateCondition clusterv1.ConditionType = "HelmReleaseProxySpecsUpToDate"

// HelmReleaseProxySpecsUpdatingReason indicates that the HelmReleaseProxy entity is not yet updated by the corresponding controller.
HelmReleaseProxySpecsUpdatingReason = "HelmReleaseProxySpecsUpdating"

// HelmReleaseProxyCreationFailedReason indicates that the HelmChartProxy controller failed to create a HelmReleaseProxy.
HelmReleaseProxyCreationFailedReason = "HelmReleaseProxyCreationFailed"

Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha1/helmchartproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ type HelmChartProxyStatus struct {
// MatchingClusters is the list of references to Clusters selected by the ClusterSelector.
// +optional
MatchingClusters []corev1.ObjectReference `json:"matchingClusters"`

// ObservedGeneration is the latest generation observed by the controller.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

// +kubebuilder:object:root=true
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha1/helmreleaseproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ type HelmReleaseProxyStatus struct {
// Revision is the current revision of the Helm release.
// +optional
Revision int `json:"revision,omitempty"`

// ObservedGeneration is the latest generation observed by the controller.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
Jont828 marked this conversation as resolved.
Show resolved Hide resolved
}

// +kubebuilder:object:root=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,11 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: array
observedGeneration:
description: ObservedGeneration is the latest generation observed
by the controller.
format: int64
type: integer
type: object
type: object
served: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ spec:
- type
type: object
type: array
observedGeneration:
description: ObservedGeneration is the latest generation observed
by the controller.
format: int64
type: integer
revision:
description: Revision is the current revision of the Helm release.
type: integer
Expand Down
10 changes: 8 additions & 2 deletions controllers/helmchartproxy/helmchartproxy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package helmchartproxy

import (
"context"
"fmt"

"github.com/pkg/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -297,7 +298,12 @@ func (r *HelmChartProxyReconciler) aggregateHelmReleaseProxyReadyCondition(ctx c

getters := make([]conditions.Getter, 0, len(releaseList.Items))
for i := range releaseList.Items {
getters = append(getters, &releaseList.Items[i])
helmReleaseProxy := &releaseList.Items[i]
if helmReleaseProxy.Generation != helmReleaseProxy.Status.ObservedGeneration {
conditions.MarkFalse(helmChartProxy, addonsv1alpha1.HelmReleaseProxySpecsUpToDateCondition, addonsv1alpha1.HelmReleaseProxySpecsUpdatingReason, clusterv1.ConditionSeverityInfo, fmt.Sprintf("Helm release proxy '%s' is not updated yet", helmReleaseProxy.Name))
return nil
}
getters = append(getters, helmReleaseProxy)
}

conditions.SetAggregate(helmChartProxy, addonsv1alpha1.HelmReleaseProxiesReadyCondition, getters, conditions.AddSourceRef(), conditions.WithStepCounterIf(false))
Expand All @@ -306,7 +312,7 @@ func (r *HelmChartProxyReconciler) aggregateHelmReleaseProxyReadyCondition(ctx c
}

// patchHelmChartProxy patches the HelmChartProxy object and sets the ReadyCondition as an aggregate of the other condition set.
// TODO: Is this preferrable to client.Update() calls? Based on testing it seems like it avoids race conditions.
// TODO: Is this preferable to client.Update() calls? Based on testing it seems like it avoids race conditions.
func patchHelmChartProxy(ctx context.Context, patchHelper *patch.Helper, helmChartProxy *addonsv1alpha1.HelmChartProxy) error {
conditions.SetSummary(helmChartProxy,
conditions.WithConditions(
Expand Down
2 changes: 2 additions & 0 deletions controllers/helmchartproxy/helmchartproxy_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ func TestReconcileNormal(t *testing.T) {
g.Expect(conditions.IsTrue(hcp, addonsv1alpha1.HelmReleaseProxiesReadyCondition)).To(BeTrue())
g.Expect(conditions.Has(hcp, clusterv1.ReadyCondition)).To(BeTrue())
g.Expect(conditions.IsTrue(hcp, clusterv1.ReadyCondition)).To(BeTrue())
g.Expect(hcp.Status.ObservedGeneration).To(Equal(hcp.Generation))
},
expectedError: "",
},
Expand All @@ -304,6 +305,7 @@ func TestReconcileNormal(t *testing.T) {
g.Expect(conditions.IsTrue(hcp, addonsv1alpha1.HelmReleaseProxiesReadyCondition)).To(BeTrue())
g.Expect(conditions.Has(hcp, clusterv1.ReadyCondition)).To(BeTrue())
g.Expect(conditions.IsTrue(hcp, clusterv1.ReadyCondition)).To(BeTrue())
g.Expect(hcp.Status.ObservedGeneration).To(Equal(hcp.Generation))
},
expectedError: "",
},
Expand Down