Skip to content

Commit

Permalink
[release/v2.23] Fix switch for sharing cluster (#6353)
Browse files Browse the repository at this point in the history
* Itroduce bool pointer

* Bump KKP version

* Fix import order
  • Loading branch information
pkprzekwas committed Oct 31, 2023
1 parent a0583ba commit fcb57ac
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions modules/api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ require (
gopkg.in/square/go-jose.v2 v2.6.0
gopkg.in/yaml.v3 v3.0.1
k8c.io/kubeone v1.6.2
k8c.io/kubermatic/v2 v2.23.6-0.20231023131608-052c6062c1a0
k8c.io/kubermatic/v2 v2.23.7-0.20231030143014-f8c952898118
k8c.io/operating-system-manager v1.3.3
k8c.io/reconciler v0.3.1
k8s.io/api v0.26.4
Expand Down Expand Up @@ -102,7 +102,7 @@ replace (

replace (
github.com/ajeddeloh/go-json => github.com/coreos/go-json v0.0.0-20220810161552-7cce03887f34
k8c.io/kubermatic/v2 => k8c.io/kubermatic/v2 v2.23.6-0.20231023131608-052c6062c1a0
k8c.io/kubermatic/v2 => k8c.io/kubermatic/v2 v2.23.7-0.20231030143014-f8c952898118
)

require (
Expand Down
4 changes: 2 additions & 2 deletions modules/api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1367,8 +1367,8 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
k8c.io/kubeone v1.6.2 h1:3oEvD90kENhYzvvmSrMNjUam2fq7UMMKVp/Py57xs6M=
k8c.io/kubeone v1.6.2/go.mod h1:5U/6sUZAkAl7uvC+VIDIA0VBZMBbFI9QD1C90kxb4qA=
k8c.io/kubermatic/v2 v2.23.6-0.20231023131608-052c6062c1a0 h1:IYHkXX/ZXWbyxAQxq4t8LbhHmdSaS3Q5Fy2C1eJrUx8=
k8c.io/kubermatic/v2 v2.23.6-0.20231023131608-052c6062c1a0/go.mod h1:1HTLurvUZGrQSkXEKmqb0tBhxPDJoSyc0VHRpKZ/E+0=
k8c.io/kubermatic/v2 v2.23.7-0.20231030143014-f8c952898118 h1:aQ8CETAUet/SbSZieNhhoTUFxB+DpkFAjMT9pjCoFD8=
k8c.io/kubermatic/v2 v2.23.7-0.20231030143014-f8c952898118/go.mod h1:1HTLurvUZGrQSkXEKmqb0tBhxPDJoSyc0VHRpKZ/E+0=
k8c.io/operating-system-manager v1.3.3 h1:8E58WGz+67+dDYuvAZu0QRRkslkWa4vMrbseQeRWceA=
k8c.io/operating-system-manager v1.3.3/go.mod h1:kKDzXLWrC5BLpDbgXQFRpTVa5Fjru2S3ylxX5hZMRKA=
k8c.io/reconciler v0.3.1 h1:fZ8gFvrDxjsJ6jdKogZVX9Er980EDUYnVPuOna32d0k=
Expand Down
4 changes: 0 additions & 4 deletions modules/api/pkg/api/v2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2027,13 +2027,9 @@ type GlobalSettings struct {
// EnableDashboard enables the link to the Kubernetes dashboard for a user cluster.
EnableDashboard bool `json:"enableDashboard"`

// +kubebuilder:default=false

// EnableWebTerminal enables the Web Terminal feature for the user clusters.
EnableWebTerminal bool `json:"enableWebTerminal,omitempty"`

// +kubebuilder:default=false

// EnableShareCluster enables the Share Cluster feature for the user clusters.
EnableShareCluster bool `json:"enableShareCluster,omitempty"`

Expand Down
2 changes: 1 addition & 1 deletion modules/api/pkg/handler/test/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ func GenDefaultSettings() *kubermaticv1.KubermaticSetting {
DisplayTermsOfService: false,
EnableDashboard: true,
EnableWebTerminal: false,
EnableShareCluster: false,
EnableShareCluster: pointer.Bool(false),
EnableOIDCKubeconfig: false,
},
}
Expand Down
10 changes: 8 additions & 2 deletions modules/api/pkg/handler/v1/admin/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"k8c.io/dashboard/v2/pkg/provider"
kubermaticv1 "k8c.io/kubermatic/v2/pkg/apis/kubermatic/v1"
utilerrors "k8c.io/kubermatic/v2/pkg/util/errors"

"k8s.io/utils/pointer"
)

// KubermaticSettingsEndpoint returns global settings.
Expand Down Expand Up @@ -127,7 +129,7 @@ func convertAPISettingsToSettingsSpec(settings *apiv2.GlobalSettings) (kubermati
DisplayTermsOfService: settings.DisplayTermsOfService,
EnableDashboard: settings.EnableDashboard,
EnableWebTerminal: settings.EnableWebTerminal,
EnableShareCluster: settings.EnableShareCluster,
EnableShareCluster: pointer.Bool(settings.EnableShareCluster),
EnableOIDCKubeconfig: settings.EnableOIDCKubeconfig,
DisableAdminKubeconfig: settings.DisableAdminKubeconfig,
UserProjectsLimit: settings.UserProjectsLimit,
Expand Down Expand Up @@ -158,6 +160,10 @@ func convertAPISettingsToSettingsSpec(settings *apiv2.GlobalSettings) (kubermati
}

func ConvertCRDSettingsToAPISettingsSpec(settings *kubermaticv1.SettingSpec) apiv2.GlobalSettings {
enableShareCluster := true
if settings.EnableShareCluster != nil {
enableShareCluster = *settings.EnableShareCluster
}
s := apiv2.GlobalSettings{
CustomLinks: settings.CustomLinks,
DefaultNodeCount: settings.DefaultNodeCount,
Expand All @@ -166,7 +172,7 @@ func ConvertCRDSettingsToAPISettingsSpec(settings *kubermaticv1.SettingSpec) api
DisplayTermsOfService: settings.DisplayTermsOfService,
EnableDashboard: settings.EnableDashboard,
EnableWebTerminal: settings.EnableWebTerminal,
EnableShareCluster: settings.EnableShareCluster,
EnableShareCluster: enableShareCluster,
EnableOIDCKubeconfig: settings.EnableOIDCKubeconfig,
DisableAdminKubeconfig: settings.DisableAdminKubeconfig,
UserProjectsLimit: settings.UserProjectsLimit,
Expand Down
4 changes: 2 additions & 2 deletions modules/api/pkg/handler/v1/admin/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestGetGlobalSettings(t *testing.T) {
// scenario 2
{
name: "scenario 2: user gets existing global settings",
expectedResponse: `{"customLinks":[{"label":"label","url":"url:label","icon":"icon","location":"EU"}],"defaultNodeCount":5,"displayDemoInfo":true,"displayAPIDocs":true,"displayTermsOfService":true,"enableDashboard":false,"enableOIDCKubeconfig":false,"userProjectsLimit":0,"restrictProjectCreation":false,"restrictProjectDeletion":false,"enableExternalClusterImport":true,"cleanupOptions":{"enabled":true,"enforced":true},"opaOptions":{"enabled":true,"enforced":true},"mlaOptions":{"loggingEnabled":true,"loggingEnforced":true,"monitoringEnabled":true,"monitoringEnforced":true},"mlaAlertmanagerPrefix":"","mlaGrafanaPrefix":"","notifications":{},"providerConfiguration":{"openStack":{}},"defaultQuota":{"quota":{"cpu":2,"memory":5,"storage":10}},"machineDeploymentOptions":{}}`,
expectedResponse: `{"customLinks":[{"label":"label","url":"url:label","icon":"icon","location":"EU"}],"defaultNodeCount":5,"displayDemoInfo":true,"displayAPIDocs":true,"displayTermsOfService":true,"enableDashboard":false,"enableShareCluster":true,"enableOIDCKubeconfig":false,"userProjectsLimit":0,"restrictProjectCreation":false,"restrictProjectDeletion":false,"enableExternalClusterImport":true,"cleanupOptions":{"enabled":true,"enforced":true},"opaOptions":{"enabled":true,"enforced":true},"mlaOptions":{"loggingEnabled":true,"loggingEnforced":true,"monitoringEnabled":true,"monitoringEnforced":true},"mlaAlertmanagerPrefix":"","mlaGrafanaPrefix":"","notifications":{},"providerConfiguration":{"openStack":{}},"defaultQuota":{"quota":{"cpu":2,"memory":5,"storage":10}},"machineDeploymentOptions":{}}`,
httpStatus: http.StatusOK,
existingKubermaticObjs: []ctrlruntimeclient.Object{genUser("Bob", "bob@acme.com", true),
test.GenDefaultGlobalSettings()},
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestUpdateGlobalSettings(t *testing.T) {
{
name: "scenario 3: authorized user updates existing global settings",
body: `{"customLinks":[],"cleanupOptions":{"enabled":true,"enforced":true},"defaultNodeCount":100,"displayDemoInfo":false,"displayAPIDocs":false,"displayTermsOfService":true,"userProjectsLimit":10,"restrictProjectCreation":true,"restrictProjectDeletion":false,"defaultQuota":{"cpu":4,"storage":12},"machineDeploymentOptions":{}}`,
expectedResponse: `{"customLinks":[],"defaultNodeCount":100,"displayDemoInfo":false,"displayAPIDocs":false,"displayTermsOfService":true,"enableDashboard":false,"enableOIDCKubeconfig":false,"userProjectsLimit":10,"restrictProjectCreation":true,"restrictProjectDeletion":false,"enableExternalClusterImport":true,"cleanupOptions":{"enabled":true,"enforced":true},"opaOptions":{"enabled":true,"enforced":true},"mlaOptions":{"loggingEnabled":true,"loggingEnforced":true,"monitoringEnabled":true,"monitoringEnforced":true},"mlaAlertmanagerPrefix":"","mlaGrafanaPrefix":"","notifications":{},"providerConfiguration":{"openStack":{}},"defaultQuota":{"quota":{"cpu":2,"memory":5,"storage":10}},"machineDeploymentOptions":{}}`,
expectedResponse: `{"customLinks":[],"defaultNodeCount":100,"displayDemoInfo":false,"displayAPIDocs":false,"displayTermsOfService":true,"enableDashboard":false,"enableShareCluster":true,"enableOIDCKubeconfig":false,"userProjectsLimit":10,"restrictProjectCreation":true,"restrictProjectDeletion":false,"enableExternalClusterImport":true,"cleanupOptions":{"enabled":true,"enforced":true},"opaOptions":{"enabled":true,"enforced":true},"mlaOptions":{"loggingEnabled":true,"loggingEnforced":true,"monitoringEnabled":true,"monitoringEnforced":true},"mlaAlertmanagerPrefix":"","mlaGrafanaPrefix":"","notifications":{},"providerConfiguration":{"openStack":{}},"defaultQuota":{"quota":{"cpu":2,"memory":5,"storage":10}},"machineDeploymentOptions":{}}`,
httpStatus: http.StatusOK,
existingKubermaticObjs: []ctrlruntimeclient.Object{genUser("Bob", "bob@acme.com", true),
test.GenDefaultGlobalSettings()},
Expand Down
3 changes: 2 additions & 1 deletion modules/api/pkg/provider/kubernetes/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/utils/pointer"
ctrlruntimeclient "sigs.k8s.io/controller-runtime/pkg/client"
)

Expand Down Expand Up @@ -82,7 +83,7 @@ func (s *SettingsProvider) createDefaultGlobalSettings(ctx context.Context) (*ku
DisplayTermsOfService: false,
EnableDashboard: true,
EnableWebTerminal: false,
EnableShareCluster: false,
EnableShareCluster: pointer.Bool(false),
EnableOIDCKubeconfig: false,
UserProjectsLimit: 0,
RestrictProjectCreation: false,
Expand Down
2 changes: 1 addition & 1 deletion modules/api/pkg/test/e2e/api/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestGetDefaultGlobalSettings(t *testing.T) {
DisplayTermsOfService: false,
EnableDashboard: true,
EnableWebTerminal: false,
EnableShareCluster: true,
EnableShareCluster: false,
EnableOIDCKubeconfig: false,
UserProjectsLimit: 0,
RestrictProjectCreation: false,
Expand Down

0 comments on commit fcb57ac

Please sign in to comment.