Skip to content

Commit

Permalink
Revert "feat(api): hide unknown conditions (#471)" (#486)
Browse files Browse the repository at this point in the history
This reverts commit e40b7ae.

Signed-off-by: yaroslavborbat <[email protected]>
  • Loading branch information
yaroslavborbat authored Oct 30, 2024
1 parent e40b7ae commit 9da0675
Show file tree
Hide file tree
Showing 87 changed files with 403 additions and 387 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package conditions

import (
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -35,7 +36,7 @@ func HasCondition(conditionType Stringer, conditions []metav1.Condition) bool {
}

func SetCondition(c Conder, conditions *[]metav1.Condition) {
ApplyCondition(c.Condition(), conditions)
meta.SetStatusCondition(conditions, c.Condition())
}

func GetCondition(condType Stringer, conditions []metav1.Condition) (metav1.Condition, bool) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package conditions
import (
"slices"

"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -52,7 +53,7 @@ func (m *Manager) Add(c metav1.Condition) (addedCondition bool) {
}

func (m *Manager) Update(c metav1.Condition) {
ApplyCondition(c, &m.conds)
meta.SetStatusCondition(&m.conds, c)
}

func (m *Manager) Generate() []metav1.Condition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"

"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2"
"github.com/deckhouse/virtualization/api/core/v1alpha2/cvicondition"
)
Expand Down Expand Up @@ -63,7 +63,7 @@ func (v *Validator) ValidateUpdate(_ context.Context, oldObj, newObj runtime.Obj
return nil, nil
}

ready, _ := conditions.GetConditionByType(cvicondition.ReadyType, newCVI.Status.Conditions)
ready, _ := service.GetCondition(cvicondition.ReadyType, newCVI.Status.Conditions)
if newCVI.Status.Phase == virtv2.ImageReady || ready.Status == metav1.ConditionTrue {
return nil, fmt.Errorf("ClusterVirtualImage is in a Ready state: configuration changes are not available")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
"github.com/deckhouse/virtualization-controller/pkg/controller/cvi/internal/source"
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2"
"github.com/deckhouse/virtualization/api/core/v1alpha2/cvicondition"
)
Expand All @@ -41,12 +41,15 @@ func NewDatasourceReadyHandler(sources *source.Sources) *DatasourceReadyHandler
}

func (h DatasourceReadyHandler) Handle(ctx context.Context, cvi *virtv2.ClusterVirtualImage) (reconcile.Result, error) {
condition := metav1.Condition{
Type: cvicondition.DatasourceReadyType,
Status: metav1.ConditionUnknown,
condition, ok := service.GetCondition(cvicondition.DatasourceReadyType, cvi.Status.Conditions)
if !ok {
condition = metav1.Condition{
Type: cvicondition.DatasourceReadyType,
Status: metav1.ConditionUnknown,
}
}

defer func() { conditions.ApplyCondition(condition, &cvi.Status.Conditions) }()
defer func() { service.SetCondition(condition, &cvi.Status.Conditions) }()

if cvi.DeletionTimestamp != nil {
return reconcile.Result{}, nil
Expand All @@ -69,27 +72,27 @@ func (h DatasourceReadyHandler) Handle(ctx context.Context, cvi *virtv2.ClusterV
case errors.Is(err, source.ErrSecretNotFound):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ContainerRegistrySecretNotFound
condition.Message = conditions.CapitalizeFirstLetter(err.Error())
condition.Message = service.CapitalizeFirstLetter(err.Error())
return reconcile.Result{}, nil
case errors.As(err, &source.ImageNotReadyError{}):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ImageNotReady
condition.Message = conditions.CapitalizeFirstLetter(err.Error())
condition.Message = service.CapitalizeFirstLetter(err.Error())
return reconcile.Result{}, nil
case errors.As(err, &source.ClusterImageNotReadyError{}):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ClusterImageNotReady
condition.Message = conditions.CapitalizeFirstLetter(err.Error())
condition.Message = service.CapitalizeFirstLetter(err.Error())
return reconcile.Result{}, nil
case errors.As(err, &source.VirtualDiskNotReadyError{}):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.VirtualDiskNotReady
condition.Message = conditions.CapitalizeFirstLetter(err.Error())
condition.Message = service.CapitalizeFirstLetter(err.Error())
return reconcile.Result{}, nil
case errors.As(err, &source.VirtualDiskAttachedToRunningVMError{}):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.VirtualDiskNotReady
condition.Message = conditions.CapitalizeFirstLetter(err.Error())
condition.Message = service.CapitalizeFirstLetter(err.Error())
return reconcile.Result{}, nil
default:
return reconcile.Result{}, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
"github.com/deckhouse/virtualization-controller/pkg/controller/cvi/internal/source"
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2"
"github.com/deckhouse/virtualization/api/core/v1alpha2/cvicondition"
)
Expand All @@ -43,7 +43,15 @@ func NewLifeCycleHandler(sources *source.Sources, client client.Client) *LifeCyc
}

func (h LifeCycleHandler) Handle(ctx context.Context, cvi *virtv2.ClusterVirtualImage) (reconcile.Result, error) {
readyCondition, _ := conditions.GetConditionByType(cvicondition.ReadyType, cvi.Status.Conditions)
readyCondition, ok := service.GetCondition(cvicondition.ReadyType, cvi.Status.Conditions)
if !ok {
readyCondition = metav1.Condition{
Type: cvicondition.ReadyType,
Status: metav1.ConditionUnknown,
}

service.SetCondition(readyCondition, &cvi.Status.Conditions)
}

if cvi.DeletionTimestamp != nil {
cvi.Status.Phase = virtv2.ImageTerminating
Expand All @@ -54,7 +62,7 @@ func (h LifeCycleHandler) Handle(ctx context.Context, cvi *virtv2.ClusterVirtual
cvi.Status.Phase = virtv2.ImagePending
}

dataSourceReadyCondition, exists := conditions.GetConditionByType(cvicondition.DatasourceReadyType, cvi.Status.Conditions)
dataSourceReadyCondition, exists := service.GetCondition(cvicondition.DatasourceReadyType, cvi.Status.Conditions)
if !exists {
return reconcile.Result{}, fmt.Errorf("condition %s not found, but required", cvicondition.DatasourceReadyType)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

"github.com/deckhouse/virtualization-controller/pkg/common/datasource"
"github.com/deckhouse/virtualization-controller/pkg/controller/common"
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
"github.com/deckhouse/virtualization-controller/pkg/controller/importer"
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
"github.com/deckhouse/virtualization-controller/pkg/controller/supplements"
Expand Down Expand Up @@ -60,12 +59,8 @@ func NewHTTPDataSource(
func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualImage) (reconcile.Result, error) {
log, ctx := logger.GetDataSourceContext(ctx, "http")

condition := metav1.Condition{
Type: cvicondition.ReadyType,
Status: metav1.ConditionUnknown,
}

defer func() { conditions.ApplyCondition(condition, &cvi.Status.Conditions) }()
condition, _ := service.GetCondition(cvicondition.ReadyType, cvi.Status.Conditions)
defer func() { service.SetCondition(condition, &cvi.Status.Conditions) }()

supgen := supplements.NewGenerator(common.CVIShortName, cvi.Name, ds.controllerNamespace, cvi.UID)
pod, err := ds.importerService.GetPod(ctx, supgen)
Expand Down Expand Up @@ -126,7 +121,7 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ProvisioningFailed
condition.Message = conditions.CapitalizeFirstLetter(err.Error() + ".")
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return reconcile.Result{}, nil
default:
return reconcile.Result{}, err
Expand Down Expand Up @@ -155,12 +150,12 @@ func (ds HTTPDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualIma
case errors.Is(err, service.ErrNotInitialized), errors.Is(err, service.ErrNotScheduled):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ProvisioningNotStarted
condition.Message = conditions.CapitalizeFirstLetter(err.Error() + ".")
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return reconcile.Result{}, nil
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ProvisioningFailed
condition.Message = conditions.CapitalizeFirstLetter(err.Error() + ".")
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return reconcile.Result{}, nil
default:
return reconcile.Result{}, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/deckhouse/virtualization-controller/pkg/common/datasource"
"github.com/deckhouse/virtualization-controller/pkg/controller"
"github.com/deckhouse/virtualization-controller/pkg/controller/common"
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
"github.com/deckhouse/virtualization-controller/pkg/controller/importer"
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
"github.com/deckhouse/virtualization-controller/pkg/controller/supplements"
Expand Down Expand Up @@ -73,12 +72,8 @@ func NewObjectRefDataSource(
func (ds ObjectRefDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualImage) (reconcile.Result, error) {
log, ctx := logger.GetDataSourceContext(ctx, "objectref")

condition := metav1.Condition{
Type: cvicondition.ReadyType,
Status: metav1.ConditionUnknown,
}

defer func() { conditions.ApplyCondition(condition, &cvi.Status.Conditions) }()
condition, _ := service.GetCondition(cvicondition.ReadyType, cvi.Status.Conditions)
defer func() { service.SetCondition(condition, &cvi.Status.Conditions) }()

switch cvi.Spec.DataSource.ObjectRef.Kind {
case virtv2.VirtualImageKind:
Expand Down Expand Up @@ -177,7 +172,7 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtu
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ProvisioningFailed
condition.Message = conditions.CapitalizeFirstLetter(err.Error() + ".")
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return reconcile.Result{}, nil
default:
return reconcile.Result{}, err
Expand Down Expand Up @@ -219,12 +214,12 @@ func (ds ObjectRefDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtu
case errors.Is(err, service.ErrNotInitialized), errors.Is(err, service.ErrNotScheduled):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ProvisioningNotStarted
condition.Message = conditions.CapitalizeFirstLetter(err.Error() + ".")
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return reconcile.Result{}, nil
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ProvisioningFailed
condition.Message = conditions.CapitalizeFirstLetter(err.Error() + ".")
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return reconcile.Result{}, nil
default:
return reconcile.Result{}, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (

"github.com/deckhouse/virtualization-controller/pkg/common/datasource"
cc "github.com/deckhouse/virtualization-controller/pkg/controller/common"
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
"github.com/deckhouse/virtualization-controller/pkg/controller/importer"
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
"github.com/deckhouse/virtualization-controller/pkg/controller/supplements"
Expand Down Expand Up @@ -123,7 +122,7 @@ func (ds ObjectRefVirtualDisk) Sync(ctx context.Context, cvi *virtv2.ClusterVirt
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = vicondition.ProvisioningFailed
condition.Message = conditions.CapitalizeFirstLetter(err.Error() + ".")
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return reconcile.Result{}, nil
default:
return reconcile.Result{}, err
Expand Down Expand Up @@ -151,12 +150,12 @@ func (ds ObjectRefVirtualDisk) Sync(ctx context.Context, cvi *virtv2.ClusterVirt
case errors.Is(err, service.ErrNotInitialized), errors.Is(err, service.ErrNotScheduled):
condition.Status = metav1.ConditionFalse
condition.Reason = vicondition.ProvisioningNotStarted
condition.Message = conditions.CapitalizeFirstLetter(err.Error() + ".")
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return reconcile.Result{}, nil
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = vicondition.ProvisioningFailed
condition.Message = conditions.CapitalizeFirstLetter(err.Error() + ".")
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return reconcile.Result{}, nil
default:
return reconcile.Result{}, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

"github.com/deckhouse/virtualization-controller/pkg/common/datasource"
"github.com/deckhouse/virtualization-controller/pkg/controller/common"
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
"github.com/deckhouse/virtualization-controller/pkg/controller/importer"
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
"github.com/deckhouse/virtualization-controller/pkg/controller/supplements"
Expand Down Expand Up @@ -117,7 +116,7 @@ func (ds ObjectRefVirtualImageOnPvc) Sync(ctx context.Context, cvi *virtv2.Clust
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ProvisioningFailed
condition.Message = conditions.CapitalizeFirstLetter(err.Error() + ".")
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return reconcile.Result{}, nil
default:
return reconcile.Result{}, err
Expand Down Expand Up @@ -145,12 +144,12 @@ func (ds ObjectRefVirtualImageOnPvc) Sync(ctx context.Context, cvi *virtv2.Clust
case errors.Is(err, service.ErrNotInitialized), errors.Is(err, service.ErrNotScheduled):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ProvisioningNotStarted
condition.Message = conditions.CapitalizeFirstLetter(err.Error() + ".")
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return reconcile.Result{}, nil
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ProvisioningFailed
condition.Message = conditions.CapitalizeFirstLetter(err.Error() + ".")
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return reconcile.Result{}, nil
default:
return reconcile.Result{}, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (

"github.com/deckhouse/virtualization-controller/pkg/common/datasource"
"github.com/deckhouse/virtualization-controller/pkg/controller/common"
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
"github.com/deckhouse/virtualization-controller/pkg/controller/importer"
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
"github.com/deckhouse/virtualization-controller/pkg/controller/supplements"
Expand Down Expand Up @@ -67,12 +66,8 @@ func NewRegistryDataSource(
func (ds RegistryDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtualImage) (reconcile.Result, error) {
log, ctx := logger.GetDataSourceContext(ctx, "registry")

condition := metav1.Condition{
Type: cvicondition.ReadyType,
Status: metav1.ConditionUnknown,
}

defer func() { conditions.ApplyCondition(condition, &cvi.Status.Conditions) }()
condition, _ := service.GetCondition(cvicondition.ReadyType, cvi.Status.Conditions)
defer func() { service.SetCondition(condition, &cvi.Status.Conditions) }()

supgen := supplements.NewGenerator(common.CVIShortName, cvi.Name, ds.controllerNamespace, cvi.UID)
pod, err := ds.importerService.GetPod(ctx, supgen)
Expand Down Expand Up @@ -133,7 +128,7 @@ func (ds RegistryDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtua
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ProvisioningFailed
condition.Message = conditions.CapitalizeFirstLetter(err.Error() + ".")
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return reconcile.Result{}, nil
default:
return reconcile.Result{}, err
Expand Down Expand Up @@ -161,12 +156,12 @@ func (ds RegistryDataSource) Sync(ctx context.Context, cvi *virtv2.ClusterVirtua
case errors.Is(err, service.ErrNotInitialized), errors.Is(err, service.ErrNotScheduled):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ProvisioningNotStarted
condition.Message = conditions.CapitalizeFirstLetter(err.Error() + ".")
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return reconcile.Result{}, nil
case errors.Is(err, service.ErrProvisioningFailed):
condition.Status = metav1.ConditionFalse
condition.Reason = cvicondition.ProvisioningFailed
condition.Message = conditions.CapitalizeFirstLetter(err.Error() + ".")
condition.Message = service.CapitalizeFirstLetter(err.Error() + ".")
return reconcile.Result{}, nil
default:
return reconcile.Result{}, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/reconcile"

cc "github.com/deckhouse/virtualization-controller/pkg/controller/common"
"github.com/deckhouse/virtualization-controller/pkg/controller/conditions"
"github.com/deckhouse/virtualization-controller/pkg/controller/service"
virtv2 "github.com/deckhouse/virtualization/api/core/v1alpha2"
"github.com/deckhouse/virtualization/api/core/v1alpha2/cvicondition"
Expand Down Expand Up @@ -112,5 +111,5 @@ func setPhaseConditionToFailed(ready *metav1.Condition, phase *virtv2.ImagePhase
*phase = virtv2.ImageFailed
ready.Status = metav1.ConditionFalse
ready.Reason = cvicondition.ProvisioningFailed
ready.Message = conditions.CapitalizeFirstLetter(err.Error())
ready.Message = service.CapitalizeFirstLetter(err.Error())
}
Loading

0 comments on commit 9da0675

Please sign in to comment.