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

Remove the CapacityThresholds from ToolchainConfig #1000

Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
Expand Up @@ -52,37 +52,6 @@ spec:
or not
type: boolean
type: object
capacityThresholds:
description: 'Keeps parameters necessary for configuring capacity
limits Deprecated: This is no longer used for anything.'
properties:
maxNumberOfSpacesPerMemberCluster:
additionalProperties:
type: integer
description: 'Contains a map of maximal number of spaces that
can be provisioned per member cluster mapped by the cluster
name Deprecated: This is no longer used for anything.'
type: object
x-kubernetes-map-type: atomic
resourceCapacityThreshold:
description: 'Contains capacity threshold configuration Deprecated:
This is no longer used for anything.'
properties:
defaultThreshold:
description: It is the default capacity threshold (in
percentage of usage) to be used for all member clusters
if no special threshold is defined
type: integer
specificPerMemberCluster:
additionalProperties:
type: integer
description: Contains a map of specific capacity thresholds
(in percentage of usage) for particular member clusters
mapped by their names
type: object
x-kubernetes-map-type: atomic
type: object
type: object
deactivation:
description: Keeps parameters concerned with user deactivation
properties:
Expand Down
25 changes: 0 additions & 25 deletions controllers/toolchainconfig/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ func (c *ToolchainConfig) AutomaticApproval() AutoApprovalConfig {
return AutoApprovalConfig{c.cfg.Host.AutomaticApproval}
}

// Deprecated: This is no longer used for anything.
func (c *ToolchainConfig) CapacityThresholds() CapacityThresholdsConfig {
return CapacityThresholdsConfig{c.cfg.Host.CapacityThresholds}
}

func (c *ToolchainConfig) SpaceConfig() SpaceConfig {
return SpaceConfig{c.cfg.Host.SpaceConfig}
}
Expand Down Expand Up @@ -152,26 +147,6 @@ func (s SpaceConfig) SpaceBindingRequestIsEnabled() bool {
return commonconfig.GetBool(s.spaceConfig.SpaceBindingRequestEnabled, false)
}

// Deprecated: This is no longer used for anything.
type CapacityThresholdsConfig struct {
capacityThresholds toolchainv1alpha1.CapacityThresholds
}

// Deprecated: This is no longer used for anything.
func (c CapacityThresholdsConfig) MaxNumberOfSpacesSpecificPerMemberCluster() map[string]int {
return c.capacityThresholds.MaxNumberOfSpacesPerMemberCluster
}

// Deprecated: This is no longer used for anything.
func (c CapacityThresholdsConfig) ResourceCapacityThresholdDefault() int {
return commonconfig.GetInt(c.capacityThresholds.ResourceCapacityThreshold.DefaultThreshold, 80)
}

// Deprecated: This is no longer used for anything.
func (c CapacityThresholdsConfig) ResourceCapacityThresholdSpecificPerMemberCluster() map[string]int {
return c.capacityThresholds.ResourceCapacityThreshold.SpecificPerMemberCluster
}

type DeactivationConfig struct {
dctv toolchainv1alpha1.DeactivationConfig
}
Expand Down
19 changes: 0 additions & 19 deletions controllers/toolchainconfig/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,25 +249,6 @@ func TestAutomaticApprovalConfig(t *testing.T) {
})
}

func TestCapacityThresholdsConfig(t *testing.T) {
t.Run("default", func(t *testing.T) {
cfg := commonconfig.NewToolchainConfigObjWithReset(t)
toolchainCfg := newToolchainConfig(cfg, map[string]map[string]string{})

assert.Empty(t, toolchainCfg.CapacityThresholds().MaxNumberOfSpacesSpecificPerMemberCluster())
assert.Equal(t, 80, toolchainCfg.CapacityThresholds().ResourceCapacityThresholdDefault())
assert.Empty(t, toolchainCfg.CapacityThresholds().ResourceCapacityThresholdSpecificPerMemberCluster())
})
t.Run("non-default", func(t *testing.T) {
cfg := commonconfig.NewToolchainConfigObjWithReset(t, testconfig.CapacityThresholds().MaxNumberOfSpaces(testconfig.PerMemberCluster("member1", 321)).ResourceCapacityThreshold(456, testconfig.PerMemberCluster("member1", 654))) //nolint:staticcheck // this will be removed once we also remove the deprecated method
toolchainCfg := newToolchainConfig(cfg, map[string]map[string]string{})

assert.Equal(t, cfg.Spec.Host.CapacityThresholds.MaxNumberOfSpacesPerMemberCluster, toolchainCfg.CapacityThresholds().MaxNumberOfSpacesSpecificPerMemberCluster())
assert.Equal(t, 456, toolchainCfg.CapacityThresholds().ResourceCapacityThresholdDefault())
assert.Equal(t, cfg.Spec.Host.CapacityThresholds.ResourceCapacityThreshold.SpecificPerMemberCluster, toolchainCfg.CapacityThresholds().ResourceCapacityThresholdSpecificPerMemberCluster())
})
}

func TestDeactivationConfig(t *testing.T) {
t.Run("default", func(t *testing.T) {
cfg := commonconfig.NewToolchainConfigObjWithReset(t)
Expand Down
28 changes: 3 additions & 25 deletions controllers/toolchainconfig/toolchainconfig_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ func TestReconcile(t *testing.T) {
t.Run("config exists", func(t *testing.T) {
config := commonconfig.NewToolchainConfigObjWithReset(t,
testconfig.AutomaticApproval().Enabled(true),
testconfig.CapacityThresholds().MaxNumberOfSpaces(testconfig.PerMemberCluster("member1", 321)), //nolint:staticcheck // this will be removed once we also remove the deprecated method
testconfig.Members().Default(defaultMemberConfig.Spec),
testconfig.Members().SpecificPerMemberCluster("member1", specificMemberConfig.Spec))
hostCl := test.NewFakeClient(t, config)
Expand All @@ -83,7 +82,6 @@ func TestReconcile(t *testing.T) {
actual, err := toolchainconfig.GetToolchainConfig(hostCl)
require.NoError(t, err)
assert.True(t, actual.AutomaticApproval().IsEnabled())
assert.Equal(t, config.Spec.Host.CapacityThresholds.MaxNumberOfSpacesPerMemberCluster, actual.CapacityThresholds().MaxNumberOfSpacesSpecificPerMemberCluster())
testconfig.AssertThatToolchainConfig(t, test.HostOperatorNs, hostCl).
Exists().
HasConditions(
Expand All @@ -105,8 +103,6 @@ func TestReconcile(t *testing.T) {
// given
err := hostCl.Get(context.TODO(), types.NamespacedName{Name: config.Name, Namespace: config.Namespace}, config)
require.NoError(t, err)
threshold := 100
config.Spec.Host.CapacityThresholds.ResourceCapacityThreshold.DefaultThreshold = &threshold
newRefreshPeriod := "20s"
config.Spec.Members.Default.MemberStatus.RefreshPeriod = &newRefreshPeriod
err = hostCl.Update(context.TODO(), config)
Expand All @@ -121,8 +117,6 @@ func TestReconcile(t *testing.T) {
actual, err := toolchainconfig.GetToolchainConfig(hostCl)
require.NoError(t, err)
assert.True(t, actual.AutomaticApproval().IsEnabled())
assert.Equal(t, config.Spec.Host.CapacityThresholds.MaxNumberOfSpacesPerMemberCluster, actual.CapacityThresholds().MaxNumberOfSpacesSpecificPerMemberCluster())
assert.Equal(t, 100, actual.CapacityThresholds().ResourceCapacityThresholdDefault())
testconfig.AssertThatToolchainConfig(t, test.HostOperatorNs, hostCl).
Exists().
HasConditions(
Expand All @@ -145,8 +139,6 @@ func TestReconcile(t *testing.T) {
// given
err := hostCl.Get(context.TODO(), types.NamespacedName{Name: config.Name, Namespace: config.Namespace}, config)
require.NoError(t, err)
threshold := 100
config.Spec.Host.CapacityThresholds.ResourceCapacityThreshold.DefaultThreshold = &threshold
err = hostCl.Update(context.TODO(), config)
require.NoError(t, err)
hostCl.MockGet = func(ctx context.Context, key types.NamespacedName, obj runtimeclient.Object, opts ...runtimeclient.GetOption) error {
Expand All @@ -162,8 +154,6 @@ func TestReconcile(t *testing.T) {
actual, err := toolchainconfig.GetToolchainConfig(hostCl)
require.NoError(t, err)
assert.True(t, actual.AutomaticApproval().IsEnabled())
assert.Equal(t, config.Spec.Host.CapacityThresholds.MaxNumberOfSpacesPerMemberCluster, actual.CapacityThresholds().MaxNumberOfSpacesSpecificPerMemberCluster())
assert.Equal(t, 100, actual.CapacityThresholds().ResourceCapacityThresholdDefault())

// check member1 config is unchanged
member1Cfg, err := getMemberConfig(member1)
Expand All @@ -183,7 +173,6 @@ func TestReconcile(t *testing.T) {
// given
config := commonconfig.NewToolchainConfigObjWithReset(t,
testconfig.AutomaticApproval().Enabled(true),
testconfig.CapacityThresholds().MaxNumberOfSpaces(testconfig.PerMemberCluster("member1", 321)), //nolint:staticcheck // this will be removed once we also remove the deprecated method
testconfig.Members().Default(defaultMemberConfig.Spec),
testconfig.Members().SpecificPerMemberCluster("member1", specificMemberConfig.Spec))
hostCl := test.NewFakeClient(t, config)
Expand Down Expand Up @@ -212,7 +201,6 @@ func TestReconcile(t *testing.T) {
// given
config := commonconfig.NewToolchainConfigObjWithReset(t,
testconfig.AutomaticApproval().Enabled(true),
testconfig.CapacityThresholds().MaxNumberOfSpaces(testconfig.PerMemberCluster("member1", 321)), //nolint:staticcheck // this will be removed once we also remove the deprecated method
testconfig.Members().Default(defaultMemberConfig.Spec),
testconfig.Members().SpecificPerMemberCluster("member1", specificMemberConfig.Spec))
hostCl := test.NewFakeClient(t, config)
Expand Down Expand Up @@ -243,8 +231,7 @@ func TestReconcile(t *testing.T) {
t.Run("reg service deploy failed", func(t *testing.T) {
// given
config := commonconfig.NewToolchainConfigObjWithReset(t,
testconfig.AutomaticApproval().Enabled(true),
testconfig.CapacityThresholds().MaxNumberOfSpaces(testconfig.PerMemberCluster("member1", 321))) //nolint:staticcheck // this will be removed once we also remove the deprecated method
testconfig.AutomaticApproval().Enabled(true))
hostCl := test.NewFakeClient(t, config)
hostCl.MockCreate = func(ctx context.Context, obj runtimeclient.Object, opts ...runtimeclient.CreateOption) error {
return fmt.Errorf("create error")
Expand All @@ -260,8 +247,6 @@ func TestReconcile(t *testing.T) {
actual, err := toolchainconfig.GetToolchainConfig(hostCl)
require.NoError(t, err)
assert.True(t, actual.AutomaticApproval().IsEnabled())
assert.Equal(t, config.Spec.Host.CapacityThresholds.MaxNumberOfSpacesPerMemberCluster, actual.CapacityThresholds().MaxNumberOfSpacesSpecificPerMemberCluster())
assert.Equal(t, 80, actual.CapacityThresholds().ResourceCapacityThresholdDefault())
testconfig.AssertThatToolchainConfig(t, test.HostOperatorNs, hostCl).
Exists().
HasConditions(
Expand All @@ -271,8 +256,7 @@ func TestReconcile(t *testing.T) {

t.Run("sync failed", func(t *testing.T) {
// given
config := commonconfig.NewToolchainConfigObjWithReset(t, testconfig.AutomaticApproval().Enabled(true), testconfig.Members().Default(defaultMemberConfig.Spec), testconfig.Members().SpecificPerMemberCluster("missing-member", specificMemberConfig.Spec),
testconfig.CapacityThresholds().MaxNumberOfSpaces(testconfig.PerMemberCluster("member1", 321))) //nolint:staticcheck // this will be removed once we also remove the deprecated method
config := commonconfig.NewToolchainConfigObjWithReset(t, testconfig.AutomaticApproval().Enabled(true), testconfig.Members().Default(defaultMemberConfig.Spec), testconfig.Members().SpecificPerMemberCluster("missing-member", specificMemberConfig.Spec))
hostCl := test.NewFakeClient(t, config)
members := NewGetMemberClusters(NewMemberClusterWithTenantRole(t, "member1", corev1.ConditionTrue), NewMemberClusterWithTenantRole(t, "member2", corev1.ConditionTrue))
controller := newController(t, hostCl, members)
Expand All @@ -286,8 +270,6 @@ func TestReconcile(t *testing.T) {
actual, err := toolchainconfig.GetToolchainConfig(hostCl)
require.NoError(t, err)
assert.True(t, actual.AutomaticApproval().IsEnabled())
assert.Equal(t, config.Spec.Host.CapacityThresholds.MaxNumberOfSpacesPerMemberCluster, actual.CapacityThresholds().MaxNumberOfSpacesSpecificPerMemberCluster())
assert.Equal(t, 80, actual.CapacityThresholds().ResourceCapacityThresholdDefault())
testconfig.AssertThatToolchainConfig(t, test.HostOperatorNs, hostCl).
Exists().
HasConditions(
Expand All @@ -300,8 +282,7 @@ func TestReconcile(t *testing.T) {

func TestWrapErrorWithUpdateStatus(t *testing.T) {
// given
config := commonconfig.NewToolchainConfigObjWithReset(t, testconfig.AutomaticApproval().Enabled(true),
testconfig.CapacityThresholds().MaxNumberOfSpaces(testconfig.PerMemberCluster("member1", 321))) //nolint:staticcheck // this will be removed once we also remove the deprecated method
config := commonconfig.NewToolchainConfigObjWithReset(t, testconfig.AutomaticApproval().Enabled(true))
hostCl := test.NewFakeClient(t, config)
members := NewGetMemberClusters(NewMemberClusterWithTenantRole(t, "member1", corev1.ConditionTrue), NewMemberClusterWithTenantRole(t, "member2", corev1.ConditionTrue))
controller := newController(t, hostCl, members)
Expand Down Expand Up @@ -353,9 +334,6 @@ func newRequest() reconcile.Request {

func matchesDefaultConfig(t *testing.T, actual toolchainconfig.ToolchainConfig) {
assert.False(t, actual.AutomaticApproval().IsEnabled())
assert.Empty(t, actual.CapacityThresholds().MaxNumberOfSpacesSpecificPerMemberCluster())
assert.Equal(t, 80, actual.CapacityThresholds().ResourceCapacityThresholdDefault())
assert.Empty(t, actual.CapacityThresholds().ResourceCapacityThresholdSpecificPerMemberCluster())
assert.Equal(t, 3, actual.Deactivation().DeactivatingNotificationDays())
}

Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
module github.com/codeready-toolchain/host-operator

replace (
github.com/codeready-toolchain/api => github.com/metlos/api v0.0.0-20240326131121-9509925cdd79
github.com/codeready-toolchain/toolchain-common => github.com/metlos/toolchain-common v0.0.0-20240408103238-edb68ec6cfa8
)

require (
github.com/codeready-toolchain/api v0.0.0-20240322110702-5ab3840476e9
github.com/codeready-toolchain/toolchain-common v0.0.0-20240404090512-046d250d7d78
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ github.com/cncf/xds/go v0.0.0-20210312221358-fbca930ec8ed/go.mod h1:eXthEFrGJvWH
github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h6jFvWxBdQXxjopDMZyH2UVceIRfR84bdzbkoKrsWNo=
github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA=
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
github.com/codeready-toolchain/api v0.0.0-20240322110702-5ab3840476e9 h1:Lm7bFLrzfJzrUiRGVqtsSaZMpj+akLiR/fvAFjjE9gM=
github.com/codeready-toolchain/api v0.0.0-20240322110702-5ab3840476e9/go.mod h1:cfNN6YPX4TORvhhZXMSjSPesqAHlB3nD/WAfGe4WLKQ=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240404090512-046d250d7d78 h1:4jFHu6xN/T+hml9egbiZyJmptrMO0azWfF94liICmrM=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240404090512-046d250d7d78/go.mod h1:OJ3L9aaTRMGjxr2WeH/9l6m5OjExwEK3Bp/+P+efoGg=
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
Expand Down Expand Up @@ -438,6 +434,10 @@ github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 h1:I0XW9+e1XWDxdcEniV4rQAIOPUGDq67JSCiRCgGCZLI=
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/metlos/api v0.0.0-20240326131121-9509925cdd79 h1:CK470udH8w1HRieGKequ1kw1iMCugAAWKyRUFV/58WE=
github.com/metlos/api v0.0.0-20240326131121-9509925cdd79/go.mod h1:cfNN6YPX4TORvhhZXMSjSPesqAHlB3nD/WAfGe4WLKQ=
github.com/metlos/toolchain-common v0.0.0-20240408103238-edb68ec6cfa8 h1:IJDBYEM7vpw/VpRyMhGMrjaPEljyemBHOUUHVmaY/us=
github.com/metlos/toolchain-common v0.0.0-20240408103238-edb68ec6cfa8/go.mod h1:YciFg9BSk48nYeoc/xVHRZ0T0lT+cS5OwTrMHdeyArA=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/migueleliasweb/go-github-mock v0.0.18 h1:0lWt9MYmZQGnQE2rFtjlft/YtD6hzxuN6JJRFpujzEI=
github.com/migueleliasweb/go-github-mock v0.0.18/go.mod h1:CcgXcbMoRnf3rRVHqGssuBquZDIcaplxL2W6G+xs7kM=
Expand Down
Loading