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

Update status once installation CR is written #668

Merged
merged 3 commits into from
Jul 10, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions pkg/controller/installation/core_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"fmt"
"net"
"os"
"reflect"
"strings"
"time"

Expand Down Expand Up @@ -426,6 +427,16 @@ func (r *ReconcileInstallation) Reconcile(request reconcile.Request) (reconcile.

ctx := context.Background()

// Get the installation object if it exists so that we can save the original
// status before we merge/fill that object with other values.
instance := &operator.Installation{}
if err := r.client.Get(ctx, utils.DefaultInstanceKey, instance); err != nil && apierrors.IsNotFound(err) {
tmjd marked this conversation as resolved.
Show resolved Hide resolved
reqLogger.Info("Installation config not found")
r.status.OnCRNotFound()
return reconcile.Result{}, nil
}
status := instance.Status

// Query for the installation object.
instance, err := GetInstallation(ctx, r.client, r.autoDetectedProvider)
if err != nil {
Expand Down Expand Up @@ -456,6 +467,17 @@ func (r *ReconcileInstallation) Reconcile(request reconcile.Request) (reconcile.
return reconcile.Result{}, err
}

// A status is needed at this point for operator scorecard tests.
// status.variant is written later but for some tests the reconciliation
// does not get to that point.
if reflect.DeepEqual(status, operator.InstallationStatus{}) {
tmjd marked this conversation as resolved.
Show resolved Hide resolved
instance.Status = operator.InstallationStatus{}
if err = r.client.Status().Update(ctx, instance); err != nil {
r.SetDegraded("Failed to write default status", err, reqLogger)
return reconcile.Result{}, err
}
}

// The operator supports running in a "Calico only" mode so that it doesn't need to run TSEE specific controllers.
// If we are switching from this mode to one that enables TSEE, we need to restart the operator to enable the other controllers.
if !r.enterpriseCRDsExist && instance.Spec.Variant == operator.TigeraSecureEnterprise {
Expand Down
34 changes: 34 additions & 0 deletions test/mainline_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package test
import (
"context"
"fmt"
"reflect"
"strings"
"time"

Expand Down Expand Up @@ -125,6 +126,38 @@ var _ = Describe("Mainline component function tests", func() {

It("Should install resources for a CRD", func() {
stopChan := installResourceCRD(c, mgr)

instance := &operator.Installation{
TypeMeta: metav1.TypeMeta{Kind: "Installation", APIVersion: "operator.tigera.io/v1"},
ObjectMeta: metav1.ObjectMeta{Name: "default"},
}
By("Checking that the installation status is set correctly")
Eventually(func() error {
err := GetResource(c, instance)
if err != nil {
return err
}
if instance.Status.Variant != operator.Calico {
return fmt.Errorf("installation status not Calico yet")
}
return nil
}, 60*time.Second).Should(BeNil())

By("Checking that the installation status does not change")
Consistently(func() error {
tmjd marked this conversation as resolved.
Show resolved Hide resolved
err := GetResource(c, instance)
if err != nil {
return err
}
if reflect.DeepEqual(instance.Status, operator.InstallationStatus{}) {
return fmt.Errorf("installation status is empty")
}
if instance.Status.Variant != operator.Calico {
return fmt.Errorf("installation status was %v, expected: %v", instance.Status, operator.Calico)
}
return nil
}, 30*time.Second, 50*time.Millisecond).Should(BeNil())

defer close(stopChan)
})
})
Expand Down Expand Up @@ -236,6 +269,7 @@ func setupManager() (client.Client, manager.Manager) {
err = controller.AddToManager(mgr, options.AddOptions{
DetectedProvider: operator.ProviderNone,
EnterpriseCRDExists: true,
AmazonCRDExists: true,
tmjd marked this conversation as resolved.
Show resolved Hide resolved
})
Expect(err).NotTo(HaveOccurred())
return mgr.GetClient(), mgr
Expand Down