Created
March 29, 2022 16:33
-
-
Save eumel8/d35368b3fedf2450673fa67edd26de13 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package daemonset | |
import ( | |
"context" | |
"testing" | |
apps "k8s.io/api/apps/v1" | |
core "k8s.io/api/core/v1" | |
meta "k8s.io/apimachinery/pkg/apis/meta/v1" | |
"k8s.io/client-go/kubernetes/fake" | |
) | |
func TestDaemonset(t *testing.T) { | |
var ( | |
app = string("overlaytest") | |
image = string("mtr.external.otc.telekomcloud.com/mcsps/swiss-army-knife:latest") | |
graceperiod = int64(1) | |
user = int64(1000) | |
privledged = bool(true) | |
readonly = bool(true) | |
) | |
client := fake.NewSimpleClientset() | |
daemonset := &apps.DaemonSet{ | |
ObjectMeta: meta.ObjectMeta{ | |
Name: app, | |
}, | |
Spec: apps.DaemonSetSpec{ | |
Selector: &meta.LabelSelector{ | |
MatchLabels: map[string]string{ | |
"app": app, | |
}, | |
}, | |
Template: core.PodTemplateSpec{ | |
ObjectMeta: meta.ObjectMeta{ | |
Labels: map[string]string{ | |
"app": app, | |
}, | |
}, | |
Spec: core.PodSpec{ | |
Containers: []core.Container{ | |
{ | |
Args: []string{"tail -f /dev/null"}, | |
Command: []string{"sh", "-c"}, | |
Name: app, | |
Image: image, | |
ImagePullPolicy: "IfNotPresent", | |
SecurityContext: &core.SecurityContext{ | |
AllowPrivilegeEscalation: &privledged, | |
Privileged: &privledged, | |
ReadOnlyRootFilesystem: &readonly, | |
RunAsGroup: &user, | |
RunAsUser: &user, | |
}, | |
}, | |
}, | |
TerminationGracePeriodSeconds: &graceperiod, | |
Tolerations: []core.Toleration{{ | |
Operator: "Exists", | |
}}, | |
SecurityContext: &core.PodSecurityContext{ | |
FSGroup: &user, | |
}, | |
}, | |
}, | |
}, | |
} | |
result, err := client.AppsV1().DaemonSets("kube-system").Create(context.TODO(), daemonset, meta.CreateOptions{}) | |
if err != nil { | |
t.Fatalf("error injecting pod add: %v", err) | |
} | |
if daemonset.ObjectMeta.Name != result.ObjectMeta.Name { | |
t.Logf("Got from manifest: %v", daemonset.ObjectMeta.Name) | |
t.Logf("Got from result: %v", result.ObjectMeta.Name) | |
t.Fatalf("result and manifest are not the same") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment