Skip to content

Commit

Permalink
non-reconciliable & readiness of static objects
Browse files Browse the repository at this point in the history
Signed-off-by: Sunny <darkowlzz@protonmail.com>
  • Loading branch information
darkowlzz committed Oct 4, 2023
1 parent a337a7e commit b324d32
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 140 deletions.
3 changes: 2 additions & 1 deletion cmd/flux/get_alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"strings"

"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 @@ -76,7 +77,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), strings.Title(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 @@ -22,6 +22,7 @@ import (
"strings"

"github.com/spf13/cobra"
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 @@ -81,7 +82,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 @@ -61,6 +61,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 @@ -101,6 +102,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.

93 changes: 0 additions & 93 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 @@ -60,3 +60,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_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
}

0 comments on commit b324d32

Please sign in to comment.