forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubevirt#11545 from ormergi/cloudinit-secret-creation
tests,cloud-init: Move secret creation to package
- Loading branch information
Showing
5 changed files
with
78 additions
and
75 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
load("@io_bazel_rules_go//go:def.bzl", "go_library") | ||
|
||
go_library( | ||
name = "go_default_library", | ||
srcs = ["secret.go"], | ||
importpath = "kubevirt.io/kubevirt/tests/libsecret", | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"//vendor/k8s.io/api/core/v1:go_default_library", | ||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library", | ||
], | ||
) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* This file is part of the KubeVirt project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* Copyright The KubeVirt Authors. | ||
* | ||
*/ | ||
|
||
package libsecret | ||
|
||
import ( | ||
kubev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// New return Secret of Opaque type with "kubevirt.io/secret" label | ||
func New(name string, data map[string][]byte) *kubev1.Secret { | ||
// secretLabel set this label to make the test suite namespace clean-up delete the secret on teardown | ||
const secretLabel = "kubevirt.io/secret" // #nosec G101 | ||
return &kubev1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: name, | ||
Labels: map[string]string{ | ||
secretLabel: name, | ||
}, | ||
}, | ||
Data: data, | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,10 +44,10 @@ import ( | |
"kubevirt.io/kubevirt/tests/exec" | ||
"kubevirt.io/kubevirt/tests/framework/kubevirt" | ||
"kubevirt.io/kubevirt/tests/libpod" | ||
"kubevirt.io/kubevirt/tests/libsecret" | ||
"kubevirt.io/kubevirt/tests/libvmifact" | ||
"kubevirt.io/kubevirt/tests/libwait" | ||
"kubevirt.io/kubevirt/tests/testsuite" | ||
"kubevirt.io/kubevirt/tests/util" | ||
|
||
v1 "kubevirt.io/api/core/v1" | ||
"kubevirt.io/client-go/kubecli" | ||
|
@@ -324,20 +324,10 @@ var _ = Describe("[rfe_id:151][crit:high][vendor:[email protected]][level:compon | |
|
||
// Store userdata as k8s secret | ||
By("Creating a user-data secret") | ||
secret := kubev1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: secretID, | ||
Namespace: vmi.Namespace, | ||
Labels: map[string]string{ | ||
util.SecretLabel: secretID, | ||
}, | ||
}, | ||
Type: "Opaque", | ||
Data: map[string][]byte{ | ||
"userdata": []byte(userData), // The client encrypts the secret for us | ||
}, | ||
} | ||
_, err := virtClient.CoreV1().Secrets(vmi.Namespace).Create(context.Background(), &secret, metav1.CreateOptions{}) | ||
secret := libsecret.New(secretID, map[string][]byte{ | ||
"userdata": []byte(userData), | ||
}) | ||
_, err := virtClient.CoreV1().Secrets(vmi.Namespace).Create(context.Background(), secret, metav1.CreateOptions{}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
break | ||
} | ||
|
@@ -405,21 +395,10 @@ var _ = Describe("[rfe_id:151][crit:high][vendor:[email protected]][level:compon | |
|
||
// Store cloudinit data as k8s secret | ||
By("Creating a secret with network data") | ||
secret := kubev1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: secretID, | ||
Namespace: vmi.Namespace, | ||
Labels: map[string]string{ | ||
util.SecretLabel: secretID, | ||
}, | ||
}, | ||
Type: "Opaque", | ||
Data: map[string][]byte{ | ||
// The client encrypts the secret for us | ||
"networkdata": []byte(testNetworkData), | ||
}, | ||
} | ||
_, err := virtClient.CoreV1().Secrets(vmi.Namespace).Create(context.Background(), &secret, metav1.CreateOptions{}) | ||
secret := libsecret.New(secretID, map[string][]byte{ | ||
"networkdata": []byte(testNetworkData), | ||
}) | ||
_, err := virtClient.CoreV1().Secrets(vmi.Namespace).Create(context.Background(), secret, metav1.CreateOptions{}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
break | ||
|
@@ -548,21 +527,11 @@ var _ = Describe("[rfe_id:151][crit:high][vendor:[email protected]][level:compon | |
|
||
// Store cloudinit data as k8s secret | ||
By("Creating a secret with user and network data") | ||
secret := kubev1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: secretID, | ||
Namespace: vmi.Namespace, | ||
Labels: map[string]string{ | ||
util.SecretLabel: secretID, | ||
}, | ||
}, | ||
Type: "Opaque", | ||
Data: map[string][]byte{ | ||
// The client encrypts the secret for us | ||
"networkdata": []byte(testNetworkData), | ||
}, | ||
} | ||
_, err := virtClient.CoreV1().Secrets(vmi.Namespace).Create(context.Background(), &secret, metav1.CreateOptions{}) | ||
secret := libsecret.New(secretID, map[string][]byte{ | ||
"networkdata": []byte(testNetworkData), | ||
}) | ||
|
||
_, err := virtClient.CoreV1().Secrets(vmi.Namespace).Create(context.Background(), secret, metav1.CreateOptions{}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
break | ||
|
@@ -606,39 +575,19 @@ var _ = Describe("[rfe_id:151][crit:high][vendor:[email protected]][level:compon | |
|
||
// Store cloudinit data as k8s secret | ||
By("Creating a secret with userdata") | ||
uSecret := kubev1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: uSecretID, | ||
Namespace: vmi.Namespace, | ||
Labels: map[string]string{ | ||
util.SecretLabel: uSecretID, | ||
}, | ||
}, | ||
Type: "Opaque", | ||
Data: map[string][]byte{ | ||
// The client encrypts the secret for us | ||
userDataLabel: []byte(testUserData), | ||
}, | ||
} | ||
uSecret := libsecret.New(uSecretID, map[string][]byte{ | ||
userDataLabel: []byte(testUserData), | ||
}) | ||
|
||
By("Creating a secret with network data") | ||
nSecret := kubev1.Secret{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: nSecretID, | ||
Namespace: vmi.Namespace, | ||
Labels: map[string]string{ | ||
util.SecretLabel: nSecretID, | ||
}, | ||
}, | ||
Type: "Opaque", | ||
Data: map[string][]byte{ | ||
// The client encrypts the secret for us | ||
networkDataLabel: []byte(testNetworkData), | ||
}, | ||
} | ||
_, err := virtClient.CoreV1().Secrets(vmi.Namespace).Create(context.Background(), &uSecret, metav1.CreateOptions{}) | ||
nSecret := libsecret.New(nSecretID, map[string][]byte{ | ||
networkDataLabel: []byte(testNetworkData), | ||
}) | ||
|
||
_, err := virtClient.CoreV1().Secrets(vmi.Namespace).Create(context.Background(), uSecret, metav1.CreateOptions{}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
_, err = virtClient.CoreV1().Secrets(vmi.Namespace).Create(context.Background(), &nSecret, metav1.CreateOptions{}) | ||
_, err = virtClient.CoreV1().Secrets(vmi.Namespace).Create(context.Background(), nSecret, metav1.CreateOptions{}) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
break | ||
|