Skip to content

Commit

Permalink
non-reconciliable & readiness of static objects
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
darkowlzz committed Oct 17, 2023
1 parent c75cdc3 commit 112a94f
Show file tree
Hide file tree
Showing 22 changed files with 81 additions and 97 deletions.
2 changes: 1 addition & 1 deletion cmd/flux/create_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/flux/create_alertprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 6 additions & 2 deletions cmd/flux/create_source_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion cmd/flux/get_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/flux/get_alertprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand Down
8 changes: 7 additions & 1 deletion cmd/flux/get_source_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
Expand Down
6 changes: 6 additions & 0 deletions cmd/flux/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type reconcilable interface {
GetAnnotations() map[string]string
SetAnnotations(map[string]string)

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

if !reconcile.object.hasReconciler() {
logger.Successf("reconciliation not supported by the object")
return nil
}

if reconcile.object.isSuspended() {
return fmt.Errorf("resource is suspended")
}
Expand Down
44 changes: 0 additions & 44 deletions cmd/flux/reconcile_alert.go

This file was deleted.

44 changes: 0 additions & 44 deletions cmd/flux/reconcile_alertprovider.go

This file was deleted.

4 changes: 4 additions & 0 deletions cmd/flux/reconcile_helmrelease.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,7 @@ func (obj helmReleaseAdapter) getSource() (reconcileSource, types.NamespacedName
Namespace: ns,
}
}

func (obj helmReleaseAdapter) hasReconciler() bool {
return true
}
4 changes: 4 additions & 0 deletions cmd/flux/reconcile_image_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) hasReconciler() bool {
return true
}
4 changes: 4 additions & 0 deletions cmd/flux/reconcile_image_updateauto.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ func (obj imageUpdateAutomationAdapter) successMessage() string {
}
return "automation not yet run"
}

func (obj imageUpdateAutomationAdapter) hasReconciler() bool {
return true
}
4 changes: 4 additions & 0 deletions cmd/flux/reconcile_kustomization.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,7 @@ func (obj kustomizationAdapter) getSource() (reconcileSource, types.NamespacedNa
Namespace: obj.Spec.SourceRef.Namespace,
}
}

func (obj kustomizationAdapter) hasReconciler() bool {
return true
}
4 changes: 4 additions & 0 deletions cmd/flux/reconcile_receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ func init() {
func (obj receiverAdapter) lastHandledReconcileRequest() string {
return obj.Status.GetLastHandledReconcileRequest()
}

func (obj receiverAdapter) hasReconciler() bool {
return true
}
4 changes: 4 additions & 0 deletions cmd/flux/reconcile_source_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) hasReconciler() bool {
return true
}
4 changes: 4 additions & 0 deletions cmd/flux/reconcile_source_chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ func (obj helmChartAdapter) getSource() (reconcileSource, types.NamespacedName)
Namespace: obj.Namespace,
}
}

func (obj helmChartAdapter) hasReconciler() bool {
return true
}
4 changes: 4 additions & 0 deletions cmd/flux/reconcile_source_git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) hasReconciler() bool {
return true
}
4 changes: 4 additions & 0 deletions cmd/flux/reconcile_source_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,7 @@ func (obj helmRepositoryAdapter) successMessage() string {
}
return fmt.Sprintf("fetched revision %s", obj.Status.Artifact.Revision)
}

func (obj helmRepositoryAdapter) hasReconciler() bool {
return obj.Spec.Type != sourcev1.HelmRepositoryTypeOCI
}
4 changes: 4 additions & 0 deletions cmd/flux/reconcile_source_oci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) hasReconciler() bool {
return true
}
10 changes: 8 additions & 2 deletions cmd/flux/resume.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type resumable interface {
copyable
statusable
setUnsuspended()
hasReconciler() bool
successMessage() string
}

Expand Down Expand Up @@ -212,8 +213,13 @@ 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.hasReconciler() {
// Objects without reconciler are static objects.
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,
Expand Down
4 changes: 4 additions & 0 deletions cmd/flux/resume_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func (obj alertAdapter) successMessage() string {
return "Alert reconciliation completed"
}

func (a alertAdapter) hasReconciler() bool {
return false
}

func (a alertListAdapter) resumeItem(i int) resumable {
return &alertAdapter{&a.AlertList.Items[i]}
}
4 changes: 4 additions & 0 deletions cmd/flux/resume_alertprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ func (obj alertProviderAdapter) successMessage() string {
return "Provider reconciliation completed"
}

func (a alertProviderAdapter) hasReconciler() bool {
return false
}

func (a alertProviderListAdapter) resumeItem(i int) resumable {
return &alertProviderAdapter{&a.ProviderList.Items[i]}
}

0 comments on commit 112a94f

Please sign in to comment.