diff --git a/manifests/charts/dubbo-cni/Chart.yaml b/manifests/charts/dubbo-cni/Chart.yaml new file mode 100644 index 000000000..2f6e07603 --- /dev/null +++ b/manifests/charts/dubbo-cni/Chart.yaml @@ -0,0 +1,33 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: v2 +annotations: + licenses: Apache-2.0 +name: dubbo-cni +home: https://github.com/apache/dubbo-kubernetes +description: Helm chart for Dubbo CNI node-level Triple tunnel DaemonSet. +keywords: + - dubbo + - dubbo-cni + - cni + - ambient + - triple +version: 0.4.7 +appVersion: "arm64" +sources: + - https://dubbo.apache.org + - https://github.com/dubml + - https://github.com/apache/dubbo-kubernetes diff --git a/manifests/charts/dubbo-cni/templates/clusterrole.yaml b/manifests/charts/dubbo-cni/templates/clusterrole.yaml new file mode 100644 index 000000000..4b5b78a5a --- /dev/null +++ b/manifests/charts/dubbo-cni/templates/clusterrole.yaml @@ -0,0 +1,28 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: dubbo-cni-node + labels: + app: dubbo-cni-node +rules: + - apiGroups: [""] + resources: ["pods", "namespaces", "secrets", "nodes"] + verbs: ["get", "list", "watch"] + - apiGroups: [""] + resources: ["events"] + verbs: ["create", "patch"] diff --git a/manifests/charts/dubbo-cni/templates/clusterrolebinding.yaml b/manifests/charts/dubbo-cni/templates/clusterrolebinding.yaml new file mode 100644 index 000000000..221c3f69e --- /dev/null +++ b/manifests/charts/dubbo-cni/templates/clusterrolebinding.yaml @@ -0,0 +1,29 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: dubbo-cni-node + labels: + app: dubbo-cni-node +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: dubbo-cni-node +subjects: + - kind: ServiceAccount + name: dubbo-cni-node + namespace: {{ .Release.Namespace }} diff --git a/manifests/charts/dubbo-cni/templates/daemonset.yaml b/manifests/charts/dubbo-cni/templates/daemonset.yaml new file mode 100644 index 000000000..a26a75ef7 --- /dev/null +++ b/manifests/charts/dubbo-cni/templates/daemonset.yaml @@ -0,0 +1,144 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +{{- $defaults := .Values._internal_default_values_not_set | default dict }} +{{- $repo := coalesce .Values.repo $defaults.repo "dubml" }} +{{- $tag := .Chart.AppVersion }} +{{- if and (hasKey .Values "tag") (ne (.Values.tag | toString) "") }} +{{- $tag = .Values.tag }} +{{- else if and (hasKey $defaults "tag") (ne ($defaults.tag | toString) "") }} +{{- $tag = $defaults.tag }} +{{- end }} +{{- $image := coalesce .Values.image $defaults.image "dubbo-cni" }} +{{- if not (contains "/" $image) }} +{{- $image = printf "%s/%s:%v" $repo $image $tag }} +{{- end }} +{{- $cniBinDir := coalesce .Values.cniBinDir $defaults.cniBinDir "/opt/cni/bin" }} +{{- $cniNetDir := coalesce .Values.cniNetDir $defaults.cniNetDir "/etc/cni/net.d" }} +{{- $socketPath := coalesce .Values.socketPath $defaults.socketPath "/var/run/dubbo-cni/cni.sock" }} +{{- $statusPort := coalesce .Values.statusPort $defaults.statusPort 15021 }} +{{- $outboundPort := coalesce .Values.outboundPort $defaults.outboundPort 15001 }} +{{- $inboundTunnelPort := coalesce .Values.inboundTunnelPort $defaults.inboundTunnelPort 15008 }} +{{- $discoveryAddress := coalesce .Values.discoveryAddress $defaults.discoveryAddress "dubbod.dubbo-system.svc:26012" }} +{{- $excludeNamespaces := coalesce .Values.excludeNamespaces $defaults.excludeNamespaces "kube-system,dubbo-system" }} +apiVersion: apps/v1 +kind: DaemonSet +metadata: + name: dubbo-cni-node + namespace: {{ .Release.Namespace }} + labels: + app: dubbo-cni-node +spec: + selector: + matchLabels: + app: dubbo-cni-node + updateStrategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 1 + template: + metadata: + labels: + app: dubbo-cni-node + annotations: + prometheus.io/scrape: "true" + prometheus.io/path: "/metrics" + prometheus.io/port: "{{ $statusPort }}" + spec: + serviceAccountName: dubbo-cni-node + hostNetwork: true + dnsPolicy: ClusterFirstWithHostNet + priorityClassName: system-node-critical + tolerations: + - operator: Exists + containers: + - name: cni-node + image: {{ $image }} + imagePullPolicy: {{ coalesce .Values.imagePullPolicy $defaults.imagePullPolicy "IfNotPresent" }} + args: + - --cni-bin-dir=/host/opt/cni/bin + - --cni-net-dir=/host/etc/cni/net.d + - --socket-path={{ $socketPath }} + - --status-addr=:{{ $statusPort }} + - --outbound-addr=:{{ $outboundPort }} + - --inbound-tunnel-addr=:{{ $inboundTunnelPort }} + - --exclude-namespaces={{ $excludeNamespaces }} + env: + - name: NODE_NAME + valueFrom: + fieldRef: + fieldPath: spec.nodeName + - name: NODE_IP + valueFrom: + fieldRef: + fieldPath: status.hostIP + - name: DUBBO_SYSTEM_NAMESPACE + value: {{ .Release.Namespace }} + - name: XDS_ADDRESS + value: {{ $discoveryAddress }} + ports: + - name: status + containerPort: {{ $statusPort }} + protocol: TCP + - name: outbound + containerPort: {{ $outboundPort }} + protocol: TCP + - name: tunnel + containerPort: {{ $inboundTunnelPort }} + protocol: TCP + securityContext: + privileged: true + capabilities: + add: + - NET_ADMIN + - NET_RAW + - SYS_ADMIN + livenessProbe: + httpGet: + path: /healthz + port: {{ $statusPort }} + initialDelaySeconds: 5 + periodSeconds: 10 + readinessProbe: + httpGet: + path: /readyz + port: {{ $statusPort }} + initialDelaySeconds: 2 + periodSeconds: 5 + volumeMounts: + - name: cni-bin-dir + mountPath: /host/opt/cni/bin + - name: cni-net-dir + mountPath: /host/etc/cni/net.d + - name: cni-socket-dir + mountPath: /var/run/dubbo-cni + - name: host-netns + mountPath: /var/run/netns + mountPropagation: HostToContainer + volumes: + - name: cni-bin-dir + hostPath: + path: {{ $cniBinDir }} + - name: cni-net-dir + hostPath: + path: {{ $cniNetDir }} + - name: cni-socket-dir + hostPath: + path: /var/run/dubbo-cni + type: DirectoryOrCreate + - name: host-netns + hostPath: + path: /var/run/netns + type: DirectoryOrCreate diff --git a/manifests/charts/dubbo-cni/templates/serviceaccount.yaml b/manifests/charts/dubbo-cni/templates/serviceaccount.yaml new file mode 100644 index 000000000..8b6cf66fd --- /dev/null +++ b/manifests/charts/dubbo-cni/templates/serviceaccount.yaml @@ -0,0 +1,22 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +apiVersion: v1 +kind: ServiceAccount +metadata: + name: dubbo-cni-node + namespace: {{ .Release.Namespace }} + labels: + app: dubbo-cni-node diff --git a/manifests/charts/dubbo-cni/values.yaml b/manifests/charts/dubbo-cni/values.yaml new file mode 100644 index 000000000..b97a1736b --- /dev/null +++ b/manifests/charts/dubbo-cni/values.yaml @@ -0,0 +1,30 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +_internal_default_values_not_set: + repo: "" + tag: "" + image: dubbo-cni + cniBinDir: /opt/cni/bin + cniNetDir: /etc/cni/net.d + cniConfName: "" + socketPath: /var/run/dubbo-cni/cni.sock + excludeNamespaces: "kube-system,dubbo-system" + failOpen: false + discoveryAddress: "dubbod.dubbo-system.svc:26012" + statusPort: 15021 + outboundPort: 15001 + inboundTunnelPort: 15008 + imagePullPolicy: IfNotPresent diff --git a/manifests/profiles/default.yaml b/manifests/profiles/default.yaml index 8862dde48..abe32c5f3 100644 --- a/manifests/profiles/default.yaml +++ b/manifests/profiles/default.yaml @@ -24,5 +24,7 @@ spec: enabled: true dubbod: enabled: true + cni: + enabled: true values: {} diff --git a/operator/pkg/apis/types.go b/operator/pkg/apis/types.go index e7a4d2c39..3bfb808a9 100644 --- a/operator/pkg/apis/types.go +++ b/operator/pkg/apis/types.go @@ -58,6 +58,8 @@ type DubboComponentSpec struct { Base *BaseComponentSpec `json:"base,omitempty"` // Using dubbod as the control plane. Dubbod *DiscoveryComponentSpec `json:"dubbod,omitempty"` + // Using dubbo-cni-node as the node-level CNI tunnel agent. + Cni *CNIComponentSpec `json:"cni,omitempty"` } type BaseComponentSpec struct { @@ -70,6 +72,11 @@ type DiscoveryComponentSpec struct { Enabled *BoolValue `json:"enabled,omitempty"` } +type CNIComponentSpec struct { + // Selects whether this component is installed. + Enabled *BoolValue `json:"enabled,omitempty"` +} + type DefaultCompSpec struct { // Selects whether this component is installed. Enabled *BoolValue `json:"enabled,omitempty"` diff --git a/operator/pkg/component/component.go b/operator/pkg/component/component.go index 2ed12f357..19a529d4f 100644 --- a/operator/pkg/component/component.go +++ b/operator/pkg/component/component.go @@ -27,6 +27,7 @@ type Name string const ( BaseComponentName Name = "Base" DubboDiscoveryComponentName Name = "Dubbod" + CniComponentName Name = "Cni" ) type Component struct { @@ -66,17 +67,28 @@ var AllComponents = []Component{ Default: true, HelmSubDir: "dubbod", }, + { + UserFacingName: CniComponentName, + SpecName: "cni", + ResourceType: "DaemonSet", + ResourceName: "dubbo-cni-node", + ContainerName: "cni-node", + Default: true, + HelmSubDir: "dubbo-cni", + }, } var ( userFacingCompNames = map[Name]string{ BaseComponentName: "Dubbo Resource Core", DubboDiscoveryComponentName: "Dubbo control plane", + CniComponentName: "Dubbo CNI node agent", } Icons = map[Name]string{ BaseComponentName: "⚡️", DubboDiscoveryComponentName: "⚡️", + CniComponentName: "⚡️", } ) diff --git a/operator/pkg/install/installer.go b/operator/pkg/install/installer.go index 6eb75eb46..9534ad5a6 100644 --- a/operator/pkg/install/installer.go +++ b/operator/pkg/install/installer.go @@ -254,7 +254,10 @@ func (i Installer) prune(manifests []manifest.ManifestSet) error { } var componentDependencies = map[component.Name][]component.Name{ - component.DubboDiscoveryComponentName: {}, + component.CniComponentName: {}, + component.DubboDiscoveryComponentName: { + component.CniComponentName, + }, component.BaseComponentName: { component.DubboDiscoveryComponentName, }, diff --git a/operator/pkg/render/manifest_test.go b/operator/pkg/render/manifest_test.go index 36b8dbfa3..7ded86b1f 100644 --- a/operator/pkg/render/manifest_test.go +++ b/operator/pkg/render/manifest_test.go @@ -371,3 +371,18 @@ func hasContainerPort(ports []interface{}, name string, number int64) bool { } return false } + +func TestGenerateManifestRendersDubboCNIDaemonSet(t *testing.T) { + manifests, _, err := GenerateManifest(nil, nil, nil, nil) + if err != nil { + t.Fatalf("GenerateManifest() error = %v", err) + } + ds := findManifest(t, manifests, "DaemonSet", "dubbo-cni-node") + hostNetwork, ok, err := unstructured.NestedBool(ds.Object, "spec", "template", "spec", "hostNetwork") + if err != nil || !ok || !hostNetwork { + t.Fatalf("dubbo-cni-node hostNetwork = %v (ok=%v err=%v), want true", hostNetwork, ok, err) + } + findManifest(t, manifests, "ServiceAccount", "dubbo-cni-node") + findManifest(t, manifests, "ClusterRole", "dubbo-cni-node") + findManifest(t, manifests, "ClusterRoleBinding", "dubbo-cni-node") +} diff --git a/operator/pkg/uninstall/prune.go b/operator/pkg/uninstall/prune.go index 075633363..40e7754e6 100644 --- a/operator/pkg/uninstall/prune.go +++ b/operator/pkg/uninstall/prune.go @@ -97,6 +97,7 @@ func GetRemovedResources(kc kube.CLIClient, dopName, dopNamespace string, includ } else { includeCN := []string{ string(component.DubboDiscoveryComponentName), + string(component.CniComponentName), } includeRequirement, lerr := klabels.NewRequirement(manifest.DubboComponentLabel, selection.In, includeCN) if lerr != nil {