Skip to content

Commit

Permalink
feat(RedisCluster): add azure boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
dushanpantic committed Feb 3, 2025
1 parent 6c965bd commit 9fd67e0
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 2 deletions.
2 changes: 2 additions & 0 deletions internal/controller/cloud-control/rediscluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/kyma-project/cloud-manager/pkg/common/actions/focal"
"github.com/kyma-project/cloud-manager/pkg/composed"
awsrediscluster "github.com/kyma-project/cloud-manager/pkg/kcp/provider/aws/rediscluster"
azurerediscluster "github.com/kyma-project/cloud-manager/pkg/kcp/provider/azure/rediscluster"
gcprediscluster "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/rediscluster"
"github.com/kyma-project/cloud-manager/pkg/kcp/rediscluster"
ctrl "sigs.k8s.io/controller-runtime"
Expand All @@ -45,6 +46,7 @@ func SetupRedisClusterReconciler(
focal.NewStateFactory(),
gcprediscluster.NewStateFactory(env),
awsrediscluster.NewStateFactory(),
azurerediscluster.NewStateFactory(),
),
).SetupWithManager(kcpManager)
}
Expand Down
51 changes: 51 additions & 0 deletions pkg/kcp/provider/azure/rediscluster/new.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package rediscluster

import (
"context"
"fmt"

"github.com/kyma-project/cloud-manager/pkg/common/actions"
"github.com/kyma-project/cloud-manager/pkg/kcp/rediscluster/types"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

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

func New(stateFactory StateFactory) composed.Action {
return func(ctx context.Context, st composed.State) (error, context.Context) {

state, err := stateFactory.NewState(ctx, st.(types.State))
if err != nil {
composed.LoggerFromCtx(ctx).Error(err, "Failed to bootstrap Azure RedisCluster state")
redisCluster := st.Obj().(*v1beta1.RedisCluster)
redisCluster.Status.State = cloudcontrolv1beta1.StateError
return composed.UpdateStatus(redisCluster).
SetExclusiveConditions(metav1.Condition{
Type: v1beta1.ConditionTypeError,
Status: metav1.ConditionTrue,
Reason: v1beta1.ReasonCloudProviderError,
Message: "Failed to create RedisCluster state",
}).
SuccessError(composed.StopAndForget).
SuccessLogMsg(fmt.Sprintf("Error creating new Azure RedisCluster state: %s", err)).
Run(ctx, st)
}

return composed.ComposeActions(
"redisCluster",
actions.AddFinalizer,

Check failure on line 38 in pkg/kcp/provider/azure/rediscluster/new.go

View workflow job for this annotation

GitHub Actions / build (false, false)

cannot use actions.AddFinalizer (value of type func(f string) composed.Action) as composed.Action value in argument to composed.ComposeActions

Check failure on line 38 in pkg/kcp/provider/azure/rediscluster/new.go

View workflow job for this annotation

GitHub Actions / build (true, true)

cannot use actions.AddFinalizer (value of type func(f string) composed.Action) as composed.Action value in argument to composed.ComposeActions

Check failure on line 38 in pkg/kcp/provider/azure/rediscluster/new.go

View workflow job for this annotation

GitHub Actions / golangci

cannot use actions.AddFinalizer (value of type func(f string) composed.Action) as composed.Action value in argument to composed.ComposeActions
composed.IfElse(composed.Not(composed.MarkedForDeletionPredicate),
composed.ComposeActions(
"redisCluster-create",
),
composed.ComposeActions(
"redisCluster-delete",
actions.RemoveFinalizer,

Check failure on line 45 in pkg/kcp/provider/azure/rediscluster/new.go

View workflow job for this annotation

GitHub Actions / build (false, false)

undefined: actions.RemoveFinalizer

Check failure on line 45 in pkg/kcp/provider/azure/rediscluster/new.go

View workflow job for this annotation

GitHub Actions / build (true, true)

undefined: actions.RemoveFinalizer

Check failure on line 45 in pkg/kcp/provider/azure/rediscluster/new.go

View workflow job for this annotation

GitHub Actions / golangci

undefined: actions.RemoveFinalizer (typecheck)
),
),
composed.StopAndForgetAction,
)(ctx, state)
}
}
32 changes: 32 additions & 0 deletions pkg/kcp/provider/azure/rediscluster/state.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package rediscluster

import (
"context"

"github.com/kyma-project/cloud-manager/pkg/kcp/rediscluster/types"
)

type State struct {
types.State
}

type StateFactory interface {
NewState(ctx context.Context, redisClusterState types.State) (*State, error)
}

type stateFactory struct{}

func NewStateFactory() StateFactory {
return &stateFactory{}
}

func (statefactory *stateFactory) NewState(ctx context.Context, redisClusterState types.State) (*State, error) {

return newState(redisClusterState), nil
}

func newState(redisClusterState types.State) *State {
return &State{
State: redisClusterState,
}
}
9 changes: 7 additions & 2 deletions pkg/kcp/rediscluster/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/kyma-project/cloud-manager/pkg/common/actions/focal"
"github.com/kyma-project/cloud-manager/pkg/composed"
awsrediscluster "github.com/kyma-project/cloud-manager/pkg/kcp/provider/aws/rediscluster"

Check failure on line 11 in pkg/kcp/rediscluster/reconciler.go

View workflow job for this annotation

GitHub Actions / golangci

could not import github.com/kyma-project/cloud-manager/pkg/kcp/provider/aws/rediscluster (-: # github.com/kyma-project/cloud-manager/pkg/kcp/provider/aws/rediscluster
azurerediscluster "github.com/kyma-project/cloud-manager/pkg/kcp/provider/azure/rediscluster"

Check failure on line 12 in pkg/kcp/rediscluster/reconciler.go

View workflow job for this annotation

GitHub Actions / golangci

could not import github.com/kyma-project/cloud-manager/pkg/kcp/provider/azure/rediscluster (-: # github.com/kyma-project/cloud-manager/pkg/kcp/provider/azure/rediscluster
gcprediscluster "github.com/kyma-project/cloud-manager/pkg/kcp/provider/gcp/rediscluster"

"k8s.io/apimachinery/pkg/types"
Expand All @@ -23,21 +24,24 @@ type redisClusterReconciler struct {
composedStateFactory composed.StateFactory
focalStateFactory focal.StateFactory

gcpStateFactory gcprediscluster.StateFactory
awsStateFactory awsrediscluster.StateFactory
gcpStateFactory gcprediscluster.StateFactory
awsStateFactory awsrediscluster.StateFactory
azureStateFactory azurerediscluster.StateFactory
}

func NewRedisClusterReconciler(
composedStateFactory composed.StateFactory,
focalStateFactory focal.StateFactory,
gcpStateFactory gcprediscluster.StateFactory,
awsStateFactory awsrediscluster.StateFactory,
azureStateFactory azurerediscluster.StateFactory,
) RedisClusterReconciler {
return &redisClusterReconciler{
composedStateFactory: composedStateFactory,
focalStateFactory: focalStateFactory,
gcpStateFactory: gcpStateFactory,
awsStateFactory: awsStateFactory,
azureStateFactory: azureStateFactory,
}
}

Expand Down Expand Up @@ -65,6 +69,7 @@ func (r *redisClusterReconciler) newAction() composed.Action {
nil,
composed.NewCase(focal.GcpProviderPredicate, gcprediscluster.New(r.gcpStateFactory)),
composed.NewCase(focal.AwsProviderPredicate, awsrediscluster.New(r.awsStateFactory)),
composed.NewCase(focal.AzureProviderPredicate, azurerediscluster.New(r.azureStateFactory)),
),
)(ctx, newState(st.(focal.State)))
},
Expand Down

0 comments on commit 9fd67e0

Please sign in to comment.