mirror of
https://github.com/fluxcd/flux2.git
synced 2026-02-25 17:11:48 +00:00
Make use of GetCondition from pkg/apis/meta
This commit is contained in:
parent
3295ef4fcf
commit
f216273008
13 changed files with 111 additions and 115 deletions
|
|
@ -275,13 +275,12 @@ func isHelmChartReady(ctx context.Context, kubeClient client.Client, name, names
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, condition := range helmChart.Status.Conditions {
|
if c := meta.GetCondition(helmChart.Status.Conditions, meta.ReadyCondition); c != nil {
|
||||||
if condition.Type == meta.ReadyCondition {
|
switch c.Status {
|
||||||
if condition.Status == corev1.ConditionTrue {
|
case corev1.ConditionTrue:
|
||||||
return true, nil
|
return true, nil
|
||||||
} else if condition.Status == corev1.ConditionFalse {
|
case corev1.ConditionFalse:
|
||||||
return false, fmt.Errorf(condition.Message)
|
return false, fmt.Errorf(c.Message)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false, nil
|
return false, nil
|
||||||
|
|
|
||||||
|
|
@ -306,13 +306,12 @@ func isKustomizationReady(ctx context.Context, kubeClient client.Client, name, n
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, condition := range kustomization.Status.Conditions {
|
if c := meta.GetCondition(kustomization.Status.Conditions, meta.ReadyCondition); c != nil {
|
||||||
if condition.Type == meta.ReadyCondition {
|
switch c.Status {
|
||||||
if condition.Status == corev1.ConditionTrue {
|
case corev1.ConditionTrue:
|
||||||
return true, nil
|
return true, nil
|
||||||
} else if condition.Status == corev1.ConditionFalse {
|
case corev1.ConditionFalse:
|
||||||
return false, fmt.Errorf(condition.Message)
|
return false, fmt.Errorf(c.Message)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false, nil
|
return false, nil
|
||||||
|
|
|
||||||
|
|
@ -373,13 +373,12 @@ func isGitRepositoryReady(ctx context.Context, kubeClient client.Client, name, n
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, condition := range gitRepository.Status.Conditions {
|
if c := meta.GetCondition(gitRepository.Status.Conditions, meta.ReadyCondition); c != nil {
|
||||||
if condition.Type == meta.ReadyCondition {
|
switch c.Status {
|
||||||
if condition.Status == corev1.ConditionTrue {
|
case corev1.ConditionTrue:
|
||||||
return true, nil
|
return true, nil
|
||||||
} else if condition.Status == corev1.ConditionFalse {
|
case corev1.ConditionFalse:
|
||||||
return false, fmt.Errorf(condition.Message)
|
return false, fmt.Errorf(c.Message)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false, nil
|
return false, nil
|
||||||
|
|
|
||||||
|
|
@ -68,20 +68,17 @@ func getHelmReleaseCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
isInitialized := false
|
isInitialized := false
|
||||||
for _, condition := range helmRelease.Status.Conditions {
|
if c := meta.GetCondition(helmRelease.Status.Conditions, meta.ReadyCondition); c != nil {
|
||||||
if condition.Type == meta.ReadyCondition {
|
switch c.Status {
|
||||||
if condition.Status != corev1.ConditionFalse {
|
case corev1.ConditionTrue:
|
||||||
if helmRelease.Status.LastAppliedRevision != "" {
|
logger.Successf("%s last applied revision %s", helmRelease.GetName(), helmRelease.Status.LastAppliedRevision)
|
||||||
logger.Successf("%s last applied revision %s", helmRelease.GetName(), helmRelease.Status.LastAppliedRevision)
|
case corev1.ConditionUnknown:
|
||||||
} else {
|
logger.Successf("%s reconciling", helmRelease.GetName())
|
||||||
logger.Successf("%s reconciling", helmRelease.GetName())
|
default:
|
||||||
}
|
logger.Failuref("%s %s", helmRelease.GetName(), c.Message)
|
||||||
} else {
|
|
||||||
logger.Failuref("%s %s", helmRelease.GetName(), condition.Message)
|
|
||||||
}
|
|
||||||
isInitialized = true
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
isInitialized = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
if !isInitialized {
|
if !isInitialized {
|
||||||
logger.Failuref("%s is not ready", helmRelease.GetName())
|
logger.Failuref("%s is not ready", helmRelease.GetName())
|
||||||
|
|
|
||||||
|
|
@ -67,20 +67,17 @@ func getKsCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
isInitialized := false
|
isInitialized := false
|
||||||
for _, condition := range kustomization.Status.Conditions {
|
if c := meta.GetCondition(kustomization.Status.Conditions, meta.ReadyCondition); c != nil {
|
||||||
if condition.Type == meta.ReadyCondition {
|
switch c.Status {
|
||||||
if condition.Status != corev1.ConditionFalse {
|
case corev1.ConditionTrue:
|
||||||
if kustomization.Status.LastAppliedRevision != "" {
|
logger.Successf("%s last applied revision %s", kustomization.GetName(), kustomization.Status.LastAppliedRevision)
|
||||||
logger.Successf("%s last applied revision %s", kustomization.GetName(), kustomization.Status.LastAppliedRevision)
|
case corev1.ConditionUnknown:
|
||||||
} else {
|
logger.Successf("%s reconciling", kustomization.GetName())
|
||||||
logger.Successf("%s reconciling", kustomization.GetName())
|
default:
|
||||||
}
|
logger.Failuref("%s %s", kustomization.GetName(), c.Message)
|
||||||
} else {
|
|
||||||
logger.Failuref("%s %s", kustomization.GetName(), condition.Message)
|
|
||||||
}
|
|
||||||
isInitialized = true
|
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
isInitialized = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
if !isInitialized {
|
if !isInitialized {
|
||||||
logger.Failuref("%s is not ready", kustomization.GetName())
|
logger.Failuref("%s is not ready", kustomization.GetName())
|
||||||
|
|
|
||||||
|
|
@ -60,18 +60,22 @@ func getSourceBucketCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
return nil
|
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 {
|
for _, source := range list.Items {
|
||||||
isInitialized := false
|
isInitialized := false
|
||||||
for _, condition := range source.Status.Conditions {
|
if c := meta.GetCondition(source.Status.Conditions, meta.ReadyCondition); c != nil {
|
||||||
if condition.Type == meta.ReadyCondition {
|
switch c.Status {
|
||||||
if condition.Status != corev1.ConditionFalse {
|
case corev1.ConditionTrue:
|
||||||
logger.Successf("%s last fetched revision: %s", source.GetName(), source.Status.Artifact.Revision)
|
logger.Successf("%s last fetched revision: %s", source.GetName(), source.GetArtifact().Revision)
|
||||||
} else {
|
case corev1.ConditionUnknown:
|
||||||
logger.Failuref("%s %s", source.GetName(), condition.Message)
|
logger.Successf("%s reconciling", source.GetName())
|
||||||
}
|
default:
|
||||||
isInitialized = true
|
logger.Failuref("%s %s", source.GetName(), c.Message)
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
isInitialized = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
if !isInitialized {
|
if !isInitialized {
|
||||||
logger.Failuref("%s is not ready", source.GetName())
|
logger.Failuref("%s is not ready", source.GetName())
|
||||||
|
|
|
||||||
|
|
@ -60,18 +60,22 @@ func getSourceGitCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
return nil
|
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 {
|
for _, source := range list.Items {
|
||||||
isInitialized := false
|
isInitialized := false
|
||||||
for _, condition := range source.Status.Conditions {
|
if c := meta.GetCondition(source.Status.Conditions, meta.ReadyCondition); c != nil {
|
||||||
if condition.Type == meta.ReadyCondition {
|
switch c.Status {
|
||||||
if condition.Status != corev1.ConditionFalse {
|
case corev1.ConditionTrue:
|
||||||
logger.Successf("%s last fetched revision: %s", source.GetName(), source.Status.Artifact.Revision)
|
logger.Successf("%s last fetched revision: %s", source.GetName(), source.GetArtifact().Revision)
|
||||||
} else {
|
case corev1.ConditionUnknown:
|
||||||
logger.Failuref("%s %s", source.GetName(), condition.Message)
|
logger.Successf("%s reconciling", source.GetName())
|
||||||
}
|
default:
|
||||||
isInitialized = true
|
logger.Failuref("%s %s", source.GetName(), c.Message)
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
isInitialized = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
if !isInitialized {
|
if !isInitialized {
|
||||||
logger.Failuref("%s is not ready", source.GetName())
|
logger.Failuref("%s is not ready", source.GetName())
|
||||||
|
|
|
||||||
|
|
@ -60,18 +60,22 @@ func getSourceHelmCmdRun(cmd *cobra.Command, args []string) error {
|
||||||
return nil
|
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 {
|
for _, source := range list.Items {
|
||||||
isInitialized := false
|
isInitialized := false
|
||||||
for _, condition := range source.Status.Conditions {
|
if c := meta.GetCondition(source.Status.Conditions, meta.ReadyCondition); c != nil {
|
||||||
if condition.Type == meta.ReadyCondition {
|
switch c.Status {
|
||||||
if condition.Status != corev1.ConditionFalse {
|
case corev1.ConditionTrue:
|
||||||
logger.Successf("%s last fetched revision: %s", source.GetName(), source.Status.Artifact.Revision)
|
logger.Successf("%s last fetched revision: %s", source.GetName(), source.GetArtifact().Revision)
|
||||||
} else {
|
case corev1.ConditionUnknown:
|
||||||
logger.Failuref("%s %s", source.GetName(), condition.Message)
|
logger.Successf("%s reconciling", source.GetName())
|
||||||
}
|
default:
|
||||||
isInitialized = true
|
logger.Failuref("%s %s", source.GetName(), c.Message)
|
||||||
break
|
|
||||||
}
|
}
|
||||||
|
isInitialized = true
|
||||||
|
break
|
||||||
}
|
}
|
||||||
if !isInitialized {
|
if !isInitialized {
|
||||||
logger.Failuref("%s is not ready", source.GetName())
|
logger.Failuref("%s is not ready", source.GetName())
|
||||||
|
|
|
||||||
|
|
@ -143,13 +143,12 @@ func isHelmReleaseReady(ctx context.Context, kubeClient client.Client, name, nam
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, condition := range helmRelease.Status.Conditions {
|
if c := meta.GetCondition(helmRelease.Status.Conditions, meta.ReadyCondition); c != nil {
|
||||||
if condition.Type == meta.ReadyCondition {
|
switch c.Status {
|
||||||
if condition.Status == corev1.ConditionTrue {
|
case corev1.ConditionTrue:
|
||||||
return true, nil
|
return true, nil
|
||||||
} else if condition.Status == corev1.ConditionFalse && helmRelease.Status.LastAttemptedRevision != "" {
|
case corev1.ConditionFalse:
|
||||||
return false, fmt.Errorf(condition.Message)
|
return false, fmt.Errorf(c.Message)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false, nil
|
return false, nil
|
||||||
|
|
|
||||||
|
|
@ -117,13 +117,12 @@ func isBucketReady(ctx context.Context, kubeClient client.Client, name, namespac
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, condition := range bucket.Status.Conditions {
|
if c := meta.GetCondition(bucket.Status.Conditions, meta.ReadyCondition); c != nil {
|
||||||
if condition.Type == meta.ReadyCondition {
|
switch c.Status {
|
||||||
if condition.Status == corev1.ConditionTrue {
|
case corev1.ConditionTrue:
|
||||||
return true, nil
|
return true, nil
|
||||||
} else if condition.Status == corev1.ConditionFalse {
|
case corev1.ConditionFalse:
|
||||||
return false, fmt.Errorf(condition.Message)
|
return false, fmt.Errorf(c.Message)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false, nil
|
return false, nil
|
||||||
|
|
|
||||||
|
|
@ -117,13 +117,12 @@ func isHelmRepositoryReady(ctx context.Context, kubeClient client.Client, name,
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, condition := range helmRepository.Status.Conditions {
|
if c := meta.GetCondition(helmRepository.Status.Conditions, meta.ReadyCondition); c != nil {
|
||||||
if condition.Type == meta.ReadyCondition {
|
switch c.Status {
|
||||||
if condition.Status == corev1.ConditionTrue {
|
case corev1.ConditionTrue:
|
||||||
return true, nil
|
return true, nil
|
||||||
} else if condition.Status == corev1.ConditionFalse {
|
case corev1.ConditionFalse:
|
||||||
return false, fmt.Errorf(condition.Message)
|
return false, fmt.Errorf(c.Message)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false, nil
|
return false, nil
|
||||||
|
|
|
||||||
|
|
@ -112,17 +112,15 @@ func isHelmReleaseResumed(ctx context.Context, kubeClient client.Client, name, n
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, condition := range helmRelease.Status.Conditions {
|
if c := meta.GetCondition(helmRelease.Status.Conditions, meta.ReadyCondition); c != nil {
|
||||||
if condition.Type == meta.ReadyCondition {
|
switch c.Status {
|
||||||
if condition.Status == corev1.ConditionTrue {
|
case corev1.ConditionTrue:
|
||||||
return true, nil
|
return true, nil
|
||||||
} else if condition.Status == corev1.ConditionFalse {
|
case corev1.ConditionFalse:
|
||||||
if condition.Reason == meta.SuspendedReason {
|
if c.Reason == meta.SuspendedReason {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
|
||||||
|
|
||||||
return false, fmt.Errorf(condition.Message)
|
|
||||||
}
|
}
|
||||||
|
return false, fmt.Errorf(c.Message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false, nil
|
return false, nil
|
||||||
|
|
|
||||||
|
|
@ -111,17 +111,15 @@ func isKustomizationResumed(ctx context.Context, kubeClient client.Client, name,
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, condition := range kustomization.Status.Conditions {
|
if c := meta.GetCondition(kustomization.Status.Conditions, meta.ReadyCondition); c != nil {
|
||||||
if condition.Type == meta.ReadyCondition {
|
switch c.Status {
|
||||||
if condition.Status == corev1.ConditionTrue {
|
case corev1.ConditionTrue:
|
||||||
return true, nil
|
return true, nil
|
||||||
} else if condition.Status == corev1.ConditionFalse {
|
case corev1.ConditionFalse:
|
||||||
if condition.Reason == meta.SuspendedReason {
|
if c.Reason == meta.SuspendedReason {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
|
||||||
|
|
||||||
return false, fmt.Errorf(condition.Message)
|
|
||||||
}
|
}
|
||||||
|
return false, fmt.Errorf(c.Message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false, nil
|
return false, nil
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue