mirror of
https://github.com/kairos-io/osbuilder.git
synced 2025-06-27 23:46:54 +00:00
Merge pull request #62 from kairos-io/1477-fix-osbuilder-tests
Remove old parameters (no longer supported)
This commit is contained in:
commit
893de1cc1d
@ -38,7 +38,3 @@ spec:
|
|||||||
- "--health-probe-bind-address=:8081"
|
- "--health-probe-bind-address=:8081"
|
||||||
- "--metrics-bind-address=127.0.0.1:8080"
|
- "--metrics-bind-address=127.0.0.1:8080"
|
||||||
- "--leader-elect"
|
- "--leader-elect"
|
||||||
- "--copy-to-namespace=$(NGINX_NAMESPACE)"
|
|
||||||
- "--copy-role=$(ARTIFACT_COPIER_ROLE)"
|
|
||||||
- --copy-to-pod-label=app.kubernetes.io/name=osbuilder-nginx
|
|
||||||
- --copy-to-path="/usr/share/nginx/html"
|
|
||||||
|
@ -2,6 +2,8 @@ package e2e_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
osbuilder "github.com/kairos-io/osbuilder/api/v1alpha2"
|
osbuilder "github.com/kairos-io/osbuilder/api/v1alpha2"
|
||||||
. "github.com/onsi/ginkgo/v2"
|
. "github.com/onsi/ginkgo/v2"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
@ -16,48 +18,54 @@ import (
|
|||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
"k8s.io/client-go/dynamic"
|
"k8s.io/client-go/dynamic"
|
||||||
ctrl "sigs.k8s.io/controller-runtime"
|
ctrl "sigs.k8s.io/controller-runtime"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("ISO build test", func() {
|
var _ = Describe("ISO build test", func() {
|
||||||
k8s := dynamic.NewForConfigOrDie(ctrl.GetConfigOrDie())
|
|
||||||
scheme := runtime.NewScheme()
|
|
||||||
_ = osbuilder.AddToScheme(scheme)
|
|
||||||
|
|
||||||
var artifactName string
|
var artifactName string
|
||||||
artifacts := k8s.Resource(schema.GroupVersionResource{Group: osbuilder.GroupVersion.Group, Version: osbuilder.GroupVersion.Version, Resource: "osartifacts"}).Namespace("default")
|
var artifacts, pods, pvcs, jobs dynamic.ResourceInterface
|
||||||
pods := k8s.Resource(schema.GroupVersionResource{Group: corev1.GroupName, Version: corev1.SchemeGroupVersion.Version, Resource: "pods"}).Namespace("default")
|
var scheme *runtime.Scheme
|
||||||
pvcs := k8s.Resource(schema.GroupVersionResource{Group: corev1.GroupName, Version: corev1.SchemeGroupVersion.Version, Resource: "persistentvolumeclaims"}).Namespace("default")
|
var artifactLabelSelector labels.Selector
|
||||||
jobs := k8s.Resource(schema.GroupVersionResource{Group: batchv1.GroupName, Version: batchv1.SchemeGroupVersion.Version, Resource: "jobs"}).Namespace("default")
|
|
||||||
|
|
||||||
artifact := &osbuilder.OSArtifact{
|
BeforeEach(func() {
|
||||||
TypeMeta: metav1.TypeMeta{
|
k8s := dynamic.NewForConfigOrDie(ctrl.GetConfigOrDie())
|
||||||
Kind: "OSArtifact",
|
scheme = runtime.NewScheme()
|
||||||
APIVersion: osbuilder.GroupVersion.String(),
|
err := osbuilder.AddToScheme(scheme)
|
||||||
},
|
Expect(err).ToNot(HaveOccurred())
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
GenerateName: "simple-",
|
artifacts = k8s.Resource(schema.GroupVersionResource{Group: osbuilder.GroupVersion.Group, Version: osbuilder.GroupVersion.Version, Resource: "osartifacts"}).Namespace("default")
|
||||||
},
|
pods = k8s.Resource(schema.GroupVersionResource{Group: corev1.GroupName, Version: corev1.SchemeGroupVersion.Version, Resource: "pods"}).Namespace("default")
|
||||||
Spec: osbuilder.OSArtifactSpec{
|
pvcs = k8s.Resource(schema.GroupVersionResource{Group: corev1.GroupName, Version: corev1.SchemeGroupVersion.Version, Resource: "persistentvolumeclaims"}).Namespace("default")
|
||||||
ImageName: "quay.io/kairos/core-opensuse:latest",
|
jobs = k8s.Resource(schema.GroupVersionResource{Group: batchv1.GroupName, Version: batchv1.SchemeGroupVersion.Version, Resource: "jobs"}).Namespace("default")
|
||||||
ISO: true,
|
|
||||||
DiskSize: "",
|
artifact := &osbuilder.OSArtifact{
|
||||||
Exporters: []batchv1.JobSpec{
|
TypeMeta: metav1.TypeMeta{
|
||||||
{
|
Kind: "OSArtifact",
|
||||||
Template: corev1.PodTemplateSpec{
|
APIVersion: osbuilder.GroupVersion.String(),
|
||||||
Spec: corev1.PodSpec{
|
},
|
||||||
RestartPolicy: corev1.RestartPolicyNever,
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Containers: []corev1.Container{
|
GenerateName: "simple-",
|
||||||
{
|
},
|
||||||
Name: "test",
|
Spec: osbuilder.OSArtifactSpec{
|
||||||
Image: "debian:latest",
|
ImageName: "quay.io/kairos/core-opensuse:latest",
|
||||||
Command: []string{"bash"},
|
ISO: true,
|
||||||
Args: []string{"-xec", "[ -f /artifacts/*.iso ]"},
|
DiskSize: "",
|
||||||
VolumeMounts: []corev1.VolumeMount{
|
Exporters: []batchv1.JobSpec{
|
||||||
{
|
{
|
||||||
Name: "artifacts",
|
Template: corev1.PodTemplateSpec{
|
||||||
ReadOnly: true,
|
Spec: corev1.PodSpec{
|
||||||
MountPath: "/artifacts",
|
RestartPolicy: corev1.RestartPolicyNever,
|
||||||
|
Containers: []corev1.Container{
|
||||||
|
{
|
||||||
|
Name: "test",
|
||||||
|
Image: "debian:latest",
|
||||||
|
Command: []string{"bash"},
|
||||||
|
Args: []string{"-xec", "[ -f /artifacts/*.iso ]"},
|
||||||
|
VolumeMounts: []corev1.VolumeMount{
|
||||||
|
{
|
||||||
|
Name: "artifacts",
|
||||||
|
ReadOnly: true,
|
||||||
|
MountPath: "/artifacts",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -66,92 +74,89 @@ var _ = Describe("ISO build test", func() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
}
|
|
||||||
|
|
||||||
uArtifact := unstructured.Unstructured{}
|
uArtifact := unstructured.Unstructured{}
|
||||||
uArtifact.Object, _ = runtime.DefaultUnstructuredConverter.ToUnstructured(artifact)
|
uArtifact.Object, _ = runtime.DefaultUnstructuredConverter.ToUnstructured(artifact)
|
||||||
resp, err := artifacts.Create(context.TODO(), &uArtifact, metav1.CreateOptions{})
|
resp, err := artifacts.Create(context.TODO(), &uArtifact, metav1.CreateOptions{})
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
artifactName = resp.GetName()
|
artifactName = resp.GetName()
|
||||||
|
|
||||||
Context("simple", func() {
|
artifactLabelSelectorReq, err := labels.NewRequirement("build.kairos.io/artifact", selection.Equals, []string{artifactName})
|
||||||
artifactLabelSelectorReq, _ := labels.NewRequirement("build.kairos.io/artifact", selection.Equals, []string{artifactName})
|
Expect(err).ToNot(HaveOccurred())
|
||||||
artifactLabelSelector := labels.NewSelector().Add(*artifactLabelSelectorReq)
|
artifactLabelSelector = labels.NewSelector().Add(*artifactLabelSelectorReq)
|
||||||
|
})
|
||||||
|
|
||||||
It("starts the build", func() {
|
It("works", func() {
|
||||||
Eventually(func(g Gomega) {
|
By("starting the build")
|
||||||
w, err := pods.Watch(context.TODO(), metav1.ListOptions{LabelSelector: artifactLabelSelector.String()})
|
Eventually(func(g Gomega) {
|
||||||
Expect(err).ToNot(HaveOccurred())
|
w, err := pods.Watch(context.TODO(), metav1.ListOptions{LabelSelector: artifactLabelSelector.String()})
|
||||||
|
|
||||||
var stopped bool
|
|
||||||
for !stopped {
|
|
||||||
event, ok := <-w.ResultChan()
|
|
||||||
|
|
||||||
stopped = event.Type != watch.Deleted && event.Type != watch.Error || !ok
|
|
||||||
}
|
|
||||||
}).WithTimeout(time.Hour).Should(Succeed())
|
|
||||||
})
|
|
||||||
|
|
||||||
It("exports the artifacts", func() {
|
|
||||||
Eventually(func(g Gomega) {
|
|
||||||
w, err := jobs.Watch(context.TODO(), metav1.ListOptions{LabelSelector: artifactLabelSelector.String()})
|
|
||||||
Expect(err).ToNot(HaveOccurred())
|
|
||||||
|
|
||||||
var stopped bool
|
|
||||||
for !stopped {
|
|
||||||
event, ok := <-w.ResultChan()
|
|
||||||
|
|
||||||
stopped = event.Type != watch.Deleted && event.Type != watch.Error || !ok
|
|
||||||
}
|
|
||||||
}).WithTimeout(time.Hour).Should(Succeed())
|
|
||||||
})
|
|
||||||
|
|
||||||
It("artifact successfully builds", func() {
|
|
||||||
Eventually(func(g Gomega) {
|
|
||||||
w, err := artifacts.Watch(context.TODO(), metav1.ListOptions{})
|
|
||||||
Expect(err).ToNot(HaveOccurred())
|
|
||||||
|
|
||||||
var artifact osbuilder.OSArtifact
|
|
||||||
var stopped bool
|
|
||||||
for !stopped {
|
|
||||||
event, ok := <-w.ResultChan()
|
|
||||||
stopped = !ok
|
|
||||||
|
|
||||||
if event.Type == watch.Modified && event.Object.(*unstructured.Unstructured).GetName() == artifactName {
|
|
||||||
err := scheme.Convert(event.Object, &artifact, nil)
|
|
||||||
Expect(err).ToNot(HaveOccurred())
|
|
||||||
stopped = artifact.Status.Phase == osbuilder.Ready
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}).WithTimeout(time.Hour).Should(Succeed())
|
|
||||||
})
|
|
||||||
|
|
||||||
It("cleans up resources on deleted", func() {
|
|
||||||
err := artifacts.Delete(context.TODO(), artifactName, metav1.DeleteOptions{})
|
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
Eventually(func(g Gomega) int {
|
var stopped bool
|
||||||
res, err := artifacts.List(context.TODO(), metav1.ListOptions{})
|
for !stopped {
|
||||||
Expect(err).ToNot(HaveOccurred())
|
event, ok := <-w.ResultChan()
|
||||||
return len(res.Items)
|
|
||||||
}).WithTimeout(time.Minute).Should(Equal(0))
|
stopped = event.Type != watch.Deleted && event.Type != watch.Error || !ok
|
||||||
Eventually(func(g Gomega) int {
|
}
|
||||||
res, err := pods.List(context.TODO(), metav1.ListOptions{LabelSelector: artifactLabelSelector.String()})
|
}).WithTimeout(time.Hour).Should(Succeed())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
|
||||||
return len(res.Items)
|
By("exporting the artifacts")
|
||||||
}).WithTimeout(time.Minute).Should(Equal(0))
|
Eventually(func(g Gomega) {
|
||||||
Eventually(func(g Gomega) int {
|
w, err := jobs.Watch(context.TODO(), metav1.ListOptions{LabelSelector: artifactLabelSelector.String()})
|
||||||
res, err := pvcs.List(context.TODO(), metav1.ListOptions{LabelSelector: artifactLabelSelector.String()})
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(err).ToNot(HaveOccurred())
|
|
||||||
return len(res.Items)
|
var stopped bool
|
||||||
}).WithTimeout(time.Minute).Should(Equal(0))
|
for !stopped {
|
||||||
Eventually(func(g Gomega) int {
|
event, ok := <-w.ResultChan()
|
||||||
res, err := jobs.List(context.TODO(), metav1.ListOptions{LabelSelector: artifactLabelSelector.String()})
|
|
||||||
Expect(err).ToNot(HaveOccurred())
|
stopped = event.Type != watch.Deleted && event.Type != watch.Error || !ok
|
||||||
return len(res.Items)
|
}
|
||||||
}).WithTimeout(time.Minute).Should(Equal(0))
|
}).WithTimeout(time.Hour).Should(Succeed())
|
||||||
})
|
|
||||||
|
By("building the artifacts successfully")
|
||||||
|
Eventually(func(g Gomega) {
|
||||||
|
w, err := artifacts.Watch(context.TODO(), metav1.ListOptions{})
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
var artifact osbuilder.OSArtifact
|
||||||
|
var stopped bool
|
||||||
|
for !stopped {
|
||||||
|
event, ok := <-w.ResultChan()
|
||||||
|
stopped = !ok
|
||||||
|
|
||||||
|
if event.Type == watch.Modified && event.Object.(*unstructured.Unstructured).GetName() == artifactName {
|
||||||
|
err := scheme.Convert(event.Object, &artifact, nil)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
stopped = artifact.Status.Phase == osbuilder.Ready
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}).WithTimeout(time.Hour).Should(Succeed())
|
||||||
|
|
||||||
|
By("cleaning up resources on deletion")
|
||||||
|
err := artifacts.Delete(context.TODO(), artifactName, metav1.DeleteOptions{})
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
Eventually(func(g Gomega) int {
|
||||||
|
res, err := artifacts.List(context.TODO(), metav1.ListOptions{})
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
return len(res.Items)
|
||||||
|
}).WithTimeout(time.Minute).Should(Equal(0))
|
||||||
|
Eventually(func(g Gomega) int {
|
||||||
|
res, err := pods.List(context.TODO(), metav1.ListOptions{LabelSelector: artifactLabelSelector.String()})
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
return len(res.Items)
|
||||||
|
}).WithTimeout(time.Minute).Should(Equal(0))
|
||||||
|
Eventually(func(g Gomega) int {
|
||||||
|
res, err := pvcs.List(context.TODO(), metav1.ListOptions{LabelSelector: artifactLabelSelector.String()})
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
return len(res.Items)
|
||||||
|
}).WithTimeout(time.Minute).Should(Equal(0))
|
||||||
|
Eventually(func(g Gomega) int {
|
||||||
|
res, err := jobs.List(context.TODO(), metav1.ListOptions{LabelSelector: artifactLabelSelector.String()})
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
return len(res.Items)
|
||||||
|
}).WithTimeout(time.Minute).Should(Equal(0))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user