Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Avoid sspv1.KubevirtNodeLabellerBundle and cpu-plugin on SSP operator" #591

Merged
merged 1 commit into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 55 additions & 1 deletion pkg/controller/hyperconverged/hyperconverged_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func add(mgr manager.Manager, r reconcile.Reconciler) error {
&cdiv1alpha1.CDI{},
&networkaddonsv1alpha1.NetworkAddonsConfig{},
&sspv1.KubevirtCommonTemplatesBundle{},
&sspv1.KubevirtNodeLabellerBundle{},
&sspv1.KubevirtTemplateValidator{},
&sspv1.KubevirtMetricsAggregation{},
&schedulingv1.PriorityClass{},
Expand Down Expand Up @@ -414,7 +415,7 @@ func (r *ReconcileHyperConverged) ensureHco(req *hcoRequest) error {
r.ensureCDI,
r.ensureNetworkAddons,
r.ensureKubeVirtCommonTemplateBundle,
// r.ensureKubeVirtNodeLabellerBundle, // TODO: what is going to remove it on upgrades if deployed in the past???
r.ensureKubeVirtNodeLabellerBundle,
r.ensureKubeVirtTemplateValidator,
r.ensureKubeVirtMetricsAggregation,
r.ensureIMSConfig,
Expand Down Expand Up @@ -1145,6 +1146,59 @@ func (r *ReconcileHyperConverged) ensureKubeVirtCommonTemplateBundle(req *hcoReq
return r.client.Status().Update(req.ctx, req.instance)
}

func newKubeVirtNodeLabellerBundleForCR(cr *hcov1alpha1.HyperConverged, namespace string) *sspv1.KubevirtNodeLabellerBundle {
labels := map[string]string{
"app": cr.Name,
}
return &sspv1.KubevirtNodeLabellerBundle{
ObjectMeta: metav1.ObjectMeta{
Name: "node-labeller-" + cr.Name,
Labels: labels,
Namespace: namespace,
},
Spec: sspv1.ComponentSpec{
UseKVM: isKVMAvailable(),
},
}
}

func (r *ReconcileHyperConverged) ensureKubeVirtNodeLabellerBundle(req *hcoRequest) error {
kvNLB := newKubeVirtNodeLabellerBundleForCR(req.instance, req.Namespace)
if err := controllerutil.SetControllerReference(req.instance, kvNLB, r.scheme); err != nil {
return err
}

key, err := client.ObjectKeyFromObject(kvNLB)
if err != nil {
req.logger.Error(err, "Failed to get object key for KubeVirt Node Labeller Bundle")
}

found := &sspv1.KubevirtNodeLabellerBundle{}
err = r.client.Get(req.ctx, key, found)
if err != nil && apierrors.IsNotFound(err) {
req.logger.Info("Creating KubeVirt Node Labeller Bundle")
return r.client.Create(req.ctx, kvNLB)
}

if err != nil {
return err
}

req.logger.Info("KubeVirt Node Labeller Bundle already exists", "bundle.Namespace", found.Namespace, "bundle.Name", found.Name)

// Add it to the list of RelatedObjects if found
objectRef, err := reference.GetReference(r.scheme, found)
if err != nil {
return err
}
objectreferencesv1.SetObjectReference(&req.instance.Status.RelatedObjects, *objectRef)

// TODO: temporary avoid checking conditions on KubevirtNodeLabellerBundle because it's currently
// broken on k8s. Revert this when we will be able to fix it
//handleComponentConditions(r, req, "KubevirtNodeLabellerBundle", found.Status.Conditions)
return r.client.Status().Update(req.ctx, req.instance)
}

func newIMSConfigForCR(cr *hcov1alpha1.HyperConverged, namespace string) *corev1.ConfigMap {
labels := map[string]string{
"app": cr.Name,
Expand Down
166 changes: 163 additions & 3 deletions pkg/controller/hyperconverged/hyperconverged_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -803,6 +803,137 @@ var _ = Describe("HyperconvergedController", func() {
*/
})

Context("KubeVirtNodeLabellerBundle", func() {
var hco *hcov1alpha1.HyperConverged
var req *hcoRequest

BeforeEach(func() {
hco = newHco()
req = newReq(hco)
})

It("should create if not present", func() {
expectedResource := newKubeVirtNodeLabellerBundleForCR(hco, namespace)
cl := initClient([]runtime.Object{})
r := initReconciler(cl)
Expect(r.ensureKubeVirtNodeLabellerBundle(req)).To(BeNil())

foundResource := &sspv1.KubevirtNodeLabellerBundle{}
Expect(
cl.Get(context.TODO(),
types.NamespacedName{Name: expectedResource.Name, Namespace: expectedResource.Namespace},
foundResource),
).To(BeNil())
Expect(foundResource.Name).To(Equal(expectedResource.Name))
Expect(foundResource.Labels).Should(HaveKeyWithValue("app", name))
Expect(foundResource.Namespace).To(Equal(expectedResource.Namespace))
})

It("should find if present", func() {
expectedResource := newKubeVirtNodeLabellerBundleForCR(hco, namespace)
expectedResource.ObjectMeta.SelfLink = fmt.Sprintf("/apis/v1/namespaces/%s/dummies/%s", expectedResource.Namespace, expectedResource.Name)
cl := initClient([]runtime.Object{hco, expectedResource})
r := initReconciler(cl)
Expect(r.ensureKubeVirtNodeLabellerBundle(req)).To(BeNil())

// Check HCO's status
Expect(hco.Status.RelatedObjects).To(Not(BeNil()))
objectRef, err := reference.GetReference(r.scheme, expectedResource)
Expect(err).To(BeNil())
// ObjectReference should have been added
Expect(hco.Status.RelatedObjects).To(ContainElement(*objectRef))
})

// TODO: temporary avoid checking conditions on KubevirtNodeLabellerBundle because it's currently
// broken on k8s. Revert this when we will be able to fix it
/*
It("should handle conditions", func() {
expectedResource := newKubeVirtNodeLabellerBundleForCR(hco, namespace)
expectedResource.ObjectMeta.SelfLink = fmt.Sprintf("/apis/v1/namespaces/%s/dummies/%s", expectedResource.Namespace, expectedResource.Name)
expectedResource.Status.Conditions = []conditionsv1.Condition{
conditionsv1.Condition{
Type: conditionsv1.ConditionAvailable,
Status: corev1.ConditionFalse,
Reason: "Foo",
Message: "Bar",
},
conditionsv1.Condition{
Type: conditionsv1.ConditionProgressing,
Status: corev1.ConditionTrue,
Reason: "Foo",
Message: "Bar",
},
conditionsv1.Condition{
Type: conditionsv1.ConditionDegraded,
Status: corev1.ConditionTrue,
Reason: "Foo",
Message: "Bar",
},
}
cl := initClient([]runtime.Object{hco, expectedResource})
r := initReconciler(cl)
Expect(r.ensureKubeVirtNodeLabellerBundle(req)).To(BeNil())

// Check HCO's status
Expect(hco.Status.RelatedObjects).To(Not(BeNil()))
objectRef, err := reference.GetReference(r.scheme, expectedResource)
Expect(err).To(BeNil())
// ObjectReference should have been added
Expect(hco.Status.RelatedObjects).To(ContainElement(*objectRef))
// Check conditions
Expect(req.conditions[]).To(ContainElement(testlib.RepresentCondition(conditionsv1.Condition{
Type: conditionsv1.ConditionAvailable,
Status: corev1.ConditionFalse,
Reason: "KubevirtNodeLabellerBundleNotAvailable",
Message: "KubevirtNodeLabellerBundle is not available: Bar",
})))
Expect(req.conditions[]).To(ContainElement(testlib.RepresentCondition(conditionsv1.Condition{
Type: conditionsv1.ConditionProgressing,
Status: corev1.ConditionTrue,
Reason: "KubevirtNodeLabellerBundleProgressing",
Message: "KubevirtNodeLabellerBundle is progressing: Bar",
})))
Expect(req.conditions[]).To(ContainElement(testlib.RepresentCondition(conditionsv1.Condition{
Type: conditionsv1.ConditionUpgradeable,
Status: corev1.ConditionFalse,
Reason: "KubevirtNodeLabellerBundleProgressing",
Message: "KubevirtNodeLabellerBundle is progressing: Bar",
})))
Expect(req.conditions[]).To(ContainElement(testlib.RepresentCondition(conditionsv1.Condition{
Type: conditionsv1.ConditionDegraded,
Status: corev1.ConditionTrue,
Reason: "KubevirtNodeLabellerBundleDegraded",
Message: "KubevirtNodeLabellerBundle is degraded: Bar",
})))
})
*/

It("should request KVM without any extra setting", func() {
os.Unsetenv("KVM_EMULATION")

expectedResource := newKubeVirtNodeLabellerBundleForCR(hco, namespace)
Expect(expectedResource.Spec.UseKVM).To(BeTrue())
})

It("should not request KVM if emulation requested", func() {
err := os.Setenv("KVM_EMULATION", "true")
Expect(err).NotTo(HaveOccurred())
defer os.Unsetenv("KVM_EMULATION")

expectedResource := newKubeVirtNodeLabellerBundleForCR(hco, namespace)
Expect(expectedResource.Spec.UseKVM).To(BeFalse())
})

It("should request KVM if emulation value not set", func() {
err := os.Setenv("KVM_EMULATION", "")
Expect(err).NotTo(HaveOccurred())
defer os.Unsetenv("KVM_EMULATION")

expectedResource := newKubeVirtNodeLabellerBundleForCR(hco, namespace)
Expect(expectedResource.Spec.UseKVM).To(BeTrue())
})
})

Context("KubeVirtTemplateValidator", func() {
var hco *hcov1alpha1.HyperConverged
var req *hcoRequest
Expand Down Expand Up @@ -1061,10 +1192,12 @@ var _ = Describe("HyperconvergedController", func() {
expectedCNA.ObjectMeta.SelfLink = fmt.Sprintf("/apis/v1/namespaces/%s/cnas/%s", expectedCNA.Namespace, expectedCNA.Name)
expectedKVCTB := newKubeVirtCommonTemplateBundleForCR(hco, OpenshiftNamespace)
expectedKVCTB.ObjectMeta.SelfLink = fmt.Sprintf("/apis/v1/namespaces/%s/ctbs/%s", expectedKVCTB.Namespace, expectedKVCTB.Name)
expectedKVNLB := newKubeVirtNodeLabellerBundleForCR(hco, namespace)
expectedKVNLB.ObjectMeta.SelfLink = fmt.Sprintf("/apis/v1/namespaces/%s/nlb/%s", expectedKVNLB.Namespace, expectedKVNLB.Name)
expectedKVTV := newKubeVirtTemplateValidatorForCR(hco, namespace)
expectedKVTV.ObjectMeta.SelfLink = fmt.Sprintf("/apis/v1/namespaces/%s/tv/%s", expectedKVTV.Namespace, expectedKVTV.Name)
// Add all of the objects to the client
cl := initClient([]runtime.Object{hco, expectedKVConfig, expectedKVStorageConfig, expectedKV, expectedCDI, expectedCNA, expectedKVCTB, expectedKVTV})
cl := initClient([]runtime.Object{hco, expectedKVConfig, expectedKVStorageConfig, expectedKV, expectedCDI, expectedCNA, expectedKVCTB, expectedKVNLB, expectedKVTV})
r := initReconciler(cl)

// Do the reconcile
Expand Down Expand Up @@ -1185,11 +1318,14 @@ var _ = Describe("HyperconvergedController", func() {
expectedKVCTB := newKubeVirtCommonTemplateBundleForCR(hco, OpenshiftNamespace)
expectedKVCTB.ObjectMeta.SelfLink = fmt.Sprintf("/apis/v1/namespaces/%s/ctbs/%s", expectedKVCTB.Namespace, expectedKVCTB.Name)
expectedKVCTB.Status.Conditions = getGenericCompletedConditions()
expectedKVNLB := newKubeVirtNodeLabellerBundleForCR(hco, namespace)
expectedKVNLB.ObjectMeta.SelfLink = fmt.Sprintf("/apis/v1/namespaces/%s/nlb/%s", expectedKVNLB.Namespace, expectedKVNLB.Name)
expectedKVNLB.Status.Conditions = getGenericCompletedConditions()
expectedKVTV := newKubeVirtTemplateValidatorForCR(hco, namespace)
expectedKVTV.ObjectMeta.SelfLink = fmt.Sprintf("/apis/v1/namespaces/%s/tv/%s", expectedKVTV.Namespace, expectedKVTV.Name)
expectedKVTV.Status.Conditions = getGenericCompletedConditions()
// Add all of the objects to the client
cl := initClient([]runtime.Object{hco, expectedKVConfig, expectedKVStorageConfig, expectedKV, expectedCDI, expectedCNA, expectedKVCTB, expectedKVTV})
cl := initClient([]runtime.Object{hco, expectedKVConfig, expectedKVStorageConfig, expectedKV, expectedCDI, expectedCNA, expectedKVCTB, expectedKVNLB, expectedKVTV})
r := initReconciler(cl)

// Do the reconcile
Expand Down Expand Up @@ -1298,6 +1434,23 @@ var _ = Describe("HyperconvergedController", func() {
checkAvailability(foundResource, corev1.ConditionTrue)
*/

// TODO: temporary avoid checking conditions on KubevirtNodeLabellerBundle because it's currently
// broken on k8s. Revert this when we will be able to fix it
/*
origConds = expected.kvNlb.Status.Conditions
expected.kvNlb.Status.Conditions = expected.cdi.Status.Conditions[1:]
cl = expected.initClient()
foundResource, requeue = doReconcile(cl, expected.hco)
Expect(requeue).To(BeFalse())
checkAvailability(foundResource, corev1.ConditionFalse)

expected.kvNlb.Status.Conditions = origConds
cl = expected.initClient()
foundResource, requeue = doReconcile(cl, expected.hco)
Expect(requeue).To(BeFalse())
checkAvailability(foundResource, corev1.ConditionTrue)
*/

// TODO: temporary avoid checking conditions on KubevirtTemplateValidator because it's currently
// broken on k8s. Revert this when we will be able to fix it
/*
Expand Down Expand Up @@ -1334,7 +1487,7 @@ var _ = Describe("HyperconvergedController", func() {
).To(BeNil())

Expect(foundResource.Status.RelatedObjects).ToNot(BeNil())
Expect(len(foundResource.Status.RelatedObjects)).Should(Equal(7))
Expect(len(foundResource.Status.RelatedObjects)).Should(Equal(8))
Expect(foundResource.ObjectMeta.Finalizers).Should(Equal([]string{FinalizerName}))

// Now, delete HCO
Expand Down Expand Up @@ -1769,6 +1922,7 @@ type basicExpected struct {
cdi *cdiv1alpha1.CDI
cna *networkaddonsv1alpha1.NetworkAddonsConfig
kvCtb *sspv1.KubevirtCommonTemplatesBundle
kvNlb *sspv1.KubevirtNodeLabellerBundle
kvTv *sspv1.KubevirtTemplateValidator
}

Expand All @@ -1781,6 +1935,7 @@ func (be basicExpected) toArray() []runtime.Object {
be.cdi,
be.cna,
be.kvCtb,
be.kvNlb,
be.kvTv,
}
}
Expand Down Expand Up @@ -1855,6 +2010,11 @@ func getBasicDeployment() *basicExpected {
expectedKVCTB.Status.Conditions = getGenericCompletedConditions()
res.kvCtb = expectedKVCTB

expectedKVNLB := newKubeVirtNodeLabellerBundleForCR(hco, namespace)
expectedKVNLB.ObjectMeta.SelfLink = fmt.Sprintf("/apis/v1/namespaces/%s/nlb/%s", expectedKVNLB.Namespace, expectedKVNLB.Name)
expectedKVNLB.Status.Conditions = getGenericCompletedConditions()
res.kvNlb = expectedKVNLB

expectedKVTV := newKubeVirtTemplateValidatorForCR(hco, namespace)
expectedKVTV.ObjectMeta.SelfLink = fmt.Sprintf("/apis/v1/namespaces/%s/tv/%s", expectedKVTV.Namespace, expectedKVTV.Name)
expectedKVTV.Status.Conditions = getGenericCompletedConditions()
Expand Down