hybrid deploy

Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
This commit is contained in:
Lyndon-Li
2024-11-26 19:21:23 +08:00
parent ff6ea15796
commit 0ea4eb563a
5 changed files with 58 additions and 5 deletions

View File

@@ -57,8 +57,13 @@ func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1.DaemonSet {
userID := int64(0)
mountPropagationMode := corev1.MountPropagationHostToContainer
dsName := "node-agent"
if c.forWindows {
dsName = "node-agent-windows"
}
daemonSet := &appsv1.DaemonSet{
ObjectMeta: objectMeta(namespace, "node-agent"),
ObjectMeta: objectMeta(namespace, dsName),
TypeMeta: metav1.TypeMeta{
Kind: "DaemonSet",
APIVersion: appsv1.SchemeGroupVersion.String(),
@@ -66,13 +71,14 @@ func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1.DaemonSet {
Spec: appsv1.DaemonSetSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"name": "node-agent",
"name": dsName,
},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: podLabels(c.labels, map[string]string{
"name": "node-agent",
"name": dsName,
"role": "node-agent",
}),
Annotations: c.annotations,
},
@@ -107,7 +113,7 @@ func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1.DaemonSet {
},
Containers: []corev1.Container{
{
Name: "node-agent",
Name: dsName,
Image: c.image,
Ports: containerPorts(),
ImagePullPolicy: pullPolicy,
@@ -205,6 +211,24 @@ func DaemonSet(namespace string, opts ...podTemplateOption) *appsv1.DaemonSet {
}...)
}
if c.forWindows {
daemonSet.Spec.Template.Spec.SecurityContext = nil
daemonSet.Spec.Template.Spec.Containers[0].SecurityContext = nil
daemonSet.Spec.Template.Spec.NodeSelector = map[string]string{
"kubernetes.io/os": "windows",
}
daemonSet.Spec.Template.Spec.OS = &corev1.PodOS{
Name: "windows",
}
} else {
daemonSet.Spec.Template.Spec.NodeSelector = map[string]string{
"kubernetes.io/os": "linux",
}
daemonSet.Spec.Template.Spec.OS = &corev1.PodOS{
Name: "linux",
}
}
daemonSet.Spec.Template.Spec.Containers[0].Env = append(daemonSet.Spec.Template.Spec.Containers[0].Env, c.envVars...)
return daemonSet

View File

@@ -58,6 +58,7 @@ type podTemplateConfig struct {
repoMaintenanceJobConfigMap string
nodeAgentConfigMap string
itemBlockWorkerCount int
forWindows bool
}
func WithImage(image string) podTemplateOption {
@@ -219,6 +220,12 @@ func WithItemBlockWorkerCount(itemBlockWorkerCount int) podTemplateOption {
}
}
func WithForWinows() podTemplateOption {
return func(c *podTemplateConfig) {
c.forWindows = true
}
}
func Deployment(namespace string, opts ...podTemplateOption) *appsv1.Deployment {
// TODO: Add support for server args
c := &podTemplateConfig{

View File

@@ -418,6 +418,13 @@ func AllResources(o *VeleroOptions) *unstructured.UnstructuredList {
if err := appendUnstructured(resources, ds); err != nil {
fmt.Printf("error appending DaemonSet %s: %s\n", ds.GetName(), err.Error())
}
dsOpts = append(dsOpts, WithForWinows())
dsWin := DaemonSet(o.Namespace, dsOpts...)
if err := appendUnstructured(resources, dsWin); err != nil {
fmt.Printf("error appending DaemonSet %s: %s\n", dsWin.GetName(), err.Error())
}
}
return resources