Skip to content

Commit 112a94f

Browse files
committed
non-reconciliable & readiness of static objects
Remove reconcile subcommand for static object APIs Alerts and Providers. Add a hasReconciler() method on all the object adapters to determine if their configuration supports reconciliation. The objects that don't support reconciliation are skilled from reconciliation and readiness checks like HelmRepository of type OCI. Add default ready message for `get` subcommand output for static objects, Alerts, Providers and HelmRepositories of type OCI, as ready message can't be derived for them from their status. Signed-off-by: Sunny <darkowlzz@protonmail.com>
1 parent c75cdc3 commit 112a94f

22 files changed

+81
-97
lines changed

cmd/flux/create_alert.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func createAlertCmdRun(cmd *cobra.Command, args []string) error {
132132

133133
logger.Waitingf("waiting for Alert reconciliation")
134134
if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true,
135-
isObjectReadyConditionFunc(kubeClient, namespacedName, &alert)); err != nil {
135+
isStaticObjectReadyConditionFunc(kubeClient, namespacedName, &alert)); err != nil {
136136
return err
137137
}
138138
logger.Successf("Alert %s is ready", name)

cmd/flux/create_alertprovider.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ func createAlertProviderCmdRun(cmd *cobra.Command, args []string) error {
127127

128128
logger.Waitingf("waiting for Provider reconciliation")
129129
if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true,
130-
isObjectReadyConditionFunc(kubeClient, namespacedName, &provider)); err != nil {
130+
isStaticObjectReadyConditionFunc(kubeClient, namespacedName, &provider)); err != nil {
131131
return err
132132
}
133133

cmd/flux/create_source_helm.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,12 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
230230
}
231231

232232
logger.Waitingf("waiting for HelmRepository source reconciliation")
233-
if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true,
234-
isObjectReadyConditionFunc(kubeClient, namespacedName, helmRepository)); err != nil {
233+
readyConditionFunc := isObjectReadyConditionFunc(kubeClient, namespacedName, helmRepository)
234+
if helmRepository.Spec.Type == sourcev1.HelmRepositoryTypeOCI {
235+
// HelmRepository type OCI is a static object.
236+
readyConditionFunc = isStaticObjectReadyConditionFunc(kubeClient, namespacedName, helmRepository)
237+
}
238+
if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true, readyConditionFunc); err != nil {
235239
return err
236240
}
237241
logger.Successf("HelmRepository source reconciliation completed")

cmd/flux/get_alert.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/spf13/cobra"
2424
"golang.org/x/text/cases"
2525
"golang.org/x/text/language"
26+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2627
"k8s.io/apimachinery/pkg/runtime"
2728

2829
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
@@ -77,7 +78,7 @@ func init() {
7778

7879
func (s alertListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
7980
item := s.Items[i]
80-
status, msg := statusAndMessage(item.Status.Conditions)
81+
status, msg := string(metav1.ConditionTrue), "Alert is Ready"
8182
return append(nameColumns(&item, includeNamespace, includeKind),
8283
cases.Title(language.English).String(strconv.FormatBool(item.Spec.Suspend)), status, msg)
8384
}

cmd/flux/get_alertprovider.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121

2222
"github.com/spf13/cobra"
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2324
"k8s.io/apimachinery/pkg/runtime"
2425

2526
notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2"
@@ -74,7 +75,7 @@ func init() {
7475

7576
func (s alertProviderListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string {
7677
item := s.Items[i]
77-
status, msg := statusAndMessage(item.Status.Conditions)
78+
status, msg := string(metav1.ConditionTrue), "Provider is Ready"
7879
return append(nameColumns(&item, includeNamespace, includeKind), status, msg)
7980
}
8081

cmd/flux/get_source_helm.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"github.com/spf13/cobra"
2424
"golang.org/x/text/cases"
2525
"golang.org/x/text/language"
26+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2627
"k8s.io/apimachinery/pkg/runtime"
2728

2829
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
@@ -82,7 +83,12 @@ func (a *helmRepositoryListAdapter) summariseItem(i int, includeNamespace bool,
8283
if item.GetArtifact() != nil {
8384
revision = item.GetArtifact().Revision
8485
}
85-
status, msg := statusAndMessage(item.Status.Conditions)
86+
var status, msg string
87+
if item.Spec.Type == sourcev1.HelmRepositoryTypeOCI {
88+
status, msg = string(metav1.ConditionTrue), "Helm repository is Ready"
89+
} else {
90+
status, msg = statusAndMessage(item.Status.Conditions)
91+
}
8692
revision = utils.TruncateHex(revision)
8793
msg = utils.TruncateHex(msg)
8894
return append(nameColumns(&item, includeNamespace, includeKind),

cmd/flux/reconcile.go

+6
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type reconcilable interface {
6060
GetAnnotations() map[string]string
6161
SetAnnotations(map[string]string)
6262

63+
hasReconciler() bool // does the object's current configuration has a reconciler to reconcile it?
6364
lastHandledReconcileRequest() string // what was the last handled reconcile request?
6465
successMessage() string // what do you want to tell people when successfully reconciled?
6566
}
@@ -100,6 +101,11 @@ func (reconcile reconcileCommand) run(cmd *cobra.Command, args []string) error {
100101
return err
101102
}
102103

104+
if !reconcile.object.hasReconciler() {
105+
logger.Successf("reconciliation not supported by the object")
106+
return nil
107+
}
108+
103109
if reconcile.object.isSuspended() {
104110
return fmt.Errorf("resource is suspended")
105111
}

cmd/flux/reconcile_alert.go

-44
This file was deleted.

cmd/flux/reconcile_alertprovider.go

-44
This file was deleted.

cmd/flux/reconcile_helmrelease.go

+4
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,7 @@ func (obj helmReleaseAdapter) getSource() (reconcileSource, types.NamespacedName
8181
Namespace: ns,
8282
}
8383
}
84+
85+
func (obj helmReleaseAdapter) hasReconciler() bool {
86+
return true
87+
}

cmd/flux/reconcile_image_repository.go

+4
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,7 @@ func (obj imageRepositoryAdapter) lastHandledReconcileRequest() string {
4848
func (obj imageRepositoryAdapter) successMessage() string {
4949
return fmt.Sprintf("scan fetched %d tags", obj.Status.LastScanResult.TagCount)
5050
}
51+
52+
func (obj imageRepositoryAdapter) hasReconciler() bool {
53+
return true
54+
}

cmd/flux/reconcile_image_updateauto.go

+4
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,7 @@ func (obj imageUpdateAutomationAdapter) successMessage() string {
5656
}
5757
return "automation not yet run"
5858
}
59+
60+
func (obj imageUpdateAutomationAdapter) hasReconciler() bool {
61+
return true
62+
}

cmd/flux/reconcile_kustomization.go

+4
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,7 @@ func (obj kustomizationAdapter) getSource() (reconcileSource, types.NamespacedNa
8888
Namespace: obj.Spec.SourceRef.Namespace,
8989
}
9090
}
91+
92+
func (obj kustomizationAdapter) hasReconciler() bool {
93+
return true
94+
}

cmd/flux/reconcile_receiver.go

+4
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@ func init() {
4242
func (obj receiverAdapter) lastHandledReconcileRequest() string {
4343
return obj.Status.GetLastHandledReconcileRequest()
4444
}
45+
46+
func (obj receiverAdapter) hasReconciler() bool {
47+
return true
48+
}

cmd/flux/reconcile_source_bucket.go

+4
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,7 @@ func (obj bucketAdapter) lastHandledReconcileRequest() string {
4848
func (obj bucketAdapter) successMessage() string {
4949
return fmt.Sprintf("fetched revision %s", obj.Status.Artifact.Revision)
5050
}
51+
52+
func (obj bucketAdapter) hasReconciler() bool {
53+
return true
54+
}

cmd/flux/reconcile_source_chart.go

+4
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,7 @@ func (obj helmChartAdapter) getSource() (reconcileSource, types.NamespacedName)
8484
Namespace: obj.Namespace,
8585
}
8686
}
87+
88+
func (obj helmChartAdapter) hasReconciler() bool {
89+
return true
90+
}

cmd/flux/reconcile_source_git.go

+4
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,7 @@ func (obj gitRepositoryAdapter) lastHandledReconcileRequest() string {
4848
func (obj gitRepositoryAdapter) successMessage() string {
4949
return fmt.Sprintf("fetched revision %s", obj.Status.Artifact.Revision)
5050
}
51+
52+
func (obj gitRepositoryAdapter) hasReconciler() bool {
53+
return true
54+
}

cmd/flux/reconcile_source_helm.go

+4
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@ func (obj helmRepositoryAdapter) successMessage() string {
6060
}
6161
return fmt.Sprintf("fetched revision %s", obj.Status.Artifact.Revision)
6262
}
63+
64+
func (obj helmRepositoryAdapter) hasReconciler() bool {
65+
return obj.Spec.Type != sourcev1.HelmRepositoryTypeOCI
66+
}

cmd/flux/reconcile_source_oci.go

+4
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,7 @@ func (obj ociRepositoryAdapter) lastHandledReconcileRequest() string {
4848
func (obj ociRepositoryAdapter) successMessage() string {
4949
return fmt.Sprintf("fetched revision %s", obj.Status.Artifact.Revision)
5050
}
51+
52+
func (obj ociRepositoryAdapter) hasReconciler() bool {
53+
return true
54+
}

cmd/flux/resume.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type resumable interface {
5656
copyable
5757
statusable
5858
setUnsuspended()
59+
hasReconciler() bool
5960
successMessage() string
6061
}
6162

@@ -212,8 +213,13 @@ func (resume resumeCommand) reconcile(ctx context.Context, res resumable) reconc
212213

213214
logger.Waitingf("waiting for %s reconciliation", resume.kind)
214215

215-
if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true,
216-
isObjectReadyConditionFunc(resume.client, namespacedName, res.asClientObject())); err != nil {
216+
readyConditionFunc := isObjectReadyConditionFunc(resume.client, namespacedName, res.asClientObject())
217+
if !res.hasReconciler() {
218+
// Objects without reconciler are static objects.
219+
readyConditionFunc = isStaticObjectReadyConditionFunc(resume.client, namespacedName, res.asClientObject())
220+
}
221+
222+
if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true, readyConditionFunc); err != nil {
217223
return reconcileResponse{
218224
resumable: res,
219225
err: err,

cmd/flux/resume_alert.go

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ func (obj alertAdapter) successMessage() string {
5555
return "Alert reconciliation completed"
5656
}
5757

58+
func (a alertAdapter) hasReconciler() bool {
59+
return false
60+
}
61+
5862
func (a alertListAdapter) resumeItem(i int) resumable {
5963
return &alertAdapter{&a.AlertList.Items[i]}
6064
}

cmd/flux/resume_alertprovider.go

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ func (obj alertProviderAdapter) successMessage() string {
5555
return "Provider reconciliation completed"
5656
}
5757

58+
func (a alertProviderAdapter) hasReconciler() bool {
59+
return false
60+
}
61+
5862
func (a alertProviderListAdapter) resumeItem(i int) resumable {
5963
return &alertProviderAdapter{&a.ProviderList.Items[i]}
6064
}

0 commit comments

Comments
 (0)