Skip to content

Commit

Permalink
Merge pull request #96 from ONE7live/main
Browse files Browse the repository at this point in the history
fix: Kosmosctl known issues
  • Loading branch information
kosmos-robot authored Oct 10, 2023
2 parents 70ce6e4 + 38bb1f0 commit 5366b2b
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 120 deletions.
2 changes: 1 addition & 1 deletion deploy/clusterlink-operator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ spec:
- name: CLUSTER_NAME
value: __CLUSTER_NAME__
- name: USE_PROXY
value: "true"
value: "false"
volumeMounts:
- mountPath: /etc/clusterlink
name: proxy-config
Expand Down
11 changes: 4 additions & 7 deletions examples/cluster-demo.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
apiVersion: kosmos.io/v1alpha1
kind: Cluster
metadata:
name: cluster-4
name: member-cluster
spec:
podCIDRs:
- "10.202.0.0/18"
serviceCIDRs:
- "10.213.0.0/18"
cni: "calico"
imageRepository: "kosmos.io"
networkType: "p2p"
defaultNICName: eth0
imageRepository: {{ .image-repository }} # Default: ghcr.io/kosmos-io
networkType: {{ .network-type }} # Optional: gateway/p2p
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (c *leaseController) sync(ctx context.Context) {
return
}

klog.Infof("Successfully updated lease")
klog.V(4).Infof("Successfully updated lease")
}

func (c *leaseController) createLeaseIfNotExistsWithRetry(ctx context.Context, node *corev1.Node) (*coordinationv1.Lease, error) {
Expand Down
60 changes: 42 additions & 18 deletions pkg/kosmosctl/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/util/homedir"
"k8s.io/klog/v2"
ctlutil "k8s.io/kubectl/pkg/cmd/util"
Expand All @@ -28,18 +30,24 @@ var installExample = templates.Examples(i18n.T(`
# Install all module to Kosmos control plane, e.g:
kosmosctl install
# Install clusterlink module to Kosmos control plane, e.g:
# Install Kosmos control plane, if you need to specify a special master cluster kubeconfig, e.g:
kosmosctl install --host-kubeconfig=[host-kubeconfig]
# Install clusterlink module to Kosmos control plane, e.g:
kosmosctl install -m clusterlink
# Install clustertree module to Kosmos control plane, e.g:
kosmosctl install -m clustertree --host-kubeconfig=[host-kubeconfig]
# Install clustertree module to Kosmos control plane, e.g:
kosmosctl install -m clustertree
`))

type CommandInstallOptions struct {
Namespace string
ImageRegistry string
Version string
Module string
Namespace string
ImageRegistry string
Version string
Module string
HostKubeConfig string
HostKubeConfigStream []byte
WaitTime int

Client kubernetes.Interface
ExtensionsClient extensionsclient.Interface
Expand Down Expand Up @@ -68,14 +76,34 @@ func NewCmdInstall(f ctlutil.Factory) *cobra.Command {
flags.StringVarP(&o.Namespace, "namespace", "n", util.DefaultNamespace, "Kosmos namespace.")
flags.StringVarP(&o.ImageRegistry, "private-image-registry", "", util.DefaultImageRepository, "Private image registry where pull images from. If set, all required images will be downloaded from it, it would be useful in offline installation scenarios. In addition, you still can use --kube-image-registry to specify the registry for Kubernetes's images.")
flags.StringVarP(&o.Module, "module", "m", util.DefaultInstallModule, "Kosmos specify the module to install.")
flags.StringVar(&o.HostKubeConfig, "host-kubeconfig", "", "Absolute path to the host kubeconfig file.")
flags.IntVarP(&o.WaitTime, "wait-time", "", 120, "Wait the specified time for the Kosmos install ready.")

return cmd
}

func (o *CommandInstallOptions) Complete(f ctlutil.Factory) error {
config, err := f.ToRESTConfig()
if err != nil {
return fmt.Errorf("kosmosctl install complete error, generate rest config failed: %v", err)
var config *rest.Config
var err error

if len(o.HostKubeConfig) > 0 {
config, err = clientcmd.BuildConfigFromFlags("", o.HostKubeConfig)
if err != nil {
return fmt.Errorf("kosmosctl install complete error, generate host config failed: %s", err)
}
o.HostKubeConfigStream, err = os.ReadFile(o.HostKubeConfig)
if err != nil {
return fmt.Errorf("kosmosctl install complete error, read host config failed: %s", err)
}
} else {
config, err = f.ToRESTConfig()
if err != nil {
return fmt.Errorf("kosmosctl install complete error, generate rest config failed: %v", err)
}
o.HostKubeConfigStream, err = os.ReadFile(filepath.Join(homedir.HomeDir(), ".kube", "config"))
if err != nil {
return fmt.Errorf("kosmosctl install complete error, read host config failed: %s", err)
}
}

o.Client, err = kubernetes.NewForConfig(config)
Expand Down Expand Up @@ -224,7 +252,7 @@ func (o *CommandInstallOptions) runClusterlink() error {
return fmt.Errorf("kosmosctl install clusterlink run error, deployment options failed: %v", err)
}
}
if err = util.WaitDeploymentReady(o.Client, clusterlinkDeployment, 120); err != nil {
if err = util.WaitDeploymentReady(o.Client, clusterlinkDeployment, o.WaitTime); err != nil {
return fmt.Errorf("kosmosctl install clusterlink run error, deployment options failed: %v", err)
} else {
klog.Info("Deployment clusterlink-network-manager has been created.")
Expand Down Expand Up @@ -302,17 +330,13 @@ func (o *CommandInstallOptions) runClustertree() error {
klog.Info("Create CRD " + clustertreeKnode.Name + " successful.")

klog.Info("Start creating kosmos-clustertree ConfigMap...")
hostKubeconfig, err := os.ReadFile(filepath.Join(homedir.HomeDir(), ".kube", "config"))
if err != nil {
return fmt.Errorf("kosmosctl install clustertree run error, host-kubeconfig read failed: %v", err)
}
clustertreeConfigMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: "host-kubeconfig",
Name: util.HostKubeConfigName,
Namespace: o.Namespace,
},
Data: map[string]string{
"kubeconfig": string(hostKubeconfig),
"kubeconfig": string(o.HostKubeConfigStream),
},
}
_, err = o.Client.CoreV1().ConfigMaps(o.Namespace).Create(context.TODO(), clustertreeConfigMap, metav1.CreateOptions{})
Expand All @@ -338,7 +362,7 @@ func (o *CommandInstallOptions) runClustertree() error {
return fmt.Errorf("kosmosctl install clustertree run error, deployment options failed: %v", err)
}
}
if err = util.WaitDeploymentReady(o.Client, clustertreeDeployment, 120); err != nil {
if err = util.WaitDeploymentReady(o.Client, clustertreeDeployment, o.WaitTime); err != nil {
return fmt.Errorf("kosmosctl install clustertree run error, deployment options failed: %v", err)
} else {
klog.Info("Deployment clustertree-knode-manager has been created.")
Expand Down
Loading

0 comments on commit 5366b2b

Please sign in to comment.