Skip to content

Commit

Permalink
hybrid deploy
Browse files Browse the repository at this point in the history
Signed-off-by: Lyndon-Li <lyonghui@vmware.com>
  • Loading branch information
Lyndon-Li committed Dec 10, 2024
1 parent ff6ea15 commit 0ea4eb5
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
32 changes: 28 additions & 4 deletions pkg/install/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,28 @@ 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(),
},
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,
},
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions pkg/install/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type podTemplateConfig struct {
repoMaintenanceJobConfigMap string
nodeAgentConfigMap string
itemBlockWorkerCount int
forWindows bool
}

func WithImage(image string) podTemplateOption {
Expand Down Expand Up @@ -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{
Expand Down
7 changes: 7 additions & 0 deletions pkg/install/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions pkg/plugin/clientmgmt/process/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -153,6 +154,7 @@ func (r *registry) readPluginsDir(dir string) ([]string, error) {
}

if !executable(file) {
r.logger.Warnf("Searching plugin skip file %s, not executable, mode %v, ext %s", file.Name(), file.Mode(), strings.ToLower(filepath.Ext(file.Name())))
continue
}

Expand All @@ -163,6 +165,15 @@ func (r *registry) readPluginsDir(dir string) ([]string, error) {

// executable determines if a file is executable.
func executable(info os.FileInfo) bool {
return executableLinux(info) || executableWindows(info)
}

func executableWindows(info os.FileInfo) bool {
ext := strings.ToLower(filepath.Ext(info.Name()))
return (ext == ".exe")
}

func executableLinux(info os.FileInfo) bool {
/*
When we AND the mode with 0111:
Expand Down
6 changes: 5 additions & 1 deletion pkg/plugin/clientmgmt/process/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ func TestReadPluginsDir(t *testing.T) {
WithFileAndMode("/plugins/nonexecutable2", []byte("plugin2"), 0644).
WithFileAndMode("/plugins/executable3", []byte("plugin3"), 0755).
WithFileAndMode("/plugins/nested/executable4", []byte("plugin4"), 0755).
WithFileAndMode("/plugins/nested/nonexecutable5", []byte("plugin4"), 0644)
WithFileAndMode("/plugins/nested/nonexecutable5", []byte("plugin4"), 0644).
WithFileAndMode("/plugins/nested/win-exe1.exe", []byte("plugin4"), 0600).
WithFileAndMode("/plugins/nested/WIN-EXE2.EXE", []byte("plugin4"), 0600)

plugins, err := r.readPluginsDir(dir)
require.NoError(t, err)
Expand All @@ -123,6 +125,8 @@ func TestReadPluginsDir(t *testing.T) {
"/plugins/executable1",
"/plugins/executable3",
"/plugins/nested/executable4",
"/plugins/nested/win-exe1.exe",
"/plugins/nested/WIN-EXE2.EXE",
}

sort.Strings(plugins)
Expand Down

0 comments on commit 0ea4eb5

Please sign in to comment.