diff --git a/cmd/gotk/create_helmrelease.go b/cmd/gotk/create_helmrelease.go index 81d6a834..64c343f4 100644 --- a/cmd/gotk/create_helmrelease.go +++ b/cmd/gotk/create_helmrelease.go @@ -275,13 +275,12 @@ func isHelmChartReady(ctx context.Context, kubeClient client.Client, name, names return false, err } - for _, condition := range helmChart.Status.Conditions { - if condition.Type == meta.ReadyCondition { - if condition.Status == corev1.ConditionTrue { - return true, nil - } else if condition.Status == corev1.ConditionFalse { - return false, fmt.Errorf(condition.Message) - } + if c := meta.GetCondition(helmChart.Status.Conditions, meta.ReadyCondition); c != nil { + switch c.Status { + case corev1.ConditionTrue: + return true, nil + case corev1.ConditionFalse: + return false, fmt.Errorf(c.Message) } } return false, nil diff --git a/cmd/gotk/create_kustomization.go b/cmd/gotk/create_kustomization.go index da575c54..d3b6e390 100644 --- a/cmd/gotk/create_kustomization.go +++ b/cmd/gotk/create_kustomization.go @@ -306,13 +306,12 @@ func isKustomizationReady(ctx context.Context, kubeClient client.Client, name, n return false, err } - for _, condition := range kustomization.Status.Conditions { - if condition.Type == meta.ReadyCondition { - if condition.Status == corev1.ConditionTrue { - return true, nil - } else if condition.Status == corev1.ConditionFalse { - return false, fmt.Errorf(condition.Message) - } + if c := meta.GetCondition(kustomization.Status.Conditions, meta.ReadyCondition); c != nil { + switch c.Status { + case corev1.ConditionTrue: + return true, nil + case corev1.ConditionFalse: + return false, fmt.Errorf(c.Message) } } return false, nil diff --git a/cmd/gotk/create_source_git.go b/cmd/gotk/create_source_git.go index 5597393d..86831ec9 100644 --- a/cmd/gotk/create_source_git.go +++ b/cmd/gotk/create_source_git.go @@ -373,13 +373,12 @@ func isGitRepositoryReady(ctx context.Context, kubeClient client.Client, name, n return false, err } - for _, condition := range gitRepository.Status.Conditions { - if condition.Type == meta.ReadyCondition { - if condition.Status == corev1.ConditionTrue { - return true, nil - } else if condition.Status == corev1.ConditionFalse { - return false, fmt.Errorf(condition.Message) - } + if c := meta.GetCondition(gitRepository.Status.Conditions, meta.ReadyCondition); c != nil { + switch c.Status { + case corev1.ConditionTrue: + return true, nil + case corev1.ConditionFalse: + return false, fmt.Errorf(c.Message) } } return false, nil diff --git a/cmd/gotk/get_helmrelease.go b/cmd/gotk/get_helmrelease.go index 4d2a89ae..29ef63aa 100644 --- a/cmd/gotk/get_helmrelease.go +++ b/cmd/gotk/get_helmrelease.go @@ -68,20 +68,17 @@ func getHelmReleaseCmdRun(cmd *cobra.Command, args []string) error { continue } isInitialized := false - for _, condition := range helmRelease.Status.Conditions { - if condition.Type == meta.ReadyCondition { - if condition.Status != corev1.ConditionFalse { - if helmRelease.Status.LastAppliedRevision != "" { - logger.Successf("%s last applied revision %s", helmRelease.GetName(), helmRelease.Status.LastAppliedRevision) - } else { - logger.Successf("%s reconciling", helmRelease.GetName()) - } - } else { - logger.Failuref("%s %s", helmRelease.GetName(), condition.Message) - } - isInitialized = true - break + if c := meta.GetCondition(helmRelease.Status.Conditions, meta.ReadyCondition); c != nil { + switch c.Status { + case corev1.ConditionTrue: + logger.Successf("%s last applied revision %s", helmRelease.GetName(), helmRelease.Status.LastAppliedRevision) + case corev1.ConditionUnknown: + logger.Successf("%s reconciling", helmRelease.GetName()) + default: + logger.Failuref("%s %s", helmRelease.GetName(), c.Message) } + isInitialized = true + break } if !isInitialized { logger.Failuref("%s is not ready", helmRelease.GetName()) diff --git a/cmd/gotk/get_kustomization.go b/cmd/gotk/get_kustomization.go index 9bc225fc..32e973b6 100644 --- a/cmd/gotk/get_kustomization.go +++ b/cmd/gotk/get_kustomization.go @@ -67,20 +67,17 @@ func getKsCmdRun(cmd *cobra.Command, args []string) error { continue } isInitialized := false - for _, condition := range kustomization.Status.Conditions { - if condition.Type == meta.ReadyCondition { - if condition.Status != corev1.ConditionFalse { - if kustomization.Status.LastAppliedRevision != "" { - logger.Successf("%s last applied revision %s", kustomization.GetName(), kustomization.Status.LastAppliedRevision) - } else { - logger.Successf("%s reconciling", kustomization.GetName()) - } - } else { - logger.Failuref("%s %s", kustomization.GetName(), condition.Message) - } - isInitialized = true - break + if c := meta.GetCondition(kustomization.Status.Conditions, meta.ReadyCondition); c != nil { + switch c.Status { + case corev1.ConditionTrue: + logger.Successf("%s last applied revision %s", kustomization.GetName(), kustomization.Status.LastAppliedRevision) + case corev1.ConditionUnknown: + logger.Successf("%s reconciling", kustomization.GetName()) + default: + logger.Failuref("%s %s", kustomization.GetName(), c.Message) } + isInitialized = true + break } if !isInitialized { logger.Failuref("%s is not ready", kustomization.GetName()) diff --git a/cmd/gotk/get_source_bucket.go b/cmd/gotk/get_source_bucket.go index e6324dd5..c0eb7a4c 100644 --- a/cmd/gotk/get_source_bucket.go +++ b/cmd/gotk/get_source_bucket.go @@ -60,18 +60,22 @@ func getSourceBucketCmdRun(cmd *cobra.Command, args []string) error { return nil } + // TODO(hidde): this should print a table, and should produce better output + // for items that have an artifact attached while they are in a reconciling + // 'Unknown' state. for _, source := range list.Items { isInitialized := false - for _, condition := range source.Status.Conditions { - if condition.Type == meta.ReadyCondition { - if condition.Status != corev1.ConditionFalse { - logger.Successf("%s last fetched revision: %s", source.GetName(), source.Status.Artifact.Revision) - } else { - logger.Failuref("%s %s", source.GetName(), condition.Message) - } - isInitialized = true - break + if c := meta.GetCondition(source.Status.Conditions, meta.ReadyCondition); c != nil { + switch c.Status { + case corev1.ConditionTrue: + logger.Successf("%s last fetched revision: %s", source.GetName(), source.GetArtifact().Revision) + case corev1.ConditionUnknown: + logger.Successf("%s reconciling", source.GetName()) + default: + logger.Failuref("%s %s", source.GetName(), c.Message) } + isInitialized = true + break } if !isInitialized { logger.Failuref("%s is not ready", source.GetName()) diff --git a/cmd/gotk/get_source_git.go b/cmd/gotk/get_source_git.go index 25a93afc..5004bb2d 100644 --- a/cmd/gotk/get_source_git.go +++ b/cmd/gotk/get_source_git.go @@ -60,18 +60,22 @@ func getSourceGitCmdRun(cmd *cobra.Command, args []string) error { return nil } + // TODO(hidde): this should print a table, and should produce better output + // for items that have an artifact attached while they are in a reconciling + // 'Unknown' state. for _, source := range list.Items { isInitialized := false - for _, condition := range source.Status.Conditions { - if condition.Type == meta.ReadyCondition { - if condition.Status != corev1.ConditionFalse { - logger.Successf("%s last fetched revision: %s", source.GetName(), source.Status.Artifact.Revision) - } else { - logger.Failuref("%s %s", source.GetName(), condition.Message) - } - isInitialized = true - break + if c := meta.GetCondition(source.Status.Conditions, meta.ReadyCondition); c != nil { + switch c.Status { + case corev1.ConditionTrue: + logger.Successf("%s last fetched revision: %s", source.GetName(), source.GetArtifact().Revision) + case corev1.ConditionUnknown: + logger.Successf("%s reconciling", source.GetName()) + default: + logger.Failuref("%s %s", source.GetName(), c.Message) } + isInitialized = true + break } if !isInitialized { logger.Failuref("%s is not ready", source.GetName()) diff --git a/cmd/gotk/get_source_helm.go b/cmd/gotk/get_source_helm.go index 80b14a5b..9383b2d3 100644 --- a/cmd/gotk/get_source_helm.go +++ b/cmd/gotk/get_source_helm.go @@ -60,18 +60,22 @@ func getSourceHelmCmdRun(cmd *cobra.Command, args []string) error { return nil } + // TODO(hidde): this should print a table, and should produce better output + // for items that have an artifact attached while they are in a reconciling + // 'Unknown' state. for _, source := range list.Items { isInitialized := false - for _, condition := range source.Status.Conditions { - if condition.Type == meta.ReadyCondition { - if condition.Status != corev1.ConditionFalse { - logger.Successf("%s last fetched revision: %s", source.GetName(), source.Status.Artifact.Revision) - } else { - logger.Failuref("%s %s", source.GetName(), condition.Message) - } - isInitialized = true - break + if c := meta.GetCondition(source.Status.Conditions, meta.ReadyCondition); c != nil { + switch c.Status { + case corev1.ConditionTrue: + logger.Successf("%s last fetched revision: %s", source.GetName(), source.GetArtifact().Revision) + case corev1.ConditionUnknown: + logger.Successf("%s reconciling", source.GetName()) + default: + logger.Failuref("%s %s", source.GetName(), c.Message) } + isInitialized = true + break } if !isInitialized { logger.Failuref("%s is not ready", source.GetName()) diff --git a/cmd/gotk/reconcile_helmrelease.go b/cmd/gotk/reconcile_helmrelease.go index e62849b8..541e4afd 100644 --- a/cmd/gotk/reconcile_helmrelease.go +++ b/cmd/gotk/reconcile_helmrelease.go @@ -143,13 +143,12 @@ func isHelmReleaseReady(ctx context.Context, kubeClient client.Client, name, nam return false, err } - for _, condition := range helmRelease.Status.Conditions { - if condition.Type == meta.ReadyCondition { - if condition.Status == corev1.ConditionTrue { - return true, nil - } else if condition.Status == corev1.ConditionFalse && helmRelease.Status.LastAttemptedRevision != "" { - return false, fmt.Errorf(condition.Message) - } + if c := meta.GetCondition(helmRelease.Status.Conditions, meta.ReadyCondition); c != nil { + switch c.Status { + case corev1.ConditionTrue: + return true, nil + case corev1.ConditionFalse: + return false, fmt.Errorf(c.Message) } } return false, nil diff --git a/cmd/gotk/reconcile_source_bucket.go b/cmd/gotk/reconcile_source_bucket.go index 1b20f112..5ac0c156 100644 --- a/cmd/gotk/reconcile_source_bucket.go +++ b/cmd/gotk/reconcile_source_bucket.go @@ -117,13 +117,12 @@ func isBucketReady(ctx context.Context, kubeClient client.Client, name, namespac return false, err } - for _, condition := range bucket.Status.Conditions { - if condition.Type == meta.ReadyCondition { - if condition.Status == corev1.ConditionTrue { - return true, nil - } else if condition.Status == corev1.ConditionFalse { - return false, fmt.Errorf(condition.Message) - } + if c := meta.GetCondition(bucket.Status.Conditions, meta.ReadyCondition); c != nil { + switch c.Status { + case corev1.ConditionTrue: + return true, nil + case corev1.ConditionFalse: + return false, fmt.Errorf(c.Message) } } return false, nil diff --git a/cmd/gotk/reconcile_source_helm.go b/cmd/gotk/reconcile_source_helm.go index 10aa07e0..ea1ad3b8 100644 --- a/cmd/gotk/reconcile_source_helm.go +++ b/cmd/gotk/reconcile_source_helm.go @@ -117,13 +117,12 @@ func isHelmRepositoryReady(ctx context.Context, kubeClient client.Client, name, return false, err } - for _, condition := range helmRepository.Status.Conditions { - if condition.Type == meta.ReadyCondition { - if condition.Status == corev1.ConditionTrue { - return true, nil - } else if condition.Status == corev1.ConditionFalse { - return false, fmt.Errorf(condition.Message) - } + if c := meta.GetCondition(helmRepository.Status.Conditions, meta.ReadyCondition); c != nil { + switch c.Status { + case corev1.ConditionTrue: + return true, nil + case corev1.ConditionFalse: + return false, fmt.Errorf(c.Message) } } return false, nil diff --git a/cmd/gotk/resume_helmrelease.go b/cmd/gotk/resume_helmrelease.go index a192c1e1..2484b0dd 100644 --- a/cmd/gotk/resume_helmrelease.go +++ b/cmd/gotk/resume_helmrelease.go @@ -112,17 +112,15 @@ func isHelmReleaseResumed(ctx context.Context, kubeClient client.Client, name, n return false, err } - for _, condition := range helmRelease.Status.Conditions { - if condition.Type == meta.ReadyCondition { - if condition.Status == corev1.ConditionTrue { - return true, nil - } else if condition.Status == corev1.ConditionFalse { - if condition.Reason == meta.SuspendedReason { - return false, nil - } - - return false, fmt.Errorf(condition.Message) + if c := meta.GetCondition(helmRelease.Status.Conditions, meta.ReadyCondition); c != nil { + switch c.Status { + case corev1.ConditionTrue: + return true, nil + case corev1.ConditionFalse: + if c.Reason == meta.SuspendedReason { + return false, nil } + return false, fmt.Errorf(c.Message) } } return false, nil diff --git a/cmd/gotk/resume_kustomization.go b/cmd/gotk/resume_kustomization.go index cc9b9451..faef0e64 100644 --- a/cmd/gotk/resume_kustomization.go +++ b/cmd/gotk/resume_kustomization.go @@ -111,17 +111,15 @@ func isKustomizationResumed(ctx context.Context, kubeClient client.Client, name, return false, err } - for _, condition := range kustomization.Status.Conditions { - if condition.Type == meta.ReadyCondition { - if condition.Status == corev1.ConditionTrue { - return true, nil - } else if condition.Status == corev1.ConditionFalse { - if condition.Reason == meta.SuspendedReason { - return false, nil - } - - return false, fmt.Errorf(condition.Message) + if c := meta.GetCondition(kustomization.Status.Conditions, meta.ReadyCondition); c != nil { + switch c.Status { + case corev1.ConditionTrue: + return true, nil + case corev1.ConditionFalse: + if c.Reason == meta.SuspendedReason { + return false, nil } + return false, fmt.Errorf(c.Message) } } return false, nil