Skip to content

Commit

Permalink
chore(RedisInstance): no longer put cloud provider errors in conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
dushanpantic committed Dec 12, 2024
1 parent b0ebfa1 commit 83fa31c
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package redisinstance

import (
"context"
"fmt"

"github.com/aws/aws-sdk-go-v2/service/elasticache/types"
"github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1"
Expand Down Expand Up @@ -69,8 +68,8 @@ func createElastiCacheCluster(ctx context.Context, st composed.State) (error, co
meta.SetStatusCondition(redisInstance.Conditions(), metav1.Condition{
Type: v1beta1.ConditionTypeError,
Status: "True",
Reason: v1beta1.ConditionTypeError,
Message: fmt.Sprintf("Failed creating AWS Elasticache: %s", err),
Reason: v1beta1.ReasonCloudProviderError,
Message: "Failed to create RedisInstance",
})
redisInstance.Status.State = cloudcontrolv1beta1.ErrorState
err = state.UpdateObjStatus(ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package redisinstance

import (
"context"
"fmt"

cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1"

Expand Down Expand Up @@ -45,8 +44,8 @@ func updateElastiCacheCluster(ctx context.Context, st composed.State) (error, co
meta.SetStatusCondition(redisInstance.Conditions(), metav1.Condition{
Type: cloudcontrolv1beta1.ConditionTypeError,
Status: "True",
Reason: cloudcontrolv1beta1.ConditionTypeError,
Message: fmt.Sprintf("Failed updating GwsRedis: %s", err),
Reason: cloudcontrolv1beta1.ReasonCloudProviderError,
Message: "Failed to update RedisInstance",
})
redisInstance.Status.State = cloudcontrolv1beta1.ErrorState
err = state.UpdateObjStatus(ctx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package redisinstance

import (
"context"
"errors"

"github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1"
cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1"
Expand All @@ -18,13 +19,14 @@ func waitElastiCacheAvailable(ctx context.Context, st composed.State) (error, co

if state.elastiCacheReplicationGroup == nil {
errorMsg := "Error: elasti cache cluster instance is not loaded"
logger.Error(errors.New(errorMsg), errorMsg)
redisInstance := st.Obj().(*v1beta1.RedisInstance)
redisInstance.Status.State = cloudcontrolv1beta1.ErrorState
return composed.UpdateStatus(redisInstance).
SetExclusiveConditions(metav1.Condition{
Type: v1beta1.ConditionTypeError,
Status: metav1.ConditionTrue,
Reason: v1beta1.ConditionTypeError,
Reason: v1beta1.ReasonUnknown,
Message: errorMsg,
}).
SuccessError(composed.StopAndForget).
Expand Down
4 changes: 3 additions & 1 deletion pkg/kcp/provider/aws/redisinstance/waitElastiCacheDeleted.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package redisinstance

import (
"context"
"errors"
"fmt"

"github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1"
Expand All @@ -25,13 +26,14 @@ func waitElastiCacheDeleted(ctx context.Context, st composed.State) (error, cont

if cacheState != awsmeta.ElastiCache_DELETING {
errorMsg := fmt.Sprintf("Error: unexpected aws elasticache cluster state: %s", cacheState)
logger.Error(errors.New(errorMsg), errorMsg)
redisInstance := st.Obj().(*v1beta1.RedisInstance)
redisInstance.Status.State = cloudcontrolv1beta1.ErrorState
return composed.UpdateStatus(redisInstance).
SetExclusiveConditions(metav1.Condition{
Type: v1beta1.ConditionTypeError,
Status: metav1.ConditionTrue,
Reason: v1beta1.ConditionTypeError,
Reason: v1beta1.ReasonUnknown,
Message: errorMsg,
}).
SuccessError(composed.StopAndForget).
Expand Down
4 changes: 3 additions & 1 deletion pkg/kcp/provider/aws/redisinstance/waitUserGroupDeleted.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package redisinstance

import (
"context"
"errors"
"fmt"

"github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1"
Expand All @@ -25,13 +26,14 @@ func waitUserGroupDeleted(ctx context.Context, st composed.State) (error, contex

if cacheState != awsmeta.ElastiCache_UserGroup_DELETING {
errorMsg := fmt.Sprintf("Error: unexpected aws elasticache user group state: %s", cacheState)
logger.Error(errors.New(errorMsg), errorMsg)
redisInstance := st.Obj().(*v1beta1.RedisInstance)
redisInstance.Status.State = cloudcontrolv1beta1.ErrorState
return composed.UpdateStatus(redisInstance).
SetExclusiveConditions(metav1.Condition{
Type: v1beta1.ConditionTypeError,
Status: metav1.ConditionTrue,
Reason: v1beta1.ConditionTypeError,
Reason: v1beta1.ReasonUnknown,
Message: errorMsg,
}).
SuccessError(composed.StopAndForget).
Expand Down
4 changes: 2 additions & 2 deletions pkg/kcp/provider/gcp/redisinstance/createRedis.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func createRedis(ctx context.Context, st composed.State) (error, context.Context
meta.SetStatusCondition(redisInstance.Conditions(), metav1.Condition{
Type: v1beta1.ConditionTypeError,
Status: "True",
Reason: v1beta1.ReasonGcpError,
Message: fmt.Sprintf("Failed creating GcpRedis: %s", err),
Reason: v1beta1.ReasonCloudProviderError,
Message: "Failed to create RedisInstance",
})
redisInstance.Status.State = cloudcontrolv1beta1.ErrorState

Expand Down
5 changes: 2 additions & 3 deletions pkg/kcp/provider/gcp/redisinstance/deleteRedis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package redisinstance

import (
"context"
"fmt"

"cloud.google.com/go/redis/apiv1/redispb"
"github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1"
Expand Down Expand Up @@ -43,8 +42,8 @@ func deleteRedis(ctx context.Context, st composed.State) (error, context.Context
meta.SetStatusCondition(redisInstance.Conditions(), metav1.Condition{
Type: v1beta1.ConditionTypeError,
Status: "True",
Reason: v1beta1.ReasonGcpError,
Message: fmt.Sprintf("Failed deleting GcpRedis: %s", err),
Reason: v1beta1.ReasonCloudProviderError,
Message: "Failed to delete RedisInstance",
})
redisInstance.Status.State = cloudcontrolv1beta1.ErrorState

Expand Down
5 changes: 2 additions & 3 deletions pkg/kcp/provider/gcp/redisinstance/loadRedis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package redisinstance

import (
"context"
"fmt"

"github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1"
cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1"
Expand Down Expand Up @@ -40,8 +39,8 @@ func loadRedis(ctx context.Context, st composed.State) (error, context.Context)
meta.SetStatusCondition(redisInstance.Conditions(), metav1.Condition{
Type: v1beta1.ConditionTypeError,
Status: "True",
Reason: v1beta1.ReasonGcpError,
Message: fmt.Sprintf("Failed loading GcpRedis: %s", err),
Reason: v1beta1.ReasonCloudProviderError,
Message: "Failed to load RedisInstance",
})
redisInstance.Status.State = cloudcontrolv1beta1.ErrorState

Expand Down
5 changes: 3 additions & 2 deletions pkg/kcp/provider/gcp/redisinstance/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ func New(stateFactory StateFactory) composed.Action {

state, err := stateFactory.NewState(ctx, st.(types.State))
if err != nil {
composed.LoggerFromCtx(ctx).Error(err, "Failed to bootstrap GCP RedisInstance state")
redisInstance := st.Obj().(*v1beta1.RedisInstance)
redisInstance.Status.State = cloudcontrolv1beta1.ErrorState
return composed.UpdateStatus(redisInstance).
SetExclusiveConditions(metav1.Condition{
Type: v1beta1.ConditionTypeError,
Status: metav1.ConditionTrue,
Reason: v1beta1.ReasonGcpError,
Message: err.Error(),
Reason: v1beta1.ReasonCloudProviderError,
Message: "Failed to create RedisInstance state",
}).
SuccessError(composed.StopAndForget).
SuccessLogMsg(fmt.Sprintf("Error creating new GCP RedisInstance state: %s", err)).
Expand Down
5 changes: 2 additions & 3 deletions pkg/kcp/provider/gcp/redisinstance/updateRedis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package redisinstance

import (
"context"
"fmt"

cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1"
"github.com/kyma-project/cloud-manager/pkg/composed"
Expand Down Expand Up @@ -43,8 +42,8 @@ func updateRedis(ctx context.Context, st composed.State) (error, context.Context
meta.SetStatusCondition(redisInstance.Conditions(), metav1.Condition{
Type: cloudcontrolv1beta1.ConditionTypeError,
Status: "True",
Reason: cloudcontrolv1beta1.ReasonGcpError,
Message: fmt.Sprintf("Failed updating GcpRedis: %s", err),
Reason: cloudcontrolv1beta1.ReasonCloudProviderError,
Message: "Failed to update RedisInstance",
})
err = state.UpdateObjStatus(ctx)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion pkg/kcp/provider/gcp/redisinstance/waitRedisAvailable.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package redisinstance

import (
"context"
"errors"

"cloud.google.com/go/redis/apiv1/redispb"
"github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1"
Expand All @@ -17,13 +18,14 @@ func waitRedisAvailable(ctx context.Context, st composed.State) (error, context.

if state.gcpRedisInstance == nil {
errorMsg := "Error: redis instance is not loaded"
logger.Error(errors.New(errorMsg), errorMsg)
redisInstance := st.Obj().(*v1beta1.RedisInstance)
redisInstance.Status.State = cloudcontrolv1beta1.ErrorState
return composed.UpdateStatus(redisInstance).
SetExclusiveConditions(metav1.Condition{
Type: v1beta1.ConditionTypeError,
Status: metav1.ConditionTrue,
Reason: v1beta1.ReasonGcpError,
Reason: v1beta1.ReasonUnknown,
Message: errorMsg,
}).
SuccessError(composed.StopAndForget).
Expand Down
4 changes: 3 additions & 1 deletion pkg/kcp/provider/gcp/redisinstance/waitRedisDeleted.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package redisinstance

import (
"context"
"errors"

"cloud.google.com/go/redis/apiv1/redispb"
"github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1"
Expand All @@ -21,13 +22,14 @@ func waitRedisDeleted(ctx context.Context, st composed.State) (error, context.Co

if state.gcpRedisInstance.State != redispb.Instance_DELETING {
errorMsg := "Error: unexpected gcp redis state"
logger.Error(errors.New(errorMsg), errorMsg)
redisInstance := st.Obj().(*v1beta1.RedisInstance)
redisInstance.Status.State = cloudcontrolv1beta1.ErrorState
return composed.UpdateStatus(redisInstance).
SetExclusiveConditions(metav1.Condition{
Type: v1beta1.ConditionTypeError,
Status: metav1.ConditionTrue,
Reason: v1beta1.ReasonGcpError,
Reason: v1beta1.ReasonUnknown,
Message: errorMsg,
}).
SuccessError(composed.StopAndForget).
Expand Down

0 comments on commit 83fa31c

Please sign in to comment.