Skip to content

Commit

Permalink
Merge pull request kosmos-io#59 from rxy0210/main
Browse files Browse the repository at this point in the history
fix: kosmosctl using issues
  • Loading branch information
kosmos-robot authored Sep 22, 2023
2 parents 41dd4d7 + d02f620 commit a9df56c
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 60 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ upload-images: images
docker push ${REGISTRY}/clusterlink-proxy:${VERSION}
docker push ${REGISTRY}/clusterlink-network-manager:${VERSION}
docker push ${REGISTRY}/clusterlink-floater:${VERSION}
docker push ${REGISTRY}/clusterlink-elector:${VERSION}

.PHONY: release
release:
Expand Down
2 changes: 1 addition & 1 deletion deploy/clusterlink-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ spec:
effect: NoSchedule
containers:
- name: clusterlink-agent
image: ghcr.io/kosmos-io/clusterlink/clusterlink-agent:__VERSION__
image: ghcr.io/kosmos-io/clusterlink-agent:__VERSION__
imagePullPolicy: IfNotPresent
command:
- clusterlink-agent
Expand Down
2 changes: 1 addition & 1 deletion deploy/clusterlink-controller-manager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
serviceAccountName: clusterlink-controller-manager
containers:
- name: manager
image: ghcr.io/kosmos-io/clusterlink/clusterlink-controller-manager:__VERSION__
image: ghcr.io/kosmos-io/clusterlink-controller-manager:__VERSION__
imagePullPolicy: IfNotPresent
command:
- clusterlink-controller-manager
Expand Down
2 changes: 1 addition & 1 deletion deploy/clusterlink-elector.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ spec:
fieldRef:
apiVersion: v1
fieldPath: spec.nodeName
image: ghcr.io/kosmos-io/clusterlink/clusterlink-elector:__VERSION__
image: ghcr.io/kosmos-io/clusterlink-elector:__VERSION__
imagePullPolicy: IfNotPresent
name: elector
resources:
Expand Down
2 changes: 1 addition & 1 deletion deploy/clusterlink-network-manager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ spec:
topologyKey: kubernetes.io/hostname
containers:
- name: manager
image: ghcr.io/kosmos-io/clusterlink/clusterlink-network-manager:__VERSION__
image: ghcr.io/kosmos-io/clusterlink-network-manager:__VERSION__
imagePullPolicy: IfNotPresent
command:
- clusterlink-network-manager
Expand Down
2 changes: 1 addition & 1 deletion deploy/clusterlink-operator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ spec:
topologyKey: kubernetes.io/hostname
containers:
- name: operator
image: ghcr.io/kosmos-io/clusterlink/clusterlink-operator:__VERSION__
image: ghcr.io/kosmos-io/clusterlink-operator:__VERSION__
imagePullPolicy: IfNotPresent
command:
- clusterlink-operator
Expand Down
2 changes: 1 addition & 1 deletion deploy/clusterlink-proxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ spec:
name: clusterlink-agent-proxy
containers:
- name: manager
image: ghcr.io/kosmos-io/clusterlink/clusterlink-proxy:__VERSION__
image: ghcr.io/kosmos-io/clusterlink-proxy:__VERSION__
imagePullPolicy: IfNotPresent
command:
- clusterlink-proxy
Expand Down
24 changes: 12 additions & 12 deletions hack/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@ CLUSTERLINK_TARGET_SOURCE=(
clusterlink-network-manager=cmd/network-manager
)

#https://textkool.com/en/ascii-art-generator?hl=default&vl=default&font=DOS%20Rebel&text=ClusterLink
CLUSTERLINK_GREETING='
------------------------------------------------------------------------------------------------------
█████████ ████ █████ █████ ███ █████
███░░░░░███░░███ ░░███ ░░███ ░░░ ░░███
███ ░░░ ░███ █████ ████ █████ ██████ ██████ ████████ ░███ ████ ████████ ░███ █████
░███ ░███ ░░██████ ███░░░░███░ ███░░███░░███░░███ ░███ ░░███ ░░███░░███ ░███░░███
░██████ ░███ ░███ ░░█████ ░███ ███████ ░███ ░░░ ░███ ░███ ░███ ░███ ░██████░
░░███ ███ ░███ ░███ ░███ ░░░░███ ███ ███░███░░░ ░███ ░███ ░███ ███ ███ ███░███
░░█████████ ████ ░░████████ ██████ ░░█████ ░░██████ █████ ███████████ █████ ████ █████ ████ █████
░░░░░░░░░ ░░░░ ░░░░░░░░ ░░░░░░ ░░░░░ ░░░░░░ ░░░░░ ░░░░░░░░░░░ ░░░░░ ░░░░ ░░░░░ ░░░░ ░░░░░
------------------------------------------------------------------------------------------------------
#https://textkool.com/en/ascii-art-generator?hl=default&vl=default&font=DOS%20Rebel&text=KOSMOS
KOSMOS_GREETING='
--------------------------------------------------------------------------------------
█████ ████ ███████ █████████ █████ █████ ███████ █████████
░░███ ███░ ███░░░░███ ███░░░░░███░░██████ ██████ ███░░░░░███ ███░░░░░███
███ ███ ███ ░░██████ ░░░ ░████████░███ ███ ██████ ░░░
░███████ ░███ ░███░░█████████ ░███░██████ ░███ ███░░█████████
░███░░███ ░███ ░███ ░░░░░░░░███ ░███ ░░░ ░███ ░███ ░███ ░░░░░░░░███
░███ ░███ ░░███ ███ ███ ░███ ░███ ░███ ░░███ ███ ███ ░███
█████ ░░████ ░░███████░░█████████ █████ █████ ░░░███████░ ░░█████████
░░░░░ ░░░░ ░░░░░░░ ░░░░░░░░░ ░░░░░ ░░░░░ ░░░░░░░ ░░░░░░░░░
---------------------------------------------------------------------------------------
'

function util::get_target_source() {
Expand Down
34 changes: 14 additions & 20 deletions pkg/kosmosctl/join/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package join

import (
"context"
"encoding/base64"
"fmt"
"os"

Expand All @@ -28,11 +27,8 @@ import (
)

var joinExample = templates.Examples(i18n.T(`
# join member1-cluster to master control plane
kosmosctl join --cluster-kubeconfig=[member-kubeconfig] -f member1-cluster.yaml --master-kubeconfig=[master-kubeconfig]
# join member1-cluster to current master control plane
kosmosctl join --cluster-kubeconfig=[member-kubeconfig] -f member1-cluster.yaml
# join member-cluster to master control plane
kosmosctl join -f member-cluster.yaml --master-kubeconfig=[master-kubeconfig] --cluster-kubeconfig=[member-kubeconfig]
`))

type CommandJoinOptions struct {
Expand Down Expand Up @@ -69,6 +65,10 @@ func NewCmdJoin(f ctlutil.Factory) *cobra.Command {
fmt.Printf("kosmosctl join cmd error, MarkFlagRequired failed: %s", err)
}
cmd.Flags().StringVarP(&o.MasterKubeConfig, "master-kubeconfig", "", "", "master-kubeconfig")
err = cmd.MarkFlagRequired("master-kubeconfig")
if err != nil {
fmt.Printf("kosmosctl join cmd error, MarkFlagRequired failed: %s", err)
}
cmd.Flags().StringVarP(&o.ClusterKubeConfig, "cluster-kubeconfig", "", "", "cluster-kubeconfig")
err = cmd.MarkFlagRequired("cluster-kubeconfig")
if err != nil {
Expand All @@ -82,16 +82,9 @@ func (o *CommandJoinOptions) Complete(f ctlutil.Factory, cmd *cobra.Command, arg
var masterConfig *restclient.Config
var err error

if o.MasterKubeConfig != "" {
masterConfig, err = clientcmd.BuildConfigFromFlags("", o.MasterKubeConfig)
if err != nil {
return fmt.Errorf("kosmosctl join complete error, generate masterConfig failed: %s", err)
}
} else {
masterConfig, err = f.ToRESTConfig()
if err != nil {
return fmt.Errorf("kosmosctl join complete error, get current masterConfig failed: %s", err)
}
masterConfig, err = clientcmd.BuildConfigFromFlags("", o.MasterKubeConfig)
if err != nil {
return fmt.Errorf("kosmosctl join complete error, generate masterConfig failed: %s", err)
}

clusterConfig, err := clientcmd.BuildConfigFromFlags("", o.ClusterKubeConfig)
Expand Down Expand Up @@ -146,9 +139,9 @@ func (o *CommandJoinOptions) Run(f ctlutil.Factory, cmd *cobra.Command, args []s
}

// 3. create secret in member
memberFile, err := os.ReadFile(o.ClusterKubeConfig)
if err != nil {
return fmt.Errorf("(secret) kosmosctl join run warning, read memberconfig failed: %s", err)
masterKubeConfig, err := os.ReadFile(o.MasterKubeConfig)
if err != nil && !apierrors.IsAlreadyExists(err) {
return fmt.Errorf("(secret) kosmosctl join run warning, read masterconfig failed: %s", err)
}
secret := &corev1.Secret{
TypeMeta: metav1.TypeMeta{},
Expand All @@ -157,7 +150,8 @@ func (o *CommandJoinOptions) Run(f ctlutil.Factory, cmd *cobra.Command, args []s
Namespace: utils.NamespaceClusterLinksystem,
},
Data: map[string][]byte{
"kubeconfig": []byte(base64.StdEncoding.EncodeToString(memberFile))},
"kubeconfig": masterKubeConfig,
},
}
_, err = o.Client.CoreV1().Secrets(secret.Namespace).Create(context.TODO(), secret, metav1.CreateOptions{})
if err != nil && !apierrors.IsAlreadyExists(err) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/kosmosctl/manifest/manifest_daemonsets.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ spec:
operator: DoesNotExist
containers:
- name: floater
image: {{ .ImageRepository }}/clusterlink-floater:{{ .Version }}
image: {{ .ImageRepository }}/clusterlink-floater:v{{ .Version }}
imagePullPolicy: IfNotPresent
command:
- clusterlink-floater
Expand Down
6 changes: 3 additions & 3 deletions pkg/kosmosctl/manifest/manifest_deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ spec:
serviceAccountName: clusterlink-network-manager
containers:
- name: manager
image: {{ .ImageRepository }}/clusterlink-network-manager:{{ .Version }}
image: {{ .ImageRepository }}/clusterlink-network-manager:v{{ .Version }}
imagePullPolicy: IfNotPresent
command:
- clusterlink-network-manager
Expand Down Expand Up @@ -68,7 +68,7 @@ spec:
topologyKey: kubernetes.io/hostname
containers:
- name: operator
image: ghcr.io/kosmos-io/clusterlink-operator:__VERSION__
image: ghcr.io/kosmos-io/clusterlink-operator:v{{ .Version }}
imagePullPolicy: IfNotPresent
command:
- clusterlink-operator
Expand All @@ -82,7 +82,7 @@ spec:
memory: 200Mi
env:
- name: VERSION
value: {{ .Version }}
value: v{{ .Version }}
- name: CLUSTER_NAME
value: {{ .ClusterName }}
- name: USE_PROXY
Expand Down
22 changes: 6 additions & 16 deletions pkg/kosmosctl/unjoin/unjoin.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ const (

var unjoinExample = templates.Examples(i18n.T(`
# unjoin member1-cluster in master control plane
kosmosctl unjoin member1-cluster --cluster-kubeconfig=[member-kubeconfig] --master-kubeconfig=[master-kubeconfig]
kosmosctl unjoin member-cluster --cluster-kubeconfig=[member-kubeconfig] --master-kubeconfig=[master-kubeconfig]
# unjoin member1-cluster in current master control plane
kosmosctl unjoin member1-cluster --cluster-kubeconfig=[member-kubeconfig]
kosmosctl unjoin member-cluster --cluster-kubeconfig=[member-kubeconfig]
`))

type CommandUnJoinOptions struct {
Expand Down Expand Up @@ -108,33 +108,23 @@ func (o *CommandUnJoinOptions) Validate() error {

func (o *CommandUnJoinOptions) Run(f ctlutil.Factory, cmd *cobra.Command, args []string) error {
//delete cluster
err := o.DynamicClient.Resource(schema.GroupVersionResource{
Group: "kosmos.io",
Version: "v1alpha1",
Resource: "clusters",
}).Namespace("").Delete(context.TODO(), args[0], metav1.DeleteOptions{})
if err != nil && !apierrors.IsNotFound(err) {
return fmt.Errorf("(cluster) kosmosctl unjoin run error, delete cluster failed: %s", err)
}

for {
// Wait 3 second
time.Sleep(3 * time.Second)
_, err := o.DynamicClient.Resource(schema.GroupVersionResource{
err := o.DynamicClient.Resource(schema.GroupVersionResource{
Group: "kosmos.io",
Version: "v1alpha1",
Resource: "clusters",
}).Namespace("").Get(context.TODO(), args[0], metav1.GetOptions{})
}).Namespace("").Delete(context.TODO(), args[0], metav1.DeleteOptions{})
if err != nil {
if apierrors.IsNotFound(err) {
break
}
return fmt.Errorf("(cluster) kosmosctl unjoin run error, delete cluster failed: %s", err)
}
time.Sleep(3 * time.Second)
}

// delete operator
err = o.Client.CoreV1().ServiceAccounts(util.DefaultNamespace).Delete(context.TODO(), ClusterlinkOperator, metav1.DeleteOptions{})
err := o.Client.CoreV1().ServiceAccounts(util.DefaultNamespace).Delete(context.TODO(), ClusterlinkOperator, metav1.DeleteOptions{})
if err != nil && !apierrors.IsNotFound(err) {
return fmt.Errorf("(operator) kosmosctl unjoin run error, delete serviceaccout failed: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/addons/proxy/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ spec:
- key: app
operator: In
values:
- elector
- clusterlink-proxy
namespaces:
- clusterlink-system
topologyKey: kubernetes.io/hostname
Expand Down
2 changes: 1 addition & 1 deletion pkg/operator/operator_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

const (
controllerName = "operator-controller"
ClusterControllerFinalizer = "cnp.io/operator-controller"
ClusterControllerFinalizer = "kosmos.io/operator-controller"
)

// nolint
Expand Down

0 comments on commit a9df56c

Please sign in to comment.