2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-03-22 11:03:15 -04:00
|
|
|
package resources
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2022-09-21 07:47:57 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/kubernetes"
|
2022-03-22 11:03:15 -04:00
|
|
|
apps "k8s.io/api/apps/v1"
|
|
|
|
k8s "k8s.io/api/core/v1"
|
|
|
|
rbac "k8s.io/api/rbac/v1"
|
|
|
|
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
)
|
|
|
|
|
2022-10-05 09:02:46 -04:00
|
|
|
type CloudControllerManagerDeployment struct {
|
2022-03-22 11:03:15 -04:00
|
|
|
ServiceAccount k8s.ServiceAccount
|
|
|
|
ClusterRoleBinding rbac.ClusterRoleBinding
|
|
|
|
DaemonSet apps.DaemonSet
|
|
|
|
}
|
|
|
|
|
|
|
|
// references:
|
|
|
|
// https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/admin/cloud/ccm-example.yaml
|
|
|
|
// https://kubernetes.io/docs/tasks/administer-cluster/running-cloud-controller/#cloud-controller-manager
|
|
|
|
|
2022-03-25 05:42:27 -04:00
|
|
|
// NewDefaultCloudControllerManagerDeployment creates a new *cloudControllerManagerDeployment, customized for the CSP.
|
2022-10-05 09:02:46 -04:00
|
|
|
func NewDefaultCloudControllerManagerDeployment(cloudProvider, image, path, podCIDR string, extraArgs []string, extraVolumes []k8s.Volume, extraVolumeMounts []k8s.VolumeMount, env []k8s.EnvVar) *CloudControllerManagerDeployment {
|
2022-03-25 05:42:27 -04:00
|
|
|
command := []string{
|
|
|
|
path,
|
|
|
|
fmt.Sprintf("--cloud-provider=%s", cloudProvider),
|
|
|
|
"--leader-elect=true",
|
2022-05-24 04:04:42 -04:00
|
|
|
fmt.Sprintf("--cluster-cidr=%s", podCIDR),
|
2022-03-25 05:42:27 -04:00
|
|
|
"-v=2",
|
|
|
|
}
|
|
|
|
command = append(command, extraArgs...)
|
|
|
|
volumes := []k8s.Volume{
|
|
|
|
{
|
|
|
|
Name: "etckubernetes",
|
|
|
|
VolumeSource: k8s.VolumeSource{
|
|
|
|
HostPath: &k8s.HostPathVolumeSource{Path: "/etc/kubernetes"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "etcssl",
|
|
|
|
VolumeSource: k8s.VolumeSource{
|
|
|
|
HostPath: &k8s.HostPathVolumeSource{Path: "/etc/ssl"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Name: "etcpki",
|
|
|
|
VolumeSource: k8s.VolumeSource{
|
|
|
|
HostPath: &k8s.HostPathVolumeSource{Path: "/etc/pki"},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
volumes = append(volumes, extraVolumes...)
|
|
|
|
volumeMounts := []k8s.VolumeMount{
|
|
|
|
{
|
|
|
|
MountPath: "/etc/kubernetes",
|
|
|
|
Name: "etckubernetes",
|
|
|
|
ReadOnly: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
MountPath: "/etc/ssl",
|
|
|
|
Name: "etcssl",
|
|
|
|
ReadOnly: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
MountPath: "/etc/pki",
|
|
|
|
Name: "etcpki",
|
|
|
|
ReadOnly: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
volumeMounts = append(volumeMounts, extraVolumeMounts...)
|
|
|
|
|
2022-10-05 09:02:46 -04:00
|
|
|
return &CloudControllerManagerDeployment{
|
2022-03-22 11:03:15 -04:00
|
|
|
ServiceAccount: k8s.ServiceAccount{
|
|
|
|
TypeMeta: meta.TypeMeta{
|
|
|
|
APIVersion: "v1",
|
|
|
|
Kind: "ServiceAccount",
|
|
|
|
},
|
|
|
|
ObjectMeta: meta.ObjectMeta{
|
|
|
|
Name: "cloud-controller-manager",
|
|
|
|
Namespace: "kube-system",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
ClusterRoleBinding: rbac.ClusterRoleBinding{
|
|
|
|
TypeMeta: meta.TypeMeta{
|
|
|
|
APIVersion: "rbac.authorization.k8s.io/v1",
|
|
|
|
Kind: "ClusterRoleBinding",
|
|
|
|
},
|
|
|
|
ObjectMeta: meta.ObjectMeta{
|
|
|
|
Name: "system:cloud-controller-manager",
|
|
|
|
},
|
|
|
|
RoleRef: rbac.RoleRef{
|
|
|
|
APIGroup: "rbac.authorization.k8s.io",
|
|
|
|
Kind: "ClusterRole",
|
|
|
|
Name: "cluster-admin",
|
|
|
|
},
|
|
|
|
Subjects: []rbac.Subject{
|
|
|
|
{
|
|
|
|
Kind: "ServiceAccount",
|
|
|
|
Name: "cloud-controller-manager",
|
|
|
|
Namespace: "kube-system",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
DaemonSet: apps.DaemonSet{
|
|
|
|
TypeMeta: meta.TypeMeta{
|
|
|
|
APIVersion: "apps/v1",
|
|
|
|
Kind: "DaemonSet",
|
|
|
|
},
|
|
|
|
ObjectMeta: meta.ObjectMeta{
|
|
|
|
Labels: map[string]string{
|
|
|
|
"k8s-app": "cloud-controller-manager",
|
|
|
|
},
|
|
|
|
Name: "cloud-controller-manager",
|
|
|
|
Namespace: "kube-system",
|
|
|
|
},
|
|
|
|
Spec: apps.DaemonSetSpec{
|
|
|
|
Selector: &meta.LabelSelector{
|
|
|
|
MatchLabels: map[string]string{
|
|
|
|
"k8s-app": "cloud-controller-manager",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Template: k8s.PodTemplateSpec{
|
|
|
|
ObjectMeta: meta.ObjectMeta{
|
|
|
|
Labels: map[string]string{
|
|
|
|
"k8s-app": "cloud-controller-manager",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Spec: k8s.PodSpec{
|
|
|
|
ServiceAccountName: "cloud-controller-manager",
|
|
|
|
Containers: []k8s.Container{
|
|
|
|
{
|
2022-03-25 05:42:27 -04:00
|
|
|
Name: "cloud-controller-manager",
|
|
|
|
Image: image,
|
|
|
|
Command: command,
|
|
|
|
VolumeMounts: volumeMounts,
|
|
|
|
Env: env,
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
},
|
2022-03-25 05:42:27 -04:00
|
|
|
Volumes: volumes,
|
2022-03-22 11:03:15 -04:00
|
|
|
Tolerations: []k8s.Toleration{
|
|
|
|
{
|
|
|
|
Key: "node.cloudprovider.kubernetes.io/uninitialized",
|
|
|
|
Value: "true",
|
|
|
|
Effect: k8s.TaintEffectNoSchedule,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Key: "node-role.kubernetes.io/master",
|
|
|
|
Effect: k8s.TaintEffectNoSchedule,
|
|
|
|
},
|
2022-06-28 11:03:28 -04:00
|
|
|
{
|
|
|
|
Key: "node-role.kubernetes.io/control-plane",
|
|
|
|
Operator: k8s.TolerationOpExists,
|
|
|
|
Effect: k8s.TaintEffectNoSchedule,
|
|
|
|
},
|
2022-05-24 04:04:42 -04:00
|
|
|
{
|
|
|
|
Key: "node.kubernetes.io/not-ready",
|
|
|
|
Effect: k8s.TaintEffectNoSchedule,
|
|
|
|
},
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
NodeSelector: map[string]string{
|
2022-07-26 11:08:57 -04:00
|
|
|
"node-role.kubernetes.io/control-plane": "",
|
2022-03-22 11:03:15 -04:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-05 09:02:46 -04:00
|
|
|
func (c *CloudControllerManagerDeployment) Marshal() ([]byte, error) {
|
2022-08-29 08:30:20 -04:00
|
|
|
return kubernetes.MarshalK8SResources(c)
|
2022-03-22 11:03:15 -04:00
|
|
|
}
|