-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #80 from deckhouse/feature/d8-module-options
[d8] Add d8 module options
- Loading branch information
Showing
14 changed files
with
688 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.", | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.