Skip to content

Commit

Permalink
Merge branch 'master' into hares-large-tier-pvc
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeykazakov authored Apr 24, 2024
2 parents 4a7f12b + d1e027d commit d74e9e3
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 106 deletions.
31 changes: 0 additions & 31 deletions config/crd/bases/toolchain.dev.openshift.com_toolchainconfigs.yaml
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/codeready-toolchain/host-operator

require (
github.com/codeready-toolchain/api v0.0.0-20240322110702-5ab3840476e9
github.com/codeready-toolchain/toolchain-common v0.0.0-20240422084400-e6d41ea74313
github.com/codeready-toolchain/api v0.0.0-20240424103940-03edc96d88fb
github.com/codeready-toolchain/toolchain-common v0.0.0-20240424171146-581ea6502cad
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-bindata/go-bindata v3.1.2+incompatible
github.com/go-logr/logr v1.2.3
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,10 @@ 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-20240422084400-e6d41ea74313 h1:UuLjLbn8Rh1QX8jyLipAtaZ3o25Ard33B2+DCcmJLsQ=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240422084400-e6d41ea74313/go.mod h1:rfVQhC9ctteNi2vbg300fgD0zgTfk/h3qjW9nsCayFs=
github.com/codeready-toolchain/api v0.0.0-20240424103940-03edc96d88fb h1:YvEVAetaNYLAyuwO8AmKTtWD9M7SZPhbBzTVMXhrGas=
github.com/codeready-toolchain/api v0.0.0-20240424103940-03edc96d88fb/go.mod h1:ie9p4LenCCS0LsnbWp6/xwpFDdCWYE0KWzUO6Sk1g0E=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240424171146-581ea6502cad h1:ka0mIrFO8+0H4uIgfhgCGh1lmRjGndRUYNEEV8O7fkQ=
github.com/codeready-toolchain/toolchain-common v0.0.0-20240424171146-581ea6502cad/go.mod h1:4BqdcAO16K/+YmPbn5XmTKOU4UUyuQPlge7ms9F1NsU=
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

0 comments on commit d74e9e3

Please sign in to comment.