Skip to content

Commit

Permalink
Merge pull request #98 from ONE7live/main
Browse files Browse the repository at this point in the history
fix: Migrate clusterlink-system to kosmos-system
  • Loading branch information
kosmos-robot authored Oct 11, 2023
2 parents 7c4c030 + 0118370 commit 708d1bd
Show file tree
Hide file tree
Showing 19 changed files with 259 additions and 93 deletions.
4 changes: 2 additions & 2 deletions cmd/clusterlink/elector/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func NewOptions() *Options {
LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
LeaderElect: true,
ResourceLock: resourcelock.LeasesResourceLock,
ResourceNamespace: utils.NamespaceClusterLinksystem,
ResourceNamespace: utils.DefaultNamespace,
ResourceName: "elector",
},
}
Expand All @@ -48,7 +48,7 @@ func (o *Options) Validate() field.ErrorList {
func (o *Options) AddFlags(fs *pflag.FlagSet) {
fs.BoolVar(&o.LeaderElection.LeaderElect, "leader-elect", true, "Enable leader election, which must be true when running multi instances.")
fs.StringVar(&o.LeaderElection.ResourceName, "leader-elect-resource-name", "elector", "The name of resource object that is used for locking during leader election.")
fs.StringVar(&o.LeaderElection.ResourceNamespace, "leader-elect-resource-namespace", utils.NamespaceClusterLinksystem, "The namespace of resource object that is used for locking during leader election.")
fs.StringVar(&o.LeaderElection.ResourceNamespace, "leader-elect-resource-namespace", utils.DefaultNamespace, "The namespace of resource object that is used for locking during leader election.")
fs.DurationVar(&o.LeaderElection.LeaseDuration.Duration, "leader-elect-lease-duration", defaultElectionLeaseDuration.Duration, ""+
"The duration that non-leader candidates will wait after observing a leadership "+
"renewal until attempting to acquire leadership of a led but unrenewed leader "+
Expand Down
4 changes: 2 additions & 2 deletions cmd/clusterlink/network-manager/app/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewOptions() *Options {
LeaderElection: componentbaseconfig.LeaderElectionConfiguration{
LeaderElect: true,
ResourceLock: resourcelock.LeasesResourceLock,
ResourceNamespace: utils.NamespaceClusterLinksystem,
ResourceNamespace: utils.DefaultNamespace,
ResourceName: "network-manager",
},
}
Expand All @@ -38,7 +38,7 @@ func (o *Options) AddFlags(flags *pflag.FlagSet) {

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.")
flags.StringVar(&o.LeaderElection.ResourceName, "leader-elect-resource-name", "network-manager", "The name of resource object that is used for locking during leader election.")
flags.StringVar(&o.LeaderElection.ResourceNamespace, "leader-elect-resource-namespace", utils.NamespaceClusterLinksystem, "The namespace of resource object that is used for locking during leader election.")
flags.StringVar(&o.LeaderElection.ResourceNamespace, "leader-elect-resource-namespace", utils.DefaultNamespace, "The namespace of resource object that is used for locking during leader election.")
flags.Float32Var(&o.KubernetesOptions.QPS, "kube-qps", 40.0, "QPS to use while talking with kube-apiserver.")
flags.IntVar(&o.KubernetesOptions.Burst, "kube-burst", 60, "Burst to use while talking with kube-apiserver.")
flags.StringVar(&o.KubernetesOptions.KubeConfig, "kubeconfig", "", "Path for kubernetes kubeconfig file, if left blank, will use in cluster way.")
Expand Down
2 changes: 1 addition & 1 deletion cmd/clusterlink/operator/app/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func run(ctx context.Context, opts *options.Options) error {
}
} else {
// try get kubeconfig from configmap
cm, err := clientset.CoreV1().ConfigMaps(utils.NamespaceClusterLinksystem).Get(context.Background(), opts.ExternalKubeConfigName, metav1.GetOptions{})
cm, err := clientset.CoreV1().ConfigMaps(utils.DefaultNamespace).Get(context.Background(), opts.ExternalKubeConfigName, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to configmap %s: %v", opts.ExternalKubeConfigName, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/kosmos/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type ClusterSpec struct {
// +optional
IPFamily IPFamilyType `json:"ipFamily"`
ImageRepository string `json:"imageRepository,omitempty"`
// +kubebuilder:default=clusterlink-system
// +kubebuilder:default=kosmos-system
// +optional
Namespace string `json:"namespace"`

Expand Down
3 changes: 2 additions & 1 deletion pkg/clusterlink/controllers/cluster/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
ctrl "sigs.k8s.io/controller-runtime"

clusterlinkv1alpha1 "github.com/kosmos.io/kosmos/pkg/apis/kosmos/v1alpha1"
"github.com/kosmos.io/kosmos/pkg/utils"
)

const (
Expand Down Expand Up @@ -58,7 +59,7 @@ func GetCalicoClient(cluster *clusterlinkv1alpha1.Cluster) (clientv3.Interface,
return nil, err
}

clusterConfigMap, err := clientSet.CoreV1().ConfigMaps("clusterlink-system").Get(context.Background(), cluster.Name, metav1.GetOptions{})
clusterConfigMap, err := clientSet.CoreV1().ConfigMaps(utils.DefaultNamespace).Get(context.Background(), cluster.Name, metav1.GetOptions{})
if err != nil {
klog.Errorf("failed to get cluster configmap, cluster name is %s.", cluster.Name)
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/clusterlink/operator/addons/elector/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ spec:
values:
- elector
namespaces:
- clusterlink-system
- {{ .Namespace }}
topologyKey: kubernetes.io/hostname
containers:
- name: elector
Expand Down
2 changes: 1 addition & 1 deletion pkg/clusterlink/operator/addons/manager/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ spec:
values:
- clusterlink-controller-manager
namespaces:
- clusterlink-system
- {{ .Namespace }}
topologyKey: kubernetes.io/hostname
containers:
- name: manager
Expand Down
2 changes: 1 addition & 1 deletion pkg/clusterlink/operator/addons/proxy/manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ spec:
values:
- clusterlink-proxy
namespaces:
- clusterlink-system
- {{ .Namespace }}
topologyKey: kubernetes.io/hostname
containers:
- name: manager
Expand Down
4 changes: 2 additions & 2 deletions pkg/kosmosctl/floater/doctor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

"github.com/kosmos.io/kosmos/pkg/kosmosctl/floater/command"
"github.com/kosmos.io/kosmos/pkg/kosmosctl/floater/netmap"
"github.com/kosmos.io/kosmos/pkg/kosmosctl/util"
"github.com/kosmos.io/kosmos/pkg/utils"
"github.com/kosmos.io/kosmos/pkg/version"
)

Expand Down Expand Up @@ -79,7 +79,7 @@ func NewCmdDoctor() *cobra.Command {
}

flags := cmd.Flags()
flags.StringVarP(&o.Namespace, "namespace", "n", util.DefaultNamespace, "Kosmos namespace.")
flags.StringVarP(&o.Namespace, "namespace", "n", utils.DefaultNamespace, "Kosmos namespace.")
flags.StringVarP(&o.ImageRepository, "image-repository", "r", "ghcr.io/kosmos-io", "Image repository.")
flags.StringVarP(&o.ImageRepositoryDst, "image-repository-dst", "", "", "Image repository.")
flags.StringVar(&o.HostKubeConfig, "host-kubeconfig", "", "Absolute path to the host kubeconfig file.")
Expand Down
4 changes: 2 additions & 2 deletions pkg/kosmosctl/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
ctlutil "k8s.io/kubectl/pkg/cmd/util"
"k8s.io/kubectl/pkg/util/i18n"

"github.com/kosmos.io/kosmos/pkg/kosmosctl/util"
"github.com/kosmos.io/kosmos/pkg/utils"
)

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

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

return cmd
}
Expand Down
15 changes: 9 additions & 6 deletions pkg/kosmosctl/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/kosmos.io/kosmos/pkg/kosmosctl/manifest"
"github.com/kosmos.io/kosmos/pkg/kosmosctl/util"
"github.com/kosmos.io/kosmos/pkg/utils"
"github.com/kosmos.io/kosmos/pkg/version"
)

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

flags := cmd.Flags()
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.StringVarP(&o.Namespace, "namespace", "n", utils.DefaultNamespace, "Kosmos namespace.")
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.")
flags.StringVarP(&o.Module, "module", "m", utils.DefaultInstallModule, "Kosmos specify the module to install.")
flags.StringVar(&o.HostKubeConfig, "host-kubeconfig", "", "Absolute path to the special host kubeconfig file.")
flags.IntVarP(&o.WaitTime, "wait-time", "", 120, "Wait the specified time for the Kosmos install ready.")

return cmd
Expand Down Expand Up @@ -214,7 +215,9 @@ func (o *CommandInstallOptions) runClusterlink() error {

klog.Info("Attempting to create kosmos-clusterlink knode CRDs...")
crds := apiextensionsv1.CustomResourceDefinitionList{}
clusterlinkCluster, err := util.GenerateCustomResourceDefinition(manifest.ClusterlinkCluster, nil)
clusterlinkCluster, err := util.GenerateCustomResourceDefinition(manifest.ClusterlinkCluster, manifest.ClusterlinkReplace{
Namespace: o.Namespace,
})
if err != nil {
return err
}
Expand Down Expand Up @@ -332,7 +335,7 @@ func (o *CommandInstallOptions) runClustertree() error {
klog.Info("Start creating kosmos-clustertree ConfigMap...")
clustertreeConfigMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: util.HostKubeConfigName,
Name: utils.HostKubeConfigName,
Namespace: o.Namespace,
},
Data: map[string]string{
Expand Down
27 changes: 15 additions & 12 deletions pkg/kosmosctl/join/join.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/kosmos.io/kosmos/pkg/kosmosctl/manifest"
"github.com/kosmos.io/kosmos/pkg/kosmosctl/util"
"github.com/kosmos.io/kosmos/pkg/utils"
"github.com/kosmos.io/kosmos/pkg/version"
)

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

func (o *CommandJoinOptions) Complete(f ctlutil.Factory) error {
var masterConfig *rest.Config
var clusterConfig *rest.Config
var err error

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

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

// 2. create namespace in member
namespace := &corev1.Namespace{}
namespace.Name = util.ClusterlinkNamespace
namespace.Name = utils.DefaultNamespace
_, err = o.Client.CoreV1().Namespaces().Create(context.TODO(), namespace, metav1.CreateOptions{})
if err != nil && !apierrors.IsAlreadyExists(err) {
return fmt.Errorf("(cluster namespace) kosmosctl join run error, create namespace failed: %s", err)
Expand All @@ -213,8 +215,8 @@ func (o *CommandJoinOptions) runCluster() error {
secret := &corev1.Secret{
TypeMeta: metav1.TypeMeta{},
ObjectMeta: metav1.ObjectMeta{
Name: util.ControlPanelSecretName,
Namespace: util.ClusterlinkNamespace,
Name: utils.ControlPanelSecretName,
Namespace: utils.DefaultNamespace,
},
Data: map[string][]byte{
"kubeconfig": o.MasterKubeConfigStream,
Expand All @@ -235,7 +237,7 @@ func (o *CommandJoinOptions) runCluster() error {
return fmt.Errorf("(cluster rbac) kosmosctl join run error, create clusterrole failed: %s", err)
}
clusterRoleBinding, err := util.GenerateClusterRoleBinding(manifest.ClusterlinkClusterRoleBinding, manifest.ClusterRoleBindingReplace{
Namespace: util.ClusterlinkNamespace,
Namespace: utils.DefaultNamespace,
})
if err != nil {
return fmt.Errorf("(cluster rbac) kosmosctl join run error, generate clusterrolebinding failed: %s", err)
Expand All @@ -247,7 +249,7 @@ func (o *CommandJoinOptions) runCluster() error {

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

deployment, err := util.GenerateDeployment(manifest.ClusterlinkOperatorDeployment, manifest.ClusterlinkDeploymentReplace{
Namespace: util.ClusterlinkNamespace,
Version: version.GetReleaseVersion().PatchRelease(),
ClusterName: o.ClusterName,
UseProxy: o.UseProxy,
Namespace: utils.DefaultNamespace,
Version: version.GetReleaseVersion().PatchRelease(),
ClusterName: o.ClusterName,
UseProxy: o.UseProxy,
ImageRepository: o.ImageRegistry,
})
if err != nil {
return fmt.Errorf("(cluster operator) kosmosctl join run error, generate deployment failed: %s", err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/kosmosctl/manifest/manifest_cr.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ metadata:
spec:
cni: {{ .CNI }}
defaultNICName: {{ .DefaultNICName }}
imageRepository: {{ .ImageRepository }} # Default: ghcr.io/kosmos-io
networkType: {{ .NetworkType }} # Optional: gateway/p2p
imageRepository: {{ .ImageRepository }}
networkType: {{ .NetworkType }}
`

KnodeCR = `
Expand Down
6 changes: 5 additions & 1 deletion pkg/kosmosctl/manifest/manifest_crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ spec:
- ip6
type: object
namespace:
default: clusterlink-system
default: {{ .Namespace }}
type: string
networkType:
default: p2p
Expand Down Expand Up @@ -473,3 +473,7 @@ spec:
storage: true
`
)

type ClusterlinkReplace struct {
Namespace string
}
13 changes: 7 additions & 6 deletions pkg/kosmosctl/manifest/manifest_deployments.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ spec:
values:
- operator
namespaces:
- clusterlink-system
- {{ .Namespace }}
topologyKey: kubernetes.io/hostname
containers:
- name: operator
image: ghcr.io/kosmos-io/clusterlink-operator:v{{ .Version }}
image: {{ .ImageRepository }}/clusterlink-operator:v{{ .Version }}
imagePullPolicy: IfNotPresent
command:
- clusterlink-operator
Expand Down Expand Up @@ -150,8 +150,9 @@ type DeploymentReplace struct {
}

type ClusterlinkDeploymentReplace struct {
Namespace string
Version string
ClusterName string
UseProxy string
Namespace string
Version string
ClusterName string
UseProxy string
ImageRepository string
}
Loading

0 comments on commit 708d1bd

Please sign in to comment.