Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
tests(e2e): Create ServiceAccount for Vault (#3571)
Browse files Browse the repository at this point in the history
Signed-off-by: Kalya Subramanian <[email protected]>
(cherry picked from commit c298f7b)
  • Loading branch information
ksubrmnn authored and mergify-bot committed Jul 27, 2021
1 parent e53260c commit f909c4f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
26 changes: 18 additions & 8 deletions tests/framework/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,29 +736,39 @@ func (td *OsmTestData) LoadOSMImagesIntoKind() error {

func (td *OsmTestData) installVault(instOpts InstallOSMOpts) error {
td.T.Log("Installing Vault")

appName := "vault"
replicas := int32(1)
terminationGracePeriodSeconds := int64(10)

serviceAccountDefinition := Td.SimpleServiceAccount(appName, td.OsmNamespace)
svcAccount, err := Td.CreateServiceAccount(serviceAccountDefinition.Namespace, &serviceAccountDefinition)
if err != nil {
return errors.Wrap(err, "failed to create vault service account")
}

vaultDep := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "vault",
Name: appName,
Labels: map[string]string{
"app": "vault",
"app": appName,
},
},
Spec: appsv1.DeploymentSpec{
Replicas: &replicas,
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
"app": "vault",
"app": appName,
},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": "vault",
"app": appName,
},
},
Spec: corev1.PodSpec{
ServiceAccountName: svcAccount.Name,
TerminationGracePeriodSeconds: &terminationGracePeriodSeconds,
Containers: []corev1.Container{
{
Expand Down Expand Up @@ -853,22 +863,22 @@ tail /dev/random;
},
},
}
_, err := td.Client.AppsV1().Deployments(instOpts.ControlPlaneNS).Create(context.TODO(), vaultDep, metav1.CreateOptions{})
_, err = td.Client.AppsV1().Deployments(instOpts.ControlPlaneNS).Create(context.TODO(), vaultDep, metav1.CreateOptions{})
if err != nil {
return errors.Wrap(err, "failed to create vault deployment")
}

vaultSvc := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: "vault",
Name: appName,
Labels: map[string]string{
"app": "vault",
"app": appName,
},
},
Spec: corev1.ServiceSpec{
Type: corev1.ServiceTypeLoadBalancer,
Selector: map[string]string{
"app": "vault",
"app": appName,
},
Ports: []corev1.ServicePort{
{
Expand Down
20 changes: 13 additions & 7 deletions tests/framework/common_apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,10 @@ type SimplePodAppDef struct {
AppProtocol string
}

// SimplePodApp creates returns a set of k8s typed definitions for a pod-based k8s definition.
// SimplePodApp returns a set of k8s typed definitions for a pod-based k8s definition.
// Includes Pod, Service and ServiceAccount types
func (td *OsmTestData) SimplePodApp(def SimplePodAppDef) (corev1.ServiceAccount, corev1.Pod, corev1.Service) {
serviceAccountDefinition := corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: def.Name,
Namespace: def.Namespace,
},
}
serviceAccountDefinition := Td.SimpleServiceAccount(def.Name, def.Namespace)

podDefinition := corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -251,6 +246,17 @@ func (td *OsmTestData) SimplePodApp(def SimplePodAppDef) (corev1.ServiceAccount,
return serviceAccountDefinition, podDefinition, serviceDefinition
}

// SimpleServiceAccount returns a k8s typed definition for a service account.
func (td *OsmTestData) SimpleServiceAccount(name string, namespace string) corev1.ServiceAccount {
serviceAccountDefinition := corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
},
}
return serviceAccountDefinition
}

// getKubernetesServerVersionNumber returns the version number in chunks, ex. v1.19.3 => [1, 19, 3]
func (td *OsmTestData) getKubernetesServerVersionNumber() ([]int, error) {
version, err := td.Client.Discovery().ServerVersion()
Expand Down

0 comments on commit f909c4f

Please sign in to comment.