diff --git a/cmd/flux/create_alert.go b/cmd/flux/create_alert.go index 22a5d289..e750d44f 100644 --- a/cmd/flux/create_alert.go +++ b/cmd/flux/create_alert.go @@ -132,7 +132,7 @@ func createAlertCmdRun(cmd *cobra.Command, args []string) error { logger.Waitingf("waiting for Alert reconciliation") if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true, - isObjectReadyConditionFunc(kubeClient, namespacedName, &alert)); err != nil { + isStaticObjectReadyConditionFunc(kubeClient, namespacedName, &alert)); err != nil { return err } logger.Successf("Alert %s is ready", name) diff --git a/cmd/flux/create_alertprovider.go b/cmd/flux/create_alertprovider.go index 468ec5d8..402ff0c4 100644 --- a/cmd/flux/create_alertprovider.go +++ b/cmd/flux/create_alertprovider.go @@ -127,7 +127,7 @@ func createAlertProviderCmdRun(cmd *cobra.Command, args []string) error { logger.Waitingf("waiting for Provider reconciliation") if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true, - isObjectReadyConditionFunc(kubeClient, namespacedName, &provider)); err != nil { + isStaticObjectReadyConditionFunc(kubeClient, namespacedName, &provider)); err != nil { return err } diff --git a/cmd/flux/create_source_helm.go b/cmd/flux/create_source_helm.go index 5b46f45e..522e980f 100644 --- a/cmd/flux/create_source_helm.go +++ b/cmd/flux/create_source_helm.go @@ -230,8 +230,12 @@ func createSourceHelmCmdRun(cmd *cobra.Command, args []string) error { } logger.Waitingf("waiting for HelmRepository source reconciliation") - if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true, - isObjectReadyConditionFunc(kubeClient, namespacedName, helmRepository)); err != nil { + readyConditionFunc := isObjectReadyConditionFunc(kubeClient, namespacedName, helmRepository) + if helmRepository.Spec.Type == sourcev1.HelmRepositoryTypeOCI { + // HelmRepository type OCI is a static object. + readyConditionFunc = isStaticObjectReadyConditionFunc(kubeClient, namespacedName, helmRepository) + } + if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true, readyConditionFunc); err != nil { return err } logger.Successf("HelmRepository source reconciliation completed") diff --git a/cmd/flux/get_alert.go b/cmd/flux/get_alert.go index 9ea6c682..760423c3 100644 --- a/cmd/flux/get_alert.go +++ b/cmd/flux/get_alert.go @@ -23,6 +23,7 @@ import ( "github.com/spf13/cobra" "golang.org/x/text/cases" "golang.org/x/text/language" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2" @@ -77,7 +78,7 @@ func init() { func (s alertListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string { item := s.Items[i] - status, msg := statusAndMessage(item.Status.Conditions) + status, msg := string(metav1.ConditionTrue), "Alert is Ready" return append(nameColumns(&item, includeNamespace, includeKind), cases.Title(language.English).String(strconv.FormatBool(item.Spec.Suspend)), status, msg) } diff --git a/cmd/flux/get_alertprovider.go b/cmd/flux/get_alertprovider.go index 983cbf33..a4c3bca6 100644 --- a/cmd/flux/get_alertprovider.go +++ b/cmd/flux/get_alertprovider.go @@ -20,6 +20,7 @@ import ( "fmt" "github.com/spf13/cobra" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2" @@ -74,7 +75,7 @@ func init() { func (s alertProviderListAdapter) summariseItem(i int, includeNamespace bool, includeKind bool) []string { item := s.Items[i] - status, msg := statusAndMessage(item.Status.Conditions) + status, msg := string(metav1.ConditionTrue), "Provider is Ready" return append(nameColumns(&item, includeNamespace, includeKind), status, msg) } diff --git a/cmd/flux/get_source_helm.go b/cmd/flux/get_source_helm.go index 173a1880..ec131714 100644 --- a/cmd/flux/get_source_helm.go +++ b/cmd/flux/get_source_helm.go @@ -23,6 +23,7 @@ import ( "github.com/spf13/cobra" "golang.org/x/text/cases" "golang.org/x/text/language" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2" @@ -82,7 +83,12 @@ func (a *helmRepositoryListAdapter) summariseItem(i int, includeNamespace bool, if item.GetArtifact() != nil { revision = item.GetArtifact().Revision } - status, msg := statusAndMessage(item.Status.Conditions) + var status, msg string + if item.Spec.Type == sourcev1.HelmRepositoryTypeOCI { + status, msg = string(metav1.ConditionTrue), "Helm repository is Ready" + } else { + status, msg = statusAndMessage(item.Status.Conditions) + } revision = utils.TruncateHex(revision) msg = utils.TruncateHex(msg) return append(nameColumns(&item, includeNamespace, includeKind), diff --git a/cmd/flux/reconcile.go b/cmd/flux/reconcile.go index 7589dcb9..c6c7a472 100644 --- a/cmd/flux/reconcile.go +++ b/cmd/flux/reconcile.go @@ -60,6 +60,7 @@ type reconcilable interface { GetAnnotations() map[string]string SetAnnotations(map[string]string) + isStatic() bool // is it a static object that does not have a reconciler? lastHandledReconcileRequest() string // what was the last handled reconcile request? successMessage() string // what do you want to tell people when successfully reconciled? } @@ -100,6 +101,11 @@ func (reconcile reconcileCommand) run(cmd *cobra.Command, args []string) error { return err } + if reconcile.object.isStatic() { + logger.Successf("reconciliation not supported by the object") + return nil + } + if reconcile.object.isSuspended() { return fmt.Errorf("resource is suspended") } diff --git a/cmd/flux/reconcile_alert.go b/cmd/flux/reconcile_alert.go deleted file mode 100644 index 8dd8be61..00000000 --- a/cmd/flux/reconcile_alert.go +++ /dev/null @@ -1,44 +0,0 @@ -/* -Copyright 2020 The Flux authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package main - -import ( - "github.com/spf13/cobra" - - notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2" -) - -var reconcileAlertCmd = &cobra.Command{ - Use: "alert [name]", - Short: "Reconcile an Alert", - Long: `The reconcile alert command triggers a reconciliation of an Alert resource and waits for it to finish.`, - Example: ` # Trigger a reconciliation for an existing alert - flux reconcile alert main`, - ValidArgsFunction: resourceNamesCompletionFunc(notificationv1.GroupVersion.WithKind(notificationv1.AlertKind)), - RunE: reconcileCommand{ - apiType: alertType, - object: alertAdapter{¬ificationv1.Alert{}}, - }.run, -} - -func init() { - reconcileCmd.AddCommand(reconcileAlertCmd) -} - -func (obj alertAdapter) lastHandledReconcileRequest() string { - return obj.Status.GetLastHandledReconcileRequest() -} diff --git a/cmd/flux/reconcile_alertprovider.go b/cmd/flux/reconcile_alertprovider.go deleted file mode 100644 index 5c3001af..00000000 --- a/cmd/flux/reconcile_alertprovider.go +++ /dev/null @@ -1,44 +0,0 @@ -/* -Copyright 2020 The Flux authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package main - -import ( - "github.com/spf13/cobra" - - notificationv1 "github.com/fluxcd/notification-controller/api/v1beta2" -) - -var reconcileAlertProviderCmd = &cobra.Command{ - Use: "alert-provider [name]", - Short: "Reconcile a Provider", - Long: `The reconcile alert-provider command triggers a reconciliation of a Provider resource and waits for it to finish.`, - Example: ` # Trigger a reconciliation for an existing provider - flux reconcile alert-provider slack`, - ValidArgsFunction: resourceNamesCompletionFunc(notificationv1.GroupVersion.WithKind(notificationv1.ProviderKind)), - RunE: reconcileCommand{ - apiType: alertProviderType, - object: alertProviderAdapter{¬ificationv1.Provider{}}, - }.run, -} - -func init() { - reconcileCmd.AddCommand(reconcileAlertProviderCmd) -} - -func (obj alertProviderAdapter) lastHandledReconcileRequest() string { - return obj.Status.GetLastHandledReconcileRequest() -} diff --git a/cmd/flux/reconcile_helmrelease.go b/cmd/flux/reconcile_helmrelease.go index b015aa8b..b55a1295 100644 --- a/cmd/flux/reconcile_helmrelease.go +++ b/cmd/flux/reconcile_helmrelease.go @@ -81,3 +81,7 @@ func (obj helmReleaseAdapter) getSource() (reconcileSource, types.NamespacedName Namespace: ns, } } + +func (obj helmReleaseAdapter) isStatic() bool { + return false +} diff --git a/cmd/flux/reconcile_image_repository.go b/cmd/flux/reconcile_image_repository.go index c7304eb7..6a386c8b 100644 --- a/cmd/flux/reconcile_image_repository.go +++ b/cmd/flux/reconcile_image_repository.go @@ -48,3 +48,7 @@ func (obj imageRepositoryAdapter) lastHandledReconcileRequest() string { func (obj imageRepositoryAdapter) successMessage() string { return fmt.Sprintf("scan fetched %d tags", obj.Status.LastScanResult.TagCount) } + +func (obj imageRepositoryAdapter) isStatic() bool { + return false +} diff --git a/cmd/flux/reconcile_image_updateauto.go b/cmd/flux/reconcile_image_updateauto.go index 2db4a1c0..95bb42df 100644 --- a/cmd/flux/reconcile_image_updateauto.go +++ b/cmd/flux/reconcile_image_updateauto.go @@ -56,3 +56,7 @@ func (obj imageUpdateAutomationAdapter) successMessage() string { } return "automation not yet run" } + +func (obj imageUpdateAutomationAdapter) isStatic() bool { + return false +} diff --git a/cmd/flux/reconcile_kustomization.go b/cmd/flux/reconcile_kustomization.go index 99d12545..7a18ec02 100644 --- a/cmd/flux/reconcile_kustomization.go +++ b/cmd/flux/reconcile_kustomization.go @@ -88,3 +88,7 @@ func (obj kustomizationAdapter) getSource() (reconcileSource, types.NamespacedNa Namespace: obj.Spec.SourceRef.Namespace, } } + +func (obj kustomizationAdapter) isStatic() bool { + return false +} diff --git a/cmd/flux/reconcile_receiver.go b/cmd/flux/reconcile_receiver.go index 42a2dd24..1691a95d 100644 --- a/cmd/flux/reconcile_receiver.go +++ b/cmd/flux/reconcile_receiver.go @@ -42,3 +42,7 @@ func init() { func (obj receiverAdapter) lastHandledReconcileRequest() string { return obj.Status.GetLastHandledReconcileRequest() } + +func (obj receiverAdapter) isStatic() bool { + return false +} diff --git a/cmd/flux/reconcile_source_bucket.go b/cmd/flux/reconcile_source_bucket.go index 2a2bbdbc..68079a66 100644 --- a/cmd/flux/reconcile_source_bucket.go +++ b/cmd/flux/reconcile_source_bucket.go @@ -48,3 +48,7 @@ func (obj bucketAdapter) lastHandledReconcileRequest() string { func (obj bucketAdapter) successMessage() string { return fmt.Sprintf("fetched revision %s", obj.Status.Artifact.Revision) } + +func (obj bucketAdapter) isStatic() bool { + return false +} diff --git a/cmd/flux/reconcile_source_chart.go b/cmd/flux/reconcile_source_chart.go index 41540617..ead4fa76 100644 --- a/cmd/flux/reconcile_source_chart.go +++ b/cmd/flux/reconcile_source_chart.go @@ -84,3 +84,7 @@ func (obj helmChartAdapter) getSource() (reconcileSource, types.NamespacedName) Namespace: obj.Namespace, } } + +func (obj helmChartAdapter) isStatic() bool { + return false +} diff --git a/cmd/flux/reconcile_source_git.go b/cmd/flux/reconcile_source_git.go index a42cd7b9..28256496 100644 --- a/cmd/flux/reconcile_source_git.go +++ b/cmd/flux/reconcile_source_git.go @@ -48,3 +48,7 @@ func (obj gitRepositoryAdapter) lastHandledReconcileRequest() string { func (obj gitRepositoryAdapter) successMessage() string { return fmt.Sprintf("fetched revision %s", obj.Status.Artifact.Revision) } + +func (obj gitRepositoryAdapter) isStatic() bool { + return false +} diff --git a/cmd/flux/reconcile_source_helm.go b/cmd/flux/reconcile_source_helm.go index f559a5e4..a081fd0e 100644 --- a/cmd/flux/reconcile_source_helm.go +++ b/cmd/flux/reconcile_source_helm.go @@ -60,3 +60,7 @@ func (obj helmRepositoryAdapter) successMessage() string { } return fmt.Sprintf("fetched revision %s", obj.Status.Artifact.Revision) } + +func (obj helmRepositoryAdapter) isStatic() bool { + return obj.Spec.Type == sourcev1.HelmRepositoryTypeOCI +} diff --git a/cmd/flux/reconcile_source_oci.go b/cmd/flux/reconcile_source_oci.go index ffc649f9..52237f2f 100644 --- a/cmd/flux/reconcile_source_oci.go +++ b/cmd/flux/reconcile_source_oci.go @@ -48,3 +48,7 @@ func (obj ociRepositoryAdapter) lastHandledReconcileRequest() string { func (obj ociRepositoryAdapter) successMessage() string { return fmt.Sprintf("fetched revision %s", obj.Status.Artifact.Revision) } + +func (obj ociRepositoryAdapter) isStatic() bool { + return false +} diff --git a/cmd/flux/resume.go b/cmd/flux/resume.go index 4cb700a2..5f3c8b81 100644 --- a/cmd/flux/resume.go +++ b/cmd/flux/resume.go @@ -56,6 +56,7 @@ type resumable interface { copyable statusable setUnsuspended() + isStatic() bool successMessage() string } @@ -212,8 +213,12 @@ func (resume resumeCommand) reconcile(ctx context.Context, res resumable) reconc logger.Waitingf("waiting for %s reconciliation", resume.kind) - if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true, - isObjectReadyConditionFunc(resume.client, namespacedName, res.asClientObject())); err != nil { + readyConditionFunc := isObjectReadyConditionFunc(resume.client, namespacedName, res.asClientObject()) + if res.isStatic() { + readyConditionFunc = isStaticObjectReadyConditionFunc(resume.client, namespacedName, res.asClientObject()) + } + + if err := wait.PollUntilContextTimeout(ctx, rootArgs.pollInterval, rootArgs.timeout, true, readyConditionFunc); err != nil { return reconcileResponse{ resumable: res, err: err, diff --git a/cmd/flux/resume_alert.go b/cmd/flux/resume_alert.go index 713aebb3..0b72b059 100644 --- a/cmd/flux/resume_alert.go +++ b/cmd/flux/resume_alert.go @@ -55,6 +55,10 @@ func (obj alertAdapter) successMessage() string { return "Alert reconciliation completed" } +func (a alertAdapter) isStatic() bool { + return true +} + func (a alertListAdapter) resumeItem(i int) resumable { return &alertAdapter{&a.AlertList.Items[i]} } diff --git a/cmd/flux/resume_alertprovider.go b/cmd/flux/resume_alertprovider.go index e0ba49b9..40427c50 100644 --- a/cmd/flux/resume_alertprovider.go +++ b/cmd/flux/resume_alertprovider.go @@ -55,6 +55,10 @@ func (obj alertProviderAdapter) successMessage() string { return "Provider reconciliation completed" } +func (a alertProviderAdapter) isStatic() bool { + return true +} + func (a alertProviderListAdapter) resumeItem(i int) resumable { return &alertProviderAdapter{&a.ProviderList.Items[i]} }