Skip to content

Commit

Permalink
feat: support install corends to virtual cluster
Browse files Browse the repository at this point in the history
Signed-off-by: baoyinghai_yewu <[email protected]>
  • Loading branch information
OrangeBao committed Sep 2, 2024
1 parent 61b9ea3 commit 8c8dba7
Show file tree
Hide file tree
Showing 13 changed files with 577 additions and 36 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ cmd/kubenest/node-agent/cert.pem
cmd/kubenest/node-agent/key.pem
cmd/kubenest/node-agent/agent.env
hack/k8s-in-k8s/nodes.txt
develop
develop

cmd/kubenest/node-agent/app/client/app.log
3 changes: 3 additions & 0 deletions deploy/crds/kosmos.io_kubenestconfigurations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ spec:
type: string
type: array
type: object
useTenantDns:
default: false
type: boolean
type: object
kubeNestType:
type: string
Expand Down
3 changes: 3 additions & 0 deletions deploy/crds/kosmos.io_virtualclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ spec:
type: string
type: array
type: object
useTenantDns:
default: false
type: boolean
type: object
kubeconfig:
description: Kubeconfig is the kubeconfig of the virtual kubernetes's
Expand Down
1 change: 1 addition & 0 deletions deploy/virtual-cluster-components-manifest-cm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ data:
{"name": "kube-proxy", "path": "/kosmos/manifest/kube-proxy/*.yaml"},
{"name": "calico", "path": "/kosmos/manifest/calico/*.yaml"},
{"name": "keepalived", "path": "/kosmos/manifest/keepalived/*.yaml"},
{"name": "core-dns-tenant", "path": "/kosmos/manifest/core-dns/tenant/*.yaml"},
]
host-core-dns-components: |
[
Expand Down
2 changes: 1 addition & 1 deletion hack/k8s-in-k8s/g.env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ PATH_KUBELET_CONF=.
KUBELET_CONFIG_NAME=
HOST_CORE_DNS=10.96.0.10
# kubeadm switch
USE_KUBEADM=true
USE_KUBEADM=false
# Generate kubelet.conf TIMEOUT
KUBELET_CONF_TIMEOUT=30

Expand Down
4 changes: 4 additions & 0 deletions pkg/apis/kosmos/v1alpha1/kubenestconfiguration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ type KubeInKubeConfig struct {
// +kubebuilder:default=hostNetwork
// +optional
ApiServerServiceType ApiServerServiceType `yaml:"apiServerServiceType" json:"apiServerServiceType,omitempty"`

// +kubebuilder:default=false
// +optional
UseTenantDns bool `yaml:"useTenantDns" json:"useTenantDns,omitempty"`
}

// TenantEntrypoint contains the configuration for the tenant entrypoint.
Expand Down
6 changes: 6 additions & 0 deletions pkg/generated/openapi/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions pkg/kubenest/constants/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,10 @@ const (
// core-dns
KubeDNSSVCName = "kube-dns"
// nolint
HostCoreDnsComponents = "host-core-dns-components"
VirtualCoreDnsComponents = "virtual-core-dns-components"
PrometheusRuleManifest = "prometheus-rules"
HostCoreDnsComponents = "host-core-dns-components"
VirtualCoreDnsComponents = "virtual-core-dns-components"
PrometheusRuleManifest = "prometheus-rules"
TenantCoreDnsComponentName = "core-dns-tenant"

StateLabelKey = "kosmos-io/state"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ func (e *CoreDNSController) Reconcile(ctx context.Context, request reconcile.Req
return reconcile.Result{RequeueAfter: utils.DefaultRequeueTime}, nil
}

if targetVirtualCluster.Spec.KubeInKubeConfig != nil && targetVirtualCluster.Spec.KubeInKubeConfig.UseTenantDns {
return reconcile.Result{}, nil
}

// Get the corresponding svc
var kubesvc v1.Service
if err := e.Get(ctx, request.NamespacedName, &kubesvc); err != nil {
Expand Down
14 changes: 14 additions & 0 deletions pkg/kubenest/tasks/coredns.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func NewCoreDNSTask() workflow.Task {
return workflow.Task{
Name: "coreDns",
Run: runCoreDns,
Skip: skipCoreDns,
RunSubTasks: true,
Tasks: []workflow.Task{
{
Expand All @@ -46,6 +47,19 @@ func NewCoreDNSTask() workflow.Task {
}
}

func skipCoreDns(d workflow.RunData) (bool, error) {
data, ok := d.(InitData)
if !ok {
return false, errors.New("coreDns task invoked with an invalid data struct")
}

vc := data.VirtualCluster()
if vc.Spec.KubeInKubeConfig != nil && vc.Spec.KubeInKubeConfig.UseTenantDns {
return true, nil
}
return false, nil
}

func runCoreDns(r workflow.RunData) error {
data, ok := r.(InitData)
if !ok {
Expand Down
31 changes: 29 additions & 2 deletions pkg/kubenest/tasks/manifests_components.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ type ComponentConfig struct {
Path string `json:"path" yaml:"path"`
}

type SkipComponentCondition struct {
Condition bool
ComponentName string
}

func NewComponentsFromManifestsTask() workflow.Task {
return workflow.Task{
Name: "manifests-components",
Expand All @@ -53,6 +58,14 @@ func runComponentsFromManifests(r workflow.RunData) error {
return nil
}

func getSkipComponentsForVirtualCluster(condition []*SkipComponentCondition) map[string]bool {
skipComponents := map[string]bool{}
for _, c := range condition {
skipComponents[c.ComponentName] = c.Condition
}
return skipComponents
}

func applyComponentsManifests(r workflow.RunData) error {
data, ok := r.(InitData)
if !ok {
Expand Down Expand Up @@ -96,10 +109,24 @@ func applyComponentsManifests(r workflow.RunData) error {
templatedMapping["KeepalivedReplicas"] = keepalivedReplicas
}

UseTenantDns := data.VirtualCluster().Spec.KubeInKubeConfig != nil && data.VirtualCluster().Spec.KubeInKubeConfig.UseTenantDns

skipComponents := getSkipComponentsForVirtualCluster([]*SkipComponentCondition{
{
// skip coredns component if tenant dns is enabled
Condition: !UseTenantDns,
ComponentName: constants.TenantCoreDnsComponentName,
}, {
// skip keepalived component if vip is not enabled
Condition: !keepalivedEnable,
ComponentName: constants.VipKeepalivedComponentName,
},
})

for _, component := range components {
klog.V(2).Infof("Deploy component %s", component.Name)
// skip keepalived component if vip is not enabled
if !keepalivedEnable && component.Name == constants.VipKeepalivedComponentName {
if v, ok := skipComponents[component.Name]; ok && v {
klog.V(2).Infof("Deploy component %s skipped", component.Name)
continue
}
err = applyTemplatedManifests(component.Name, dynamicClient, component.Path, templatedMapping)
Expand Down
Loading

0 comments on commit 8c8dba7

Please sign in to comment.