Skip to content

Commit

Permalink
title: virtualcluster join controller deploy
Browse files Browse the repository at this point in the history
Signed-off-by: GreatLazyMan <[email protected]>
  • Loading branch information
GreatLazyMan committed Feb 26, 2024
1 parent 52db907 commit b683f5b
Show file tree
Hide file tree
Showing 7 changed files with 419 additions and 5 deletions.
9 changes: 8 additions & 1 deletion cmd/clustertree-operator/app/tree_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/spf13/cobra"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
"k8s.io/client-go/tools/clientcmd"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -54,9 +55,15 @@ func run(ctx context.Context, opts *options.Options) error {
}
config.QPS, config.Burst = opts.KubernetesOptions.QPS, opts.KubernetesOptions.Burst

newscheme := scheme.NewSchema()
err = apiextensionsv1.AddToScheme(newscheme)
if err != nil {
panic(err)
}

mgr, err := controllerruntime.NewManager(config, controllerruntime.Options{
Logger: klog.Background(),
Scheme: scheme.NewSchema(),
Scheme: newscheme,
LeaderElection: opts.LeaderElection.LeaderElect,
LeaderElectionID: opts.LeaderElection.ResourceName,
LeaderElectionNamespace: opts.LeaderElection.ResourceNamespace,
Expand Down
10 changes: 9 additions & 1 deletion deploy/crds/kosmos.io_virtualclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ spec:
listKind: VirtualClusterList
plural: virtualclusters
singular: virtualcluster
scope: Cluster
scope: Namespaced
versions:
- name: v1alpha1
schema:
Expand All @@ -34,6 +34,14 @@ spec:
spec:
description: Spec is the specification for the behaviour of the VirtualCluster.
properties:
hostKubeconfig:
description: HostKubeconfig is the kubeconfig of the host kubernetes's
control plane
type: string
imageRepository:
type: string
kosmosVersion:
type: string
kubeconfig:
description: Kubeconfig is the kubeconfig of the virtual kubernetes's
control plane
Expand Down
12 changes: 11 additions & 1 deletion pkg/apis/kosmos/v1alpha1/virtualcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const (

// +genclient
// +genclient:nonNamespaced
// +kubebuilder:resource:scope="Cluster"
// +kubebuilder:resource:scope="Namespaced"
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type VirtualCluster struct {
Expand All @@ -39,10 +39,20 @@ type VirtualClusterSpec struct {
// +optional
Kubeconfig string `json:"kubeconfig,omitempty"`

// HostKubeconfig is the kubeconfig of the host kubernetes's control plane
// +optional
HostKubeconfig string `json:"hostKubeconfig,omitempty"`

// PromoteResources definites the resources for promote to the kubernetes's control plane,
// the resources can be nodes or just cpu,memory or gpu resources
// +required
PromoteResources PromoteResources `json:"promoteResources"`

// +optional
ImageRepository string `json:"imageRepository,omitempty"`

// +optional
KosmosVersion string `json:"kosmosVersion,omitempty"`
}

type PromoteResources struct {
Expand Down
3 changes: 2 additions & 1 deletion pkg/kosmosctl/manifest/manifest_crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,8 @@ spec:
properties:
clusterLinkOptions:
properties:
autodetectionMethod:
type: string
bridgeCIDRs:
default:
ip: 220.0.0.0/8
Expand Down Expand Up @@ -652,7 +654,6 @@ spec:
storage: true
subresources: {}
`

const NodeConfig = `---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
Expand Down
59 changes: 59 additions & 0 deletions pkg/treeoperator/manifest_deployments.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package treeoperator

const (
DefaultKubeconfigPath = "/etc/cluster-tree/cert"
ClusterTreeClusterManagerDeployment = `---
apiVersion: apps/v1
kind: Deployment
metadata:
name: clustertree-cluster-manager
namespace: {{ .Namespace }}
labels:
app: clustertree-cluster-manager
spec:
replicas: 1
selector:
matchLabels:
app: clustertree-cluster-manager
template:
metadata:
labels:
app: clustertree-cluster-manager
spec:
serviceAccountName: clustertree
containers:
- name: manager
image: {{ .ImageRepository }}/clustertree-cluster-manager:{{ .Version }}
imagePullPolicy: IfNotPresent
env:
- name: APISERVER_CERT_LOCATION
value: {{ .FilePath }}/cert.pem
- name: APISERVER_KEY_LOCATION
value: {{ .FilePath }}/key.pem
- name: LEAF_NODE_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
volumeMounts:
- name: credentials
mountPath: "{{ .FilePath }}"
readOnly: true
command:
- clustertree-cluster-manager
- --multi-cluster-service=true
- --v=4
- --leader-elect-resource-namespace={{ .Namespace }}
- --kubeconfig={{ .FilePath }}/kubeconfig
volumes:
- name: credentials
secret:
secretName: clustertree-cluster-manager
`
)

type DeploymentReplace struct {
Namespace string
ImageRepository string
Version string
FilePath string
}
23 changes: 23 additions & 0 deletions pkg/treeoperator/manifest_secrets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package treeoperator

const (
ClusterTreeClusterManagerSecret = `---
apiVersion: v1
kind: Secret
metadata:
name: clustertree-cluster-manager
namespace: {{ .Namespace }}
type: Opaque
data:
cert.pem: {{ .Cert }}
key.pem: {{ .Key }}
kubeconfig: {{ .Kubeconfig }}
`
)

type SecretReplace struct {
Namespace string
Cert string
Key string
Kubeconfig string
}
Loading

0 comments on commit b683f5b

Please sign in to comment.