-
Notifications
You must be signed in to change notification settings - Fork 566
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 #2267 from will4j/feature/addons-enhance
Feature/cluster addons enhancement
- Loading branch information
Showing
10 changed files
with
227 additions
and
10 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,49 @@ | ||
package phase | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/kubesphere/kubekey/v3/cmd/kk/cmd/options" | ||
"github.com/kubesphere/kubekey/v3/cmd/kk/cmd/util" | ||
"github.com/kubesphere/kubekey/v3/cmd/kk/pkg/common" | ||
"github.com/kubesphere/kubekey/v3/cmd/kk/pkg/phase/addons" | ||
) | ||
|
||
type ApplyAddonsOptions struct { | ||
CommonOptions *options.CommonOptions | ||
ClusterCfgFile string | ||
} | ||
|
||
func NewApplyAddonsOptions() *ApplyAddonsOptions { | ||
return &ApplyAddonsOptions{ | ||
CommonOptions: options.NewCommonOptions(), | ||
} | ||
} | ||
|
||
func NewCmdApplyAddons() *cobra.Command { | ||
o := NewApplyAddonsOptions() | ||
cmd := &cobra.Command{ | ||
Use: "addons", | ||
Short: "Apply cluster addons", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
util.CheckErr(o.Run(args)) | ||
}, | ||
} | ||
|
||
o.CommonOptions.AddCommonFlag(cmd) | ||
o.AddFlags(cmd) | ||
return cmd | ||
} | ||
|
||
func (o *ApplyAddonsOptions) Run(args []string) error { | ||
arg := common.Argument{ | ||
FilePath: o.ClusterCfgFile, | ||
Debug: o.CommonOptions.Verbose, | ||
EnabledAddons: args, | ||
} | ||
return addons.ApplyClusterAddons(arg) | ||
} | ||
|
||
func (o *ApplyAddonsOptions) AddFlags(cmd *cobra.Command) { | ||
cmd.Flags().StringVarP(&o.ClusterCfgFile, "filename", "f", "", "Path to a configuration file") | ||
} |
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
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,57 @@ | ||
package addons | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
|
||
"github.com/kubesphere/kubekey/v3/cmd/kk/pkg/addons" | ||
"github.com/kubesphere/kubekey/v3/cmd/kk/pkg/bootstrap/precheck" | ||
"github.com/kubesphere/kubekey/v3/cmd/kk/pkg/common" | ||
"github.com/kubesphere/kubekey/v3/cmd/kk/pkg/core/module" | ||
"github.com/kubesphere/kubekey/v3/cmd/kk/pkg/core/pipeline" | ||
"github.com/kubesphere/kubekey/v3/cmd/kk/pkg/kubernetes" | ||
) | ||
|
||
func ApplyClusterAddons(args common.Argument) error { | ||
|
||
var loaderType string | ||
if args.FilePath != "" { | ||
loaderType = common.File | ||
} else { | ||
loaderType = common.AllInOne | ||
} | ||
|
||
runtime, err := common.NewKubeRuntime(loaderType, args) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
switch runtime.Cluster.Kubernetes.Type { | ||
case common.Kubernetes: | ||
if err := ApplyClusterAddonsPipeline(runtime); err != nil { | ||
return err | ||
} | ||
default: | ||
return errors.New("unsupported cluster kubernetes type") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func ApplyClusterAddonsPipeline(runtime *common.KubeRuntime) error { | ||
m := []module.Module{ | ||
&precheck.GreetingsModule{}, | ||
&precheck.NodePreCheckModule{}, | ||
&kubernetes.StatusModule{}, | ||
&addons.AddonsModule{}, | ||
} | ||
|
||
p := pipeline.Pipeline{ | ||
Name: "ApplyClusterAddonsPipeline", | ||
Modules: m, | ||
Runtime: runtime, | ||
} | ||
if err := p.Start(); err != nil { | ||
return err | ||
} | ||
return nil | ||
} |
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