Skip to content

Commit

Permalink
Merge pull request tigera#668 from lmm/lmm-status
Browse files Browse the repository at this point in the history
Update status once installation CR is written
  • Loading branch information
tmjd authored and lmm committed Aug 7, 2020
1 parent b612f7c commit 235ccc3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 8 deletions.
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 @@ -387,6 +388,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) {
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 @@ -417,6 +428,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{}) {
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.requiresTSEE && instance.Spec.Variant == operator.TigeraSecureEnterprise {
Expand Down
44 changes: 36 additions & 8 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 All @@ -40,7 +41,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"

"k8s.io/kubernetes/cmd/kubeadm/app/util/apiclient"
"k8s.io/kubernetes/cmd/kubeadm/app/util/apiclient"
)

var _ = Describe("Mainline component function tests", func() {
Expand Down Expand Up @@ -72,13 +73,13 @@ var _ = Describe("Mainline component function tests", func() {

// Clean up Calico data that might be left behind.
Eventually(func() error {
patchF := func(n *corev1.Node) {
for k, _ := range n.ObjectMeta.Annotations {
if strings.Contains(k, "projectcalico") {
delete(n.ObjectMeta.Annotations, k)
}
}
}
patchF := func(n *corev1.Node) {
for k, _ := range n.ObjectMeta.Annotations {
if strings.Contains(k, "projectcalico") {
delete(n.ObjectMeta.Annotations, k)
}
}
}

cs := kubernetes.NewForConfigOrDie(mgr.GetConfig())
nodes, err := cs.CoreV1().Nodes().List(metav1.ListOptions{})
Expand Down Expand Up @@ -171,6 +172,33 @@ var _ = Describe("Mainline component function tests", func() {
}
return assertAvailable(ts)
}, 60*time.Second).Should(BeNil())

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 {
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())
})
})

Expand Down

0 comments on commit 235ccc3

Please sign in to comment.