Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(AzureRedis) - allow standard tier - kcp piece #1046

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions api/cloud-control/v1beta1/redisinstance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ type AzureRedisSKU struct {
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum=1;2;3;4;5
Capacity int `json:"capacity"`

// +kubebuilder:validation:Optional
// +kubebuilder:validation:Enum=S;P
// +kubebuilder:default=P
// +kubebuilder:validation:XValidation:rule=(self == oldSelf), message="Family is immutable."
Family string `json:"family,omitempty"`
}

type TimeOfDayGcp struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ spec:
- 4
- 5
type: integer
family:
default: P
enum:
- S
- P
type: string
x-kubernetes-validations:
- message: Family is immutable.
rule: (self == oldSelf)
required:
- capacity
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ spec:
- 4
- 5
type: integer
family:
default: P
enum:
- S
- P
type: string
x-kubernetes-validations:
- message: Family is immutable.
rule: (self == oldSelf)
required:
- capacity
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ var _ = Describe("Feature: Cleanup orphan resources", func() {
WithIpRange(ipRange.Name),
WithScope(kymaName),
WithRedisInstanceAzure(),
WithSKU(2),
WithSKU(2, "P"),
WithKcpAzureRedisVersion("6.0"),
)).To(Succeed(), "failed creating RedisInstance")
})
Expand Down
13 changes: 12 additions & 1 deletion internal/controller/cloud-control/redisinstance_azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var _ = Describe("Feature: KCP RedisInstance", func() {

redisInstance := &cloudcontrolv1beta1.RedisInstance{}
redisCapacity := 2
redisFamily := "S"

resourceGroupName := azurecommon.AzureCloudManagerResourceGroupName(scope.Spec.Scope.Azure.VpcNetwork)
var redis *armredis.ResourceInfo
Expand All @@ -75,7 +76,7 @@ var _ = Describe("Feature: KCP RedisInstance", func() {
WithIpRange(kcpIpRangeName),
WithScope(name),
WithRedisInstanceAzure(),
WithSKU(redisCapacity),
WithSKU(redisCapacity, redisFamily),
WithKcpAzureRedisVersion("6.0"),
).
Should(Succeed(), "failed creating RedisInstance")
Expand All @@ -97,6 +98,16 @@ var _ = Describe("Feature: KCP RedisInstance", func() {
Expect(actualCapacity).To(Equal(int32(redisCapacity)))
})

By("And Then Azure Redis has family as specified in KCP RedisInstance", func() {
actualFamily := string(ptr.Deref(redis.Properties.SKU.Family, ""))
redisStandardFamilyTier := "C"
Expect(actualFamily).To(Equal(redisStandardFamilyTier))

redisStandardFamilyName := "Standard"
actualFamilyName := string(ptr.Deref(redis.Properties.SKU.Name, ""))
Expect(actualFamilyName).To(Equal(redisStandardFamilyName))
})

By("And Then Azure Redis has nonSSl port disabled ", func() {
nonSSLPortEnabled := ptr.Deref(redis.Properties.EnableNonSSLPort, true)
Expect(nonSSLPortEnabled).To(Equal(false))
Expand Down
15 changes: 13 additions & 2 deletions pkg/kcp/provider/azure/redisinstance/createRedis.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ func createRedis(ctx context.Context, st composed.State) (error, context.Context
}

func getCreateParams(state *State) armredis.CreateParameters {
skuName, skuFamily := getSKUParams(state)
createProperties := &armredis.CreateProperties{
SKU: &armredis.SKU{
Name: to.Ptr(armredis.SKUNamePremium),
Name: skuName,
Capacity: to.Ptr[int32](int32(state.ObjAsRedisInstance().Spec.Instance.Azure.SKU.Capacity)),
Family: to.Ptr(armredis.SKUFamilyP),
Family: skuFamily,
},
RedisConfiguration: state.ObjAsRedisInstance().Spec.Instance.Azure.RedisConfiguration.GetRedisConfig(),
EnableNonSSLPort: to.Ptr(false),
Expand All @@ -78,3 +79,13 @@ func getCreateParams(state *State) armredis.CreateParameters {
}
return createParameters
}

func getSKUParams(state *State) (*armredis.SKUName, *armredis.SKUFamily) {
skuName := to.Ptr(armredis.SKUNamePremium)
skuFamily := to.Ptr(armredis.SKUFamilyP)
if state.ObjAsRedisInstance().Spec.Instance.Azure.SKU.Family == "S" {
skuName = to.Ptr(armredis.SKUNameStandard)
skuFamily = to.Ptr(armredis.SKUFamilyC)
}
return skuName, skuFamily
}
2 changes: 0 additions & 2 deletions pkg/kcp/provider/azure/redisinstance/modifyRedis.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ func getUpdateParams(state *State) (armredis.UpdateParameters, bool) {

updateProperties := &armredis.UpdateProperties{
SKU: &armredis.SKU{
Name: to.Ptr(armredis.SKUNamePremium),
Capacity: to.Ptr[int32](int32(state.ObjAsRedisInstance().Spec.Instance.Azure.SKU.Capacity)),
Family: to.Ptr(armredis.SKUFamilyP),
},
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/testinfra/dsl/redisInstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,11 @@ func WithKcpAzureRedisVersion(redisVersion string) ObjAction {
},
}
}
func WithSKU(capacity int) ObjAction {
func WithSKU(capacity int, family string) ObjAction {
return &objAction{
f: func(obj client.Object) {
if azureRedisInstance, ok := obj.(*cloudcontrolv1beta1.RedisInstance); ok {
azureRedisInstance.Spec.Instance.Azure.SKU = cloudcontrolv1beta1.AzureRedisSKU{Capacity: capacity}
azureRedisInstance.Spec.Instance.Azure.SKU = cloudcontrolv1beta1.AzureRedisSKU{Capacity: capacity, Family: family}
return
}
panic(fmt.Errorf("unhandled type %T in WithKcpAzureRedisVersion", obj))
Expand Down
Loading