-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
204 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
Copyright 2023 The Kubebb Authors. | ||
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 main | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/kubebb/core/pkg/cmd" | ||
) | ||
|
||
var longUsage = `Quickly deploy the kubebb platform in the existing k8s environment. | ||
The platform mainly includes four components: core, cluster-component, u4a, and component-store. | ||
For more details, please refer to https://kubebb.github.io/website | ||
Examples: | ||
# install kubebb to a cluster | ||
corectl install --context ~/.kube/devconfig [--skip-component-store|--skip-u4a-component|--skip-cluster-component] | ||
` | ||
|
||
func main() { | ||
rootCmd := cobra.Command{ | ||
Use: "corectl", | ||
Short: "Quickly deploy the kubebb platform in the existing k8s environment", | ||
Long: longUsage, | ||
} | ||
|
||
rootCmd.AddCommand(cmd.NewInstallCmd()) | ||
if err := rootCmd.Execute(); err != nil { | ||
panic(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
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,118 @@ | ||
/* | ||
Copyright 2023 The Kubebb Authors. | ||
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 cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
"k8s.io/client-go/rest" | ||
) | ||
|
||
type config struct { | ||
// {"core": []string{"webhook.enalbe=true"}} | ||
installers map[string][]string | ||
// maybe for helm client | ||
cfg *rest.Config // nolint | ||
// If necessary, define other parameters here | ||
} | ||
|
||
type InstallerFunc func(*config) Installer | ||
|
||
var ( | ||
store map[string]InstallerFunc | ||
) | ||
|
||
const ( | ||
CORE = "core" | ||
CLUSTERCOMPONENT = "cluster-component" | ||
U4A = "u4a" | ||
COMPONENTSTORE = "component-store" | ||
) | ||
|
||
// Enroll Only name conflicts will return an error | ||
func Enroll(name string, instance InstallerFunc) { | ||
store[name] = instance | ||
} | ||
|
||
func GetInstaller(name string) InstallerFunc { | ||
return store[name] | ||
} | ||
|
||
type Installer interface { | ||
Description() string | ||
Install() error | ||
Uninstall() | ||
} | ||
|
||
func NewInstallCmd() *cobra.Command { | ||
var ( | ||
installClusterComponent, installU4A, installComponentStore bool | ||
) | ||
cmd := &cobra.Command{ | ||
Use: "install", | ||
Long: "install core, cluster-component", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
initConf := config{ | ||
// Must install core | ||
installers: map[string][]string{ | ||
CORE: {}, | ||
CLUSTERCOMPONENT: {}, | ||
U4A: {}, | ||
COMPONENTSTORE: {}, | ||
}, | ||
} | ||
if installClusterComponent { // nolint | ||
// if install cluster-component, we will upgrade core | ||
// TODO | ||
} | ||
if installU4A { // nolint | ||
// make sure cluster-component is set | ||
// TODO | ||
} | ||
if installComponentStore { // nolint | ||
// TODO | ||
} | ||
|
||
// get complete config | ||
installTasks := []string{CORE, CLUSTERCOMPONENT, U4A, COMPONENTSTORE} | ||
tasks := make([]Installer, 0) | ||
for _, task := range installTasks { | ||
if _, ok := initConf.installers[task]; ok { | ||
if fn := GetInstaller(task); fn != nil { | ||
tasks = append(tasks, fn(&initConf)) | ||
} | ||
} | ||
} | ||
|
||
for idx, installer := range tasks { | ||
fmt.Printf("Step %d: %s\n", idx+1, installer.Description()) | ||
if err := installer.Install(); err != nil { | ||
// uninstall | ||
for i := idx; i >= 0; i-- { | ||
tasks[i].Uninstall() | ||
} | ||
} | ||
} | ||
}, | ||
} | ||
|
||
cmd.Flags().BoolVar(&installClusterComponent, "cluster-component", false, "install cluster-component?") | ||
cmd.Flags().BoolVar(&installU4A, "u4a", false, "install u4a?") | ||
cmd.Flags().BoolVar(&installComponentStore, "component-store", false, "install component-store?") | ||
return cmd | ||
} |
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,38 @@ | ||
/* | ||
Copyright 2023 The Kubebb Authors. | ||
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 cmd | ||
|
||
type core struct { | ||
args []string | ||
} | ||
|
||
func NewCoreInstaller(conf *config) Installer { | ||
return &core{args: conf.installers[CORE]} | ||
} | ||
|
||
func (c *core) Description() string { | ||
return "Installing core" | ||
} | ||
|
||
func (c *core) Install() error { | ||
return nil | ||
} | ||
|
||
func (c *core) Uninstall() {} | ||
func init() { | ||
Enroll(CORE, NewCoreInstaller) | ||
} |