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

[d8] Add d8 module options #80

Merged
merged 23 commits into from
Jan 29, 2025
Merged
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ require (
k8s.io/component-base v0.29.3
k8s.io/klog/v2 v2.120.1
k8s.io/kubectl v0.29.3
k8s.io/utils v0.0.0-20240310230437-4693a0247e57
sigs.k8s.io/yaml v1.4.0
)

Expand Down Expand Up @@ -562,7 +563,6 @@ require (
k8s.io/klog v1.0.0 // indirect
k8s.io/kube-openapi v0.0.0-20240105020646-a37d4de58910 // indirect
k8s.io/metrics v0.29.3 // indirect
k8s.io/utils v0.0.0-20240310230437-4693a0247e57 // indirect
kubevirt.io/api v1.2.0 // indirect
kubevirt.io/containerized-data-importer-api v1.57.0-alpha1 // indirect
kubevirt.io/controller-lifecycle-operator-sdk/api v0.0.0-20220329064328-f3cc58c6ed90 // indirect
Expand Down
3 changes: 1 addition & 2 deletions internal/platform/cmd/edit/editconfig/editconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ func BaseEditConfigCMD(cmd *cobra.Command, name, secret, dataKey string) error {

encodedValue, err := encodeSecretTmp(updatedContent, dataKey)
_, err = kubeCl.CoreV1().
Secrets("kube-system").
Patch(context.TODO(), secret, types.MergePatchType, encodedValue, metav1.PatchOptions{})
Secrets("kube-system").Patch(context.TODO(), secret, types.MergePatchType, encodedValue, metav1.PatchOptions{})
if err != nil {
return fmt.Errorf("Error updating secret: %w", err)
}
Expand Down
69 changes: 69 additions & 0 deletions internal/platform/cmd/module/disable/disable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
Copyright 2025 Flant JSC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package disable

import (
"fmt"
"github.com/deckhouse/deckhouse-cli/internal/platform/cmd/module/operatemodule"
"github.com/deckhouse/deckhouse-cli/internal/utilk8s"
"k8s.io/client-go/dynamic"

"github.com/deckhouse/deckhouse-cli/internal/platform/cmd/edit/flags"
"github.com/spf13/cobra"
"k8s.io/kubectl/pkg/util/templates"
)

var disableLong = templates.LongDesc(`
Disable module using the ModuleConfig resource.

© Flant JSC 2025`)

func NewCommand() *cobra.Command {
disableCmd := &cobra.Command{
Use: "disable",
Short: "Disable module.",
Long: disableLong,
ValidArgs: []string{"module_name"},
SilenceErrors: true,
SilenceUsage: true,
RunE: disableModule,
}
flags.AddFlags(disableCmd.Flags())
return disableCmd
}

func disableModule(cmd *cobra.Command, moduleName []string) error {
kubeconfigPath, err := cmd.Flags().GetString("kubeconfig")
if err != nil {
return fmt.Errorf("Failed to setup Kubernetes client: %w", err)
}

config, _, err := utilk8s.SetupK8sClientSet(kubeconfigPath)
if err != nil {
return fmt.Errorf("Failed to setup Kubernetes client: %w", err)
}
dynamicClient, err := dynamic.NewForConfig(config)
if err != nil {
return fmt.Errorf("Failed to create dynamic client: %v", err)
}
err = operatemodule.OperateModule(dynamicClient, moduleName[0], operatemodule.ModuleDisabled)
if err != nil {
return fmt.Errorf("Error disable module: %w", err)
}
fmt.Printf("Module %s disabled\n", moduleName[0])
return err
}
70 changes: 70 additions & 0 deletions internal/platform/cmd/module/enable/enable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
Copyright 2025 Flant JSC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package enable

import (
"fmt"
"github.com/deckhouse/deckhouse-cli/internal/platform/cmd/module/operatemodule"
"github.com/deckhouse/deckhouse-cli/internal/utilk8s"
"k8s.io/client-go/dynamic"

"github.com/deckhouse/deckhouse-cli/internal/platform/cmd/edit/flags"
"github.com/spf13/cobra"
"k8s.io/kubectl/pkg/util/templates"
)

var enableLong = templates.LongDesc(`
Enable module using the ModuleConfig resource.

© Flant JSC 2025`)

func NewCommand() *cobra.Command {
enableCmd := &cobra.Command{
Use: "enable",
Short: "Enable module.",
Long: enableLong,
ValidArgs: []string{"module_name"},
SilenceErrors: true,
SilenceUsage: true,
RunE: enableModule,
}
flags.AddFlags(enableCmd.Flags())
return enableCmd
}

func enableModule(cmd *cobra.Command, moduleName []string) error {
kubeconfigPath, err := cmd.Flags().GetString("kubeconfig")
if err != nil {
return fmt.Errorf("Failed to setup Kubernetes client: %w", err)
}

config, _, err := utilk8s.SetupK8sClientSet(kubeconfigPath)
if err != nil {
return fmt.Errorf("Failed to setup Kubernetes client: %w", err)
}

dynamicClient, err := dynamic.NewForConfig(config)
if err != nil {
return fmt.Errorf("Failed to create dynamic client: %v", err)
}
err = operatemodule.OperateModule(dynamicClient, moduleName[0], operatemodule.ModuleEnabled)
if err != nil {
return fmt.Errorf("Error enable module: %w", err)
}
fmt.Printf("Module %s enabled\n", moduleName[0])
return err
}
29 changes: 29 additions & 0 deletions internal/platform/cmd/module/flags/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2025 Flant JSC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package flags

import (
"github.com/spf13/pflag"
)

func AddFlags(flagSet *pflag.FlagSet) {
flagSet.StringP(
"editor", "e",
"vi",
"Your favourite editor.",
)
}
63 changes: 63 additions & 0 deletions internal/platform/cmd/module/list/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright 2025 Flant JSC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package list

import (
"fmt"
"github.com/deckhouse/deckhouse-cli/internal/platform/cmd/module/operatemodule"
"github.com/deckhouse/deckhouse-cli/internal/utilk8s"

"github.com/deckhouse/deckhouse-cli/internal/platform/cmd/edit/flags"
"github.com/spf13/cobra"
"k8s.io/kubectl/pkg/util/templates"
)

var listLong = templates.LongDesc(`
List enabled Deckhouse Kubernetes Platform modules.

© Flant JSC 2025`)

func NewCommand() *cobra.Command {
listCmd := &cobra.Command{
Use: "list",
Short: "List enabled modules.",
Long: listLong,
SilenceErrors: true,
SilenceUsage: true,
RunE: listModule,
}
flags.AddFlags(listCmd.Flags())
return listCmd
}

func listModule(cmd *cobra.Command, args []string) error {
kubeconfigPath, err := cmd.Flags().GetString("kubeconfig")
if err != nil {
return fmt.Errorf("Failed to setup Kubernetes client: %w", err)
}

config, kubeCl, err := utilk8s.SetupK8sClientSet(kubeconfigPath)
if err != nil {
return fmt.Errorf("Failed to setup Kubernetes client: %w", err)
}

err = operatemodule.OptionsModule(config, kubeCl, "list.yaml")
if err != nil {
return fmt.Errorf("Error list modules: %w", err)
}
return err
}
53 changes: 53 additions & 0 deletions internal/platform/cmd/module/module.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2025 Flant JSC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package module

import (
"github.com/deckhouse/deckhouse-cli/internal/platform/cmd/module/enable"
"github.com/deckhouse/deckhouse-cli/internal/platform/cmd/module/list"
"github.com/deckhouse/deckhouse-cli/internal/platform/cmd/module/snapshots"
"github.com/deckhouse/deckhouse-cli/internal/platform/cmd/module/values"
"github.com/spf13/cobra"
"k8s.io/kubectl/pkg/util/templates"

"github.com/deckhouse/deckhouse-cli/internal/platform/cmd/module/disable"
"github.com/deckhouse/deckhouse-cli/internal/platform/cmd/module/flags"
)

var moduleLong = templates.LongDesc(`
Operate the Deckhouse Kubernetes Platform modules.

© Flant JSC 2025`)

func NewCommand() *cobra.Command {
moduleCmd := &cobra.Command{
Use: "module", Short: "Operate the Deckhouse Kubernetes Platform modules",
Long: moduleLong,
}

moduleCmd.AddCommand(
enable.NewCommand(),
disable.NewCommand(),
list.NewCommand(),
values.NewCommand(),
snapshots.NewCommand(),
)

flags.AddFlags(moduleCmd.Flags())

return moduleCmd
}
Loading