Skip to content

Commit 708d1bd

Browse files
authored
Merge pull request kosmos-io#98 from ONE7live/main
fix: Migrate clusterlink-system to kosmos-system
2 parents 7c4c030 + 0118370 commit 708d1bd

File tree

19 files changed

+259
-93
lines changed

19 files changed

+259
-93
lines changed

cmd/clusterlink/elector/app/options/options.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func NewOptions() *Options {
3030
LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
3131
LeaderElect: true,
3232
ResourceLock: resourcelock.LeasesResourceLock,
33-
ResourceNamespace: utils.NamespaceClusterLinksystem,
33+
ResourceNamespace: utils.DefaultNamespace,
3434
ResourceName: "elector",
3535
},
3636
}
@@ -48,7 +48,7 @@ func (o *Options) Validate() field.ErrorList {
4848
func (o *Options) AddFlags(fs *pflag.FlagSet) {
4949
fs.BoolVar(&o.LeaderElection.LeaderElect, "leader-elect", true, "Enable leader election, which must be true when running multi instances.")
5050
fs.StringVar(&o.LeaderElection.ResourceName, "leader-elect-resource-name", "elector", "The name of resource object that is used for locking during leader election.")
51-
fs.StringVar(&o.LeaderElection.ResourceNamespace, "leader-elect-resource-namespace", utils.NamespaceClusterLinksystem, "The namespace of resource object that is used for locking during leader election.")
51+
fs.StringVar(&o.LeaderElection.ResourceNamespace, "leader-elect-resource-namespace", utils.DefaultNamespace, "The namespace of resource object that is used for locking during leader election.")
5252
fs.DurationVar(&o.LeaderElection.LeaseDuration.Duration, "leader-elect-lease-duration", defaultElectionLeaseDuration.Duration, ""+
5353
"The duration that non-leader candidates will wait after observing a leadership "+
5454
"renewal until attempting to acquire leadership of a led but unrenewed leader "+

cmd/clusterlink/network-manager/app/options/options.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func NewOptions() *Options {
2525
LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
2626
LeaderElect: true,
2727
ResourceLock: resourcelock.LeasesResourceLock,
28-
ResourceNamespace: utils.NamespaceClusterLinksystem,
28+
ResourceNamespace: utils.DefaultNamespace,
2929
ResourceName: "network-manager",
3030
},
3131
}
@@ -38,7 +38,7 @@ func (o *Options) AddFlags(flags *pflag.FlagSet) {
3838

3939
flags.BoolVar(&o.LeaderElection.LeaderElect, "leader-elect", true, "Start a leader election client and gain leadership before executing the main loop. Enable this when running replicated components for high availability.")
4040
flags.StringVar(&o.LeaderElection.ResourceName, "leader-elect-resource-name", "network-manager", "The name of resource object that is used for locking during leader election.")
41-
flags.StringVar(&o.LeaderElection.ResourceNamespace, "leader-elect-resource-namespace", utils.NamespaceClusterLinksystem, "The namespace of resource object that is used for locking during leader election.")
41+
flags.StringVar(&o.LeaderElection.ResourceNamespace, "leader-elect-resource-namespace", utils.DefaultNamespace, "The namespace of resource object that is used for locking during leader election.")
4242
flags.Float32Var(&o.KubernetesOptions.QPS, "kube-qps", 40.0, "QPS to use while talking with kube-apiserver.")
4343
flags.IntVar(&o.KubernetesOptions.Burst, "kube-burst", 60, "Burst to use while talking with kube-apiserver.")
4444
flags.StringVar(&o.KubernetesOptions.KubeConfig, "kubeconfig", "", "Path for kubernetes kubeconfig file, if left blank, will use in cluster way.")

cmd/clusterlink/operator/app/operator.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func run(ctx context.Context, opts *options.Options) error {
8888
}
8989
} else {
9090
// try get kubeconfig from configmap
91-
cm, err := clientset.CoreV1().ConfigMaps(utils.NamespaceClusterLinksystem).Get(context.Background(), opts.ExternalKubeConfigName, metav1.GetOptions{})
91+
cm, err := clientset.CoreV1().ConfigMaps(utils.DefaultNamespace).Get(context.Background(), opts.ExternalKubeConfigName, metav1.GetOptions{})
9292
if err != nil {
9393
return fmt.Errorf("failed to configmap %s: %v", opts.ExternalKubeConfigName, err)
9494
}

pkg/apis/kosmos/v1alpha1/cluster_types.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type ClusterSpec struct {
3535
// +optional
3636
IPFamily IPFamilyType `json:"ipFamily"`
3737
ImageRepository string `json:"imageRepository,omitempty"`
38-
// +kubebuilder:default=clusterlink-system
38+
// +kubebuilder:default=kosmos-system
3939
// +optional
4040
Namespace string `json:"namespace"`
4141

pkg/clusterlink/controllers/cluster/helper.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
ctrl "sigs.k8s.io/controller-runtime"
1717

1818
clusterlinkv1alpha1 "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1"
19+
"github.com/kosmos.io/kosmos/pkg/utils"
1920
)
2021

2122
const (
@@ -58,7 +59,7 @@ func GetCalicoClient(cluster *clusterlinkv1alpha1.Cluster) (clientv3.Interface,
5859
return nil, err
5960
}
6061

61-
clusterConfigMap, err := clientSet.CoreV1().ConfigMaps("clusterlink-system").Get(context.Background(), cluster.Name, metav1.GetOptions{})
62+
clusterConfigMap, err := clientSet.CoreV1().ConfigMaps(utils.DefaultNamespace).Get(context.Background(), cluster.Name, metav1.GetOptions{})
6263
if err != nil {
6364
klog.Errorf("failed to get cluster configmap, cluster name is %s.", cluster.Name)
6465
return nil, err

pkg/clusterlink/operator/addons/elector/manifests.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ spec:
4242
values:
4343
- elector
4444
namespaces:
45-
- clusterlink-system
45+
- {{ .Namespace }}
4646
topologyKey: kubernetes.io/hostname
4747
containers:
4848
- name: elector

pkg/clusterlink/operator/addons/manager/manifests.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ spec:
4242
values:
4343
- clusterlink-controller-manager
4444
namespaces:
45-
- clusterlink-system
45+
- {{ .Namespace }}
4646
topologyKey: kubernetes.io/hostname
4747
containers:
4848
- name: manager

pkg/clusterlink/operator/addons/proxy/manifests.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ spec:
4949
values:
5050
- clusterlink-proxy
5151
namespaces:
52-
- clusterlink-system
52+
- {{ .Namespace }}
5353
topologyKey: kubernetes.io/hostname
5454
containers:
5555
- name: manager

pkg/kosmosctl/floater/doctor.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
"github.com/kosmos.io/kosmos/pkg/kosmosctl/floater/command"
1515
"github.com/kosmos.io/kosmos/pkg/kosmosctl/floater/netmap"
16-
"github.com/kosmos.io/kosmos/pkg/kosmosctl/util"
16+
"github.com/kosmos.io/kosmos/pkg/utils"
1717
"github.com/kosmos.io/kosmos/pkg/version"
1818
)
1919

@@ -79,7 +79,7 @@ func NewCmdDoctor() *cobra.Command {
7979
}
8080

8181
flags := cmd.Flags()
82-
flags.StringVarP(&o.Namespace, "namespace", "n", util.DefaultNamespace, "Kosmos namespace.")
82+
flags.StringVarP(&o.Namespace, "namespace", "n", utils.DefaultNamespace, "Kosmos namespace.")
8383
flags.StringVarP(&o.ImageRepository, "image-repository", "r", "ghcr.io/kosmos-io", "Image repository.")
8484
flags.StringVarP(&o.ImageRepositoryDst, "image-repository-dst", "", "", "Image repository.")
8585
flags.StringVar(&o.HostKubeConfig, "host-kubeconfig", "", "Absolute path to the host kubeconfig file.")

pkg/kosmosctl/get/get.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
ctlutil "k8s.io/kubectl/pkg/cmd/util"
1111
"k8s.io/kubectl/pkg/util/i18n"
1212

13-
"github.com/kosmos.io/kosmos/pkg/kosmosctl/util"
13+
"github.com/kosmos.io/kosmos/pkg/utils"
1414
)
1515

1616
const (
@@ -49,7 +49,7 @@ func NewCmdGet(f ctlutil.Factory, streams genericclioptions.IOStreams) *cobra.Co
4949

5050
o.GetOptions.PrintFlags.AddFlags(cmd)
5151
flags := cmd.Flags()
52-
flags.StringVarP(&o.Namespace, "namespace", "n", util.DefaultNamespace, "If present, the namespace scope for this CLI request.")
52+
flags.StringVarP(&o.Namespace, "namespace", "n", utils.DefaultNamespace, "If present, the namespace scope for this CLI request.")
5353

5454
return cmd
5555
}

pkg/kosmosctl/install/install.go

+9-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
"github.com/kosmos.io/kosmos/pkg/kosmosctl/manifest"
2525
"github.com/kosmos.io/kosmos/pkg/kosmosctl/util"
26+
"github.com/kosmos.io/kosmos/pkg/utils"
2627
"github.com/kosmos.io/kosmos/pkg/version"
2728
)
2829

@@ -73,10 +74,10 @@ func NewCmdInstall(f ctlutil.Factory) *cobra.Command {
7374
}
7475

7576
flags := cmd.Flags()
76-
flags.StringVarP(&o.Namespace, "namespace", "n", util.DefaultNamespace, "Kosmos namespace.")
77-
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.")
78-
flags.StringVarP(&o.Module, "module", "m", util.DefaultInstallModule, "Kosmos specify the module to install.")
79-
flags.StringVar(&o.HostKubeConfig, "host-kubeconfig", "", "Absolute path to the host kubeconfig file.")
77+
flags.StringVarP(&o.Namespace, "namespace", "n", utils.DefaultNamespace, "Kosmos namespace.")
78+
flags.StringVarP(&o.ImageRegistry, "private-image-registry", "", utils.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.")
79+
flags.StringVarP(&o.Module, "module", "m", utils.DefaultInstallModule, "Kosmos specify the module to install.")
80+
flags.StringVar(&o.HostKubeConfig, "host-kubeconfig", "", "Absolute path to the special host kubeconfig file.")
8081
flags.IntVarP(&o.WaitTime, "wait-time", "", 120, "Wait the specified time for the Kosmos install ready.")
8182

8283
return cmd
@@ -214,7 +215,9 @@ func (o *CommandInstallOptions) runClusterlink() error {
214215

215216
klog.Info("Attempting to create kosmos-clusterlink knode CRDs...")
216217
crds := apiextensionsv1.CustomResourceDefinitionList{}
217-
clusterlinkCluster, err := util.GenerateCustomResourceDefinition(manifest.ClusterlinkCluster, nil)
218+
clusterlinkCluster, err := util.GenerateCustomResourceDefinition(manifest.ClusterlinkCluster, manifest.ClusterlinkReplace{
219+
Namespace: o.Namespace,
220+
})
218221
if err != nil {
219222
return err
220223
}
@@ -332,7 +335,7 @@ func (o *CommandInstallOptions) runClustertree() error {
332335
klog.Info("Start creating kosmos-clustertree ConfigMap...")
333336
clustertreeConfigMap := &corev1.ConfigMap{
334337
ObjectMeta: metav1.ObjectMeta{
335-
Name: util.HostKubeConfigName,
338+
Name: utils.HostKubeConfigName,
336339
Namespace: o.Namespace,
337340
},
338341
Data: map[string]string{

pkg/kosmosctl/join/join.go

+15-12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
"github.com/kosmos.io/kosmos/pkg/kosmosctl/manifest"
2727
"github.com/kosmos.io/kosmos/pkg/kosmosctl/util"
28+
"github.com/kosmos.io/kosmos/pkg/utils"
2829
"github.com/kosmos.io/kosmos/pkg/version"
2930
)
3031

@@ -85,8 +86,8 @@ func NewCmdJoin(f ctlutil.Factory) *cobra.Command {
8586
flags.StringVar(&o.ClusterKubeConfig, "cluster-kubeconfig", "", "Absolute path to the cluster kubeconfig file.")
8687
flags.StringVar(&o.ClusterName, "cluster-name", "", "Specify the name of the member cluster to join.")
8788
flags.StringVar(&o.CNI, "cni", "", "The cluster is configured using cni and currently supports calico and flannel.")
88-
flags.StringVar(&o.DefaultNICName, "default-nic", "", "Specify the name of the cluster to join.")
89-
flags.StringVar(&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.")
89+
flags.StringVar(&o.DefaultNICName, "default-nic", "", "Set default network interface card.")
90+
flags.StringVar(&o.ImageRegistry, "private-image-registry", utils.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.")
9091
flags.StringVar(&o.NetworkType, "network-type", "gateway", "Set the cluster network connection mode, which supports gateway and p2p modes. Gateway is used by default.")
9192
flags.StringVar(&o.KnodeName, "knode-name", "", "Specify the name of the knode to join.")
9293
flags.StringVar(&o.UseProxy, "use-proxy", "false", "Set whether to enable proxy.")
@@ -97,6 +98,7 @@ func NewCmdJoin(f ctlutil.Factory) *cobra.Command {
9798

9899
func (o *CommandJoinOptions) Complete(f ctlutil.Factory) error {
99100
var masterConfig *rest.Config
101+
var clusterConfig *rest.Config
100102
var err error
101103

102104
if len(o.MasterKubeConfig) > 0 {
@@ -125,7 +127,7 @@ func (o *CommandJoinOptions) Complete(f ctlutil.Factory) error {
125127
}
126128

127129
if len(o.ClusterKubeConfig) > 0 {
128-
clusterConfig, err := clientcmd.BuildConfigFromFlags("", o.ClusterKubeConfig)
130+
clusterConfig, err = clientcmd.BuildConfigFromFlags("", o.ClusterKubeConfig)
129131
if err != nil {
130132
return fmt.Errorf("kosmosctl join complete error, generate clusterConfig failed: %s", err)
131133
}
@@ -203,7 +205,7 @@ func (o *CommandJoinOptions) runCluster() error {
203205

204206
// 2. create namespace in member
205207
namespace := &corev1.Namespace{}
206-
namespace.Name = util.ClusterlinkNamespace
208+
namespace.Name = utils.DefaultNamespace
207209
_, err = o.Client.CoreV1().Namespaces().Create(context.TODO(), namespace, metav1.CreateOptions{})
208210
if err != nil && !apierrors.IsAlreadyExists(err) {
209211
return fmt.Errorf("(cluster namespace) kosmosctl join run error, create namespace failed: %s", err)
@@ -213,8 +215,8 @@ func (o *CommandJoinOptions) runCluster() error {
213215
secret := &corev1.Secret{
214216
TypeMeta: metav1.TypeMeta{},
215217
ObjectMeta: metav1.ObjectMeta{
216-
Name: util.ControlPanelSecretName,
217-
Namespace: util.ClusterlinkNamespace,
218+
Name: utils.ControlPanelSecretName,
219+
Namespace: utils.DefaultNamespace,
218220
},
219221
Data: map[string][]byte{
220222
"kubeconfig": o.MasterKubeConfigStream,
@@ -235,7 +237,7 @@ func (o *CommandJoinOptions) runCluster() error {
235237
return fmt.Errorf("(cluster rbac) kosmosctl join run error, create clusterrole failed: %s", err)
236238
}
237239
clusterRoleBinding, err := util.GenerateClusterRoleBinding(manifest.ClusterlinkClusterRoleBinding, manifest.ClusterRoleBindingReplace{
238-
Namespace: util.ClusterlinkNamespace,
240+
Namespace: utils.DefaultNamespace,
239241
})
240242
if err != nil {
241243
return fmt.Errorf("(cluster rbac) kosmosctl join run error, generate clusterrolebinding failed: %s", err)
@@ -247,7 +249,7 @@ func (o *CommandJoinOptions) runCluster() error {
247249

248250
// 5. create operator in member
249251
serviceAccount, err := util.GenerateServiceAccount(manifest.ClusterlinkOperatorServiceAccount, manifest.ServiceAccountReplace{
250-
Namespace: util.ClusterlinkNamespace,
252+
Namespace: utils.DefaultNamespace,
251253
})
252254
if err != nil {
253255
return fmt.Errorf("(cluster operator) kosmosctl join run error, generate serviceaccount failed: %s", err)
@@ -258,10 +260,11 @@ func (o *CommandJoinOptions) runCluster() error {
258260
}
259261

260262
deployment, err := util.GenerateDeployment(manifest.ClusterlinkOperatorDeployment, manifest.ClusterlinkDeploymentReplace{
261-
Namespace: util.ClusterlinkNamespace,
262-
Version: version.GetReleaseVersion().PatchRelease(),
263-
ClusterName: o.ClusterName,
264-
UseProxy: o.UseProxy,
263+
Namespace: utils.DefaultNamespace,
264+
Version: version.GetReleaseVersion().PatchRelease(),
265+
ClusterName: o.ClusterName,
266+
UseProxy: o.UseProxy,
267+
ImageRepository: o.ImageRegistry,
265268
})
266269
if err != nil {
267270
return fmt.Errorf("(cluster operator) kosmosctl join run error, generate deployment failed: %s", err)

pkg/kosmosctl/manifest/manifest_cr.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ metadata:
99
spec:
1010
cni: {{ .CNI }}
1111
defaultNICName: {{ .DefaultNICName }}
12-
imageRepository: {{ .ImageRepository }} # Default: ghcr.io/kosmos-io
13-
networkType: {{ .NetworkType }} # Optional: gateway/p2p
12+
imageRepository: {{ .ImageRepository }}
13+
networkType: {{ .NetworkType }}
1414
`
1515

1616
KnodeCR = `

pkg/kosmosctl/manifest/manifest_crds.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ spec:
164164
- ip6
165165
type: object
166166
namespace:
167-
default: clusterlink-system
167+
default: {{ .Namespace }}
168168
type: string
169169
networkType:
170170
default: p2p
@@ -473,3 +473,7 @@ spec:
473473
storage: true
474474
`
475475
)
476+
477+
type ClusterlinkReplace struct {
478+
Namespace string
479+
}

pkg/kosmosctl/manifest/manifest_deployments.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ spec:
6565
values:
6666
- operator
6767
namespaces:
68-
- clusterlink-system
68+
- {{ .Namespace }}
6969
topologyKey: kubernetes.io/hostname
7070
containers:
7171
- name: operator
72-
image: ghcr.io/kosmos-io/clusterlink-operator:v{{ .Version }}
72+
image: {{ .ImageRepository }}/clusterlink-operator:v{{ .Version }}
7373
imagePullPolicy: IfNotPresent
7474
command:
7575
- clusterlink-operator
@@ -150,8 +150,9 @@ type DeploymentReplace struct {
150150
}
151151

152152
type ClusterlinkDeploymentReplace struct {
153-
Namespace string
154-
Version string
155-
ClusterName string
156-
UseProxy string
153+
Namespace string
154+
Version string
155+
ClusterName string
156+
UseProxy string
157+
ImageRepository string
157158
}

0 commit comments

Comments
 (0)