mirror of
https://github.com/kairos-io/osbuilder.git
synced 2025-08-31 23:10:11 +00:00
1546 byoi (#88)
* Add fields to the CRDs Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * WIP Create test Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Refactor code to split in testable functions Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * WIP Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Do something actually useful in tests - Create a random namespace - Create an artifact - Check that CreateConfigmap doesn't error Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * WIP Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Refactor before each so that we can change the artifact object per test Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * WIP Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * WIP Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Run kaniko to build the Dockerfile Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Build the image from Dockerfile with kaniko Currently can build an image. For example apply these: ``` kind: Secret apiVersion: v1 metadata: name: mydockerfile stringData: Dockerfile: | FROM ubuntu RUN touch myfile --- kind: OSArtifact apiVersion: build.kairos.io/v1alpha2 metadata: name: hello-kairos spec: imageName: "quay.io/kairos/core-opensuse-leap:latest" baseImageDockerfile: name: "mydockerfile" key: "Dockerfile" iso: true ``` Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Clarify that convert-to-kairos is not yet implemented Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Remove implemented TODO Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * WIP Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Bump linting action Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Fix linting errors Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Bump it again Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Unexport function and run controller tests in CI Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Unexport the other one too Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Extract case to a function Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Split controller tests in a separate job so that they run on a fresh cluster and they run in parallel Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Remove non-implemented functionality Will happen as part of this: https://github.com/kairos-io/kairos/issues/1721 Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * go mod tidy Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> * Try to use a random (free) port in tests because sometimes we collide Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> --------- Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me>
This commit is contained in:
committed by
GitHub
parent
09058c0d69
commit
e55bd03800
@@ -18,6 +18,7 @@ package controllers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
@@ -292,6 +293,17 @@ func (r *OSArtifactReconciler) newBuilderPod(pvcName string, artifact *osbuilder
|
||||
},
|
||||
}
|
||||
|
||||
if artifact.Spec.BaseImageDockerfile != nil {
|
||||
podSpec.Volumes = append(podSpec.Volumes, corev1.Volume{
|
||||
Name: "dockerfile",
|
||||
VolumeSource: corev1.VolumeSource{
|
||||
Secret: &corev1.SecretVolumeSource{
|
||||
SecretName: artifact.Spec.BaseImageDockerfile.Name,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if artifact.Spec.CloudConfigRef != nil {
|
||||
podSpec.Volumes = append(podSpec.Volumes, corev1.Volume{
|
||||
Name: "cloudconfig",
|
||||
@@ -304,11 +316,40 @@ func (r *OSArtifactReconciler) newBuilderPod(pvcName string, artifact *osbuilder
|
||||
})
|
||||
}
|
||||
|
||||
for i := range artifact.Spec.ImagePullSecrets {
|
||||
podSpec.ImagePullSecrets = append(podSpec.ImagePullSecrets, artifact.Spec.ImagePullSecrets[i])
|
||||
podSpec.ImagePullSecrets = append(podSpec.ImagePullSecrets, artifact.Spec.ImagePullSecrets...)
|
||||
|
||||
podSpec.InitContainers = []corev1.Container{}
|
||||
// Base image can be:
|
||||
// - built from a dockerfile and converted to a kairos one
|
||||
// - built by converting an existing image to a kairos one
|
||||
// - a prebuilt kairos image
|
||||
if artifact.Spec.BaseImageDockerfile != nil {
|
||||
podSpec.InitContainers = append(podSpec.InitContainers, baseImageBuildContainers()...)
|
||||
} else if artifact.Spec.BaseImageName != "" { // Existing base image - non kairos
|
||||
podSpec.InitContainers = append(podSpec.InitContainers,
|
||||
unpackContainer("baseimage-non-kairos", r.ToolImage, artifact.Spec.BaseImageName))
|
||||
} else { // Existing Kairos base image
|
||||
podSpec.InitContainers = append(podSpec.InitContainers, unpackContainer("baseimage", r.ToolImage, artifact.Spec.ImageName))
|
||||
}
|
||||
|
||||
podSpec.InitContainers = []corev1.Container{unpackContainer("baseimage", r.ToolImage, artifact.Spec.ImageName)}
|
||||
// If base image was a non kairos one, either one we built with kaniko or prebuilt,
|
||||
// convert it to a Kairos one, in a best effort manner.
|
||||
if artifact.Spec.BaseImageDockerfile != nil || artifact.Spec.BaseImageName != "" {
|
||||
podSpec.InitContainers = append(podSpec.InitContainers,
|
||||
corev1.Container{
|
||||
ImagePullPolicy: corev1.PullAlways,
|
||||
Name: "convert-to-kairos",
|
||||
Image: "busybox",
|
||||
Command: []string{"/bin/echo"},
|
||||
Args: []string{"TODO"},
|
||||
VolumeMounts: []corev1.VolumeMount{
|
||||
{
|
||||
Name: "rootfs",
|
||||
MountPath: "/rootfs",
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
for i, bundle := range artifact.Spec.Bundles {
|
||||
podSpec.InitContainers = append(podSpec.InitContainers, unpackContainer(fmt.Sprint(i), r.ToolImage, bundle))
|
||||
@@ -352,3 +393,59 @@ func (r *OSArtifactReconciler) newBuilderPod(pvcName string, artifact *osbuilder
|
||||
func ptr[T any](val T) *T {
|
||||
return &val
|
||||
}
|
||||
|
||||
func baseImageBuildContainers() []corev1.Container {
|
||||
return []corev1.Container{
|
||||
corev1.Container{
|
||||
ImagePullPolicy: corev1.PullAlways,
|
||||
Name: "kaniko-build",
|
||||
Image: "gcr.io/kaniko-project/executor:latest",
|
||||
Args: []string{
|
||||
"--dockerfile", "dockerfile/Dockerfile",
|
||||
"--context", "dir://workspace",
|
||||
"--destination", "whatever", // We don't push, but it needs this
|
||||
"--tar-path", "/rootfs/image.tar",
|
||||
"--no-push",
|
||||
},
|
||||
VolumeMounts: []corev1.VolumeMount{
|
||||
{
|
||||
Name: "rootfs",
|
||||
MountPath: "/rootfs",
|
||||
},
|
||||
{
|
||||
Name: "dockerfile",
|
||||
MountPath: "/workspace/dockerfile",
|
||||
},
|
||||
},
|
||||
},
|
||||
corev1.Container{
|
||||
ImagePullPolicy: corev1.PullAlways,
|
||||
Name: "image-extractor",
|
||||
Image: "quay.io/luet/base",
|
||||
Args: []string{
|
||||
"util", "unpack", "--local", "file:////rootfs/image.tar", "/rootfs",
|
||||
},
|
||||
VolumeMounts: []corev1.VolumeMount{
|
||||
{
|
||||
Name: "rootfs",
|
||||
MountPath: "/rootfs",
|
||||
},
|
||||
},
|
||||
},
|
||||
corev1.Container{
|
||||
ImagePullPolicy: corev1.PullAlways,
|
||||
Name: "cleanup",
|
||||
Image: "busybox",
|
||||
Command: []string{"/bin/rm"},
|
||||
Args: []string{
|
||||
"/rootfs/image.tar",
|
||||
},
|
||||
VolumeMounts: []corev1.VolumeMount{
|
||||
{
|
||||
Name: "rootfs",
|
||||
MountPath: "/rootfs",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ package controllers
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
osbuilder "github.com/kairos-io/osbuilder/api/v1alpha2"
|
||||
batchv1 "k8s.io/api/batch/v1"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
@@ -99,41 +100,69 @@ func (r *OSArtifactReconciler) Reconcile(ctx context.Context, req ctrl.Request)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *OSArtifactReconciler) startBuild(ctx context.Context, artifact *osbuilder.OSArtifact) (ctrl.Result, error) {
|
||||
// generate configmap required for building a custom image
|
||||
// CreateConfigMap generates a configmap required for building a custom image
|
||||
func (r *OSArtifactReconciler) CreateConfigMap(ctx context.Context, artifact *osbuilder.OSArtifact) error {
|
||||
cm := r.genConfigMap(artifact)
|
||||
if cm.Labels == nil {
|
||||
cm.Labels = map[string]string{}
|
||||
}
|
||||
cm.Labels[artifactLabel] = artifact.Name
|
||||
if err := controllerutil.SetOwnerReference(artifact, cm, r.Scheme()); err != nil {
|
||||
return ctrl.Result{Requeue: true}, err
|
||||
return err
|
||||
}
|
||||
if err := r.Create(ctx, cm); err != nil && !apierrors.IsAlreadyExists(err) {
|
||||
return ctrl.Result{Requeue: true}, err
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *OSArtifactReconciler) createPVC(ctx context.Context, artifact *osbuilder.OSArtifact) (*corev1.PersistentVolumeClaim, error) {
|
||||
pvc := r.newArtifactPVC(artifact)
|
||||
if pvc.Labels == nil {
|
||||
pvc.Labels = map[string]string{}
|
||||
}
|
||||
pvc.Labels[artifactLabel] = artifact.Name
|
||||
if err := controllerutil.SetOwnerReference(artifact, pvc, r.Scheme()); err != nil {
|
||||
return ctrl.Result{Requeue: true}, err
|
||||
return pvc, err
|
||||
}
|
||||
if err := r.Create(ctx, pvc); err != nil {
|
||||
return ctrl.Result{Requeue: true}, err
|
||||
return pvc, err
|
||||
}
|
||||
|
||||
return pvc, nil
|
||||
}
|
||||
|
||||
func (r *OSArtifactReconciler) createBuilderPod(ctx context.Context, artifact *osbuilder.OSArtifact, pvc *corev1.PersistentVolumeClaim) (*corev1.Pod, error) {
|
||||
pod := r.newBuilderPod(pvc.Name, artifact)
|
||||
if pod.Labels == nil {
|
||||
pod.Labels = map[string]string{}
|
||||
}
|
||||
pod.Labels[artifactLabel] = artifact.Name
|
||||
if err := controllerutil.SetOwnerReference(artifact, pod, r.Scheme()); err != nil {
|
||||
return pod, err
|
||||
}
|
||||
|
||||
if err := r.Create(ctx, pod); err != nil {
|
||||
return pod, err
|
||||
}
|
||||
|
||||
return pod, nil
|
||||
}
|
||||
|
||||
func (r *OSArtifactReconciler) startBuild(ctx context.Context, artifact *osbuilder.OSArtifact) (ctrl.Result, error) {
|
||||
err := r.CreateConfigMap(ctx, artifact)
|
||||
if err != nil {
|
||||
return ctrl.Result{Requeue: true}, err
|
||||
}
|
||||
if err := r.Create(ctx, pod); err != nil {
|
||||
|
||||
pvc, err := r.createPVC(ctx, artifact)
|
||||
if err != nil {
|
||||
return ctrl.Result{Requeue: true}, err
|
||||
}
|
||||
|
||||
_, err = r.createBuilderPod(ctx, artifact, pvc)
|
||||
if err != nil {
|
||||
return ctrl.Result{Requeue: true}, err
|
||||
}
|
||||
|
||||
|
173
controllers/osartifact_controller_test.go
Normal file
173
controllers/osartifact_controller_test.go
Normal file
@@ -0,0 +1,173 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
osbuilder "github.com/kairos-io/osbuilder/api/v1alpha2"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/phayes/freeport"
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
|
||||
"k8s.io/client-go/dynamic"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
|
||||
"k8s.io/client-go/rest"
|
||||
ctrl "sigs.k8s.io/controller-runtime"
|
||||
)
|
||||
|
||||
var _ = Describe("OSArtifactReconciler", func() {
|
||||
var r *OSArtifactReconciler
|
||||
var artifact *osbuilder.OSArtifact
|
||||
var namespace string
|
||||
var restConfig *rest.Config
|
||||
var clientset *kubernetes.Clientset
|
||||
var err error
|
||||
|
||||
BeforeEach(func() {
|
||||
restConfig = ctrl.GetConfigOrDie()
|
||||
clientset, err = kubernetes.NewForConfig(restConfig)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
namespace = createRandomNamespace(clientset)
|
||||
|
||||
artifact = &osbuilder.OSArtifact{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
Kind: "OSArtifact",
|
||||
APIVersion: osbuilder.GroupVersion.String(),
|
||||
},
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: namespace,
|
||||
Name: randStringRunes(10),
|
||||
},
|
||||
}
|
||||
|
||||
scheme := runtime.NewScheme()
|
||||
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
|
||||
utilruntime.Must(osbuilder.AddToScheme(scheme))
|
||||
|
||||
metricsPort, err := freeport.GetFreePort()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
fmt.Printf("metricsPort = %+v\n", metricsPort)
|
||||
mgr, err := ctrl.NewManager(restConfig, ctrl.Options{
|
||||
Scheme: scheme,
|
||||
MetricsBindAddress: fmt.Sprintf("127.0.0.1:%d", metricsPort),
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
r = &OSArtifactReconciler{
|
||||
ToolImage: "quay.io/kairos/osbuilder-tools:latest",
|
||||
}
|
||||
err = (r).SetupWithManager(mgr)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
JustBeforeEach(func() {
|
||||
k8s := dynamic.NewForConfigOrDie(restConfig)
|
||||
artifacts := k8s.Resource(
|
||||
schema.GroupVersionResource{
|
||||
Group: osbuilder.GroupVersion.Group,
|
||||
Version: osbuilder.GroupVersion.Version,
|
||||
Resource: "osartifacts"}).Namespace(namespace)
|
||||
|
||||
uArtifact := unstructured.Unstructured{}
|
||||
uArtifact.Object, _ = runtime.DefaultUnstructuredConverter.ToUnstructured(artifact)
|
||||
resp, err := artifacts.Create(context.TODO(), &uArtifact, metav1.CreateOptions{})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
// Update the local object with the one fetched from k8s
|
||||
err = runtime.DefaultUnstructuredConverter.FromUnstructured(resp.Object, artifact)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
deleteNamepace(clientset, namespace)
|
||||
})
|
||||
|
||||
Describe("CreateConfigMap", func() {
|
||||
It("creates a ConfigMap with no error", func() {
|
||||
ctx := context.Background()
|
||||
err := r.CreateConfigMap(ctx, artifact)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
c, err := clientset.CoreV1().ConfigMaps(namespace).Get(context.TODO(), artifact.Name, metav1.GetOptions{})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(c).ToNot(BeNil())
|
||||
})
|
||||
})
|
||||
|
||||
Describe("CreateBuilderPod", func() {
|
||||
When("BaseImageDockerfile is set", func() {
|
||||
BeforeEach(func() {
|
||||
secretName := artifact.Name + "-dockerfile"
|
||||
|
||||
_, err := clientset.CoreV1().Secrets(namespace).Create(context.TODO(),
|
||||
&corev1.Secret{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: secretName,
|
||||
Namespace: namespace,
|
||||
},
|
||||
StringData: map[string]string{
|
||||
"Dockerfile": "FROM ubuntu",
|
||||
},
|
||||
Type: "Opaque",
|
||||
}, metav1.CreateOptions{})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
artifact.Spec.BaseImageDockerfile = &osbuilder.SecretKeySelector{
|
||||
Name: secretName,
|
||||
Key: "Dockerfile",
|
||||
}
|
||||
|
||||
// Whatever, just to let it work
|
||||
artifact.Spec.ImageName = "quay.io/kairos-ci/" + artifact.Name + ":latest"
|
||||
})
|
||||
|
||||
It("creates an Init Container to build the image", func() {
|
||||
pvc, err := r.createPVC(context.TODO(), artifact)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
pod, err := r.createBuilderPod(context.TODO(), artifact, pvc)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
By("checking if an init container was created")
|
||||
initContainerNames := []string{}
|
||||
for _, c := range pod.Spec.InitContainers {
|
||||
initContainerNames = append(initContainerNames, c.Name)
|
||||
}
|
||||
Expect(initContainerNames).To(ContainElement("kaniko-build"))
|
||||
|
||||
By("checking if init containers complete successfully")
|
||||
Eventually(func() bool {
|
||||
p, err := clientset.CoreV1().Pods(namespace).Get(context.TODO(), pod.Name, metav1.GetOptions{})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
var allReady = false
|
||||
if len(p.Status.InitContainerStatuses) > 0 {
|
||||
allReady = true
|
||||
}
|
||||
for _, c := range p.Status.InitContainerStatuses {
|
||||
allReady = allReady && c.Ready
|
||||
}
|
||||
|
||||
return allReady
|
||||
}, 2*time.Minute, 5*time.Second).Should(BeTrue())
|
||||
|
||||
// req := clientset.CoreV1().Pods(pod.Namespace).GetLogs(pod.Name, &v1.PodLogOptions{})
|
||||
// podLogs, err := req.Stream(context.TODO())
|
||||
// Expect(err).ToNot(HaveOccurred())
|
||||
// defer podLogs.Close()
|
||||
|
||||
// buf := new(bytes.Buffer)
|
||||
// _, err = io.Copy(buf, podLogs)
|
||||
// Expect(err).ToNot(HaveOccurred())
|
||||
// str := buf.String()
|
||||
// fmt.Printf("str = %+v\n", str)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
@@ -17,20 +17,24 @@ limitations under the License.
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"context"
|
||||
"math/rand"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/kubernetes/scheme"
|
||||
"k8s.io/client-go/rest"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/envtest"
|
||||
"sigs.k8s.io/controller-runtime/pkg/envtest/printer"
|
||||
logf "sigs.k8s.io/controller-runtime/pkg/log"
|
||||
"sigs.k8s.io/controller-runtime/pkg/log/zap"
|
||||
|
||||
buildv1alpha1 "github.com/kairos-io/osbuilder/api/v1alpha1"
|
||||
buildv1alpha2 "github.com/kairos-io/osbuilder/api/v1alpha2"
|
||||
//+kubebuilder:scaffold:imports
|
||||
)
|
||||
|
||||
@@ -43,10 +47,7 @@ var testEnv *envtest.Environment
|
||||
|
||||
func TestAPIs(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
|
||||
RunSpecsWithDefaultAndCustomReporters(t,
|
||||
"Controller Suite",
|
||||
[]Reporter{printer.NewlineReporter{}})
|
||||
RunSpecs(t, "Controller Suite")
|
||||
}
|
||||
|
||||
var _ = BeforeSuite(func() {
|
||||
@@ -64,7 +65,7 @@ var _ = BeforeSuite(func() {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(cfg).NotTo(BeNil())
|
||||
|
||||
err = buildv1alpha1.AddToScheme(scheme.Scheme)
|
||||
err = buildv1alpha2.AddToScheme(scheme.Scheme)
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
|
||||
//+kubebuilder:scaffold:scheme
|
||||
@@ -73,10 +74,36 @@ var _ = BeforeSuite(func() {
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
Expect(k8sClient).NotTo(BeNil())
|
||||
|
||||
}, 60)
|
||||
})
|
||||
|
||||
var _ = AfterSuite(func() {
|
||||
By("tearing down the test environment")
|
||||
err := testEnv.Stop()
|
||||
Expect(err).NotTo(HaveOccurred())
|
||||
})
|
||||
|
||||
func randStringRunes(n int) string {
|
||||
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyz")
|
||||
b := make([]rune, n)
|
||||
for i := range b {
|
||||
b[i] = letterRunes[rand.Intn(len(letterRunes))]
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func createRandomNamespace(clientset *kubernetes.Clientset) string {
|
||||
name := randStringRunes(10)
|
||||
_, err := clientset.CoreV1().Namespaces().Create(context.Background(), &v1.Namespace{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: name,
|
||||
},
|
||||
}, metav1.CreateOptions{})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
return name
|
||||
}
|
||||
|
||||
func deleteNamepace(clientset *kubernetes.Clientset, name string) {
|
||||
err := clientset.CoreV1().Namespaces().Delete(context.Background(), name, metav1.DeleteOptions{})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
Reference in New Issue
Block a user