Skip to content

Commit

Permalink
Added basic status to CR{D}
Browse files Browse the repository at this point in the history
Signed-off-by: Juraci Paixão Kröhling <[email protected]>
  • Loading branch information
jpkrohling committed Dec 3, 2019
1 parent db1aa94 commit b690e2a
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
11 changes: 11 additions & 0 deletions deploy/crds/jaegertracing.io_jaegers_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,24 @@ kind: CustomResourceDefinition
metadata:
name: jaegers.jaegertracing.io
spec:
additionalPrinterColumns:
- JSONPath: .status.phase
description: Instance's status
name: Status
type: string
- JSONPath: .status.version
description: Jaeger Version
name: Version
type: string
group: jaegertracing.io
names:
kind: Jaeger
listKind: JaegerList
plural: jaegers
singular: jaeger
scope: Namespaced
subresources:
status: {}
version: v1
versions:
- name: v1
Expand Down
18 changes: 17 additions & 1 deletion pkg/apis/jaegertracing/v1/jaeger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
// +k8s:openapi-gen=true
type IngressSecurityType string

// JaegerPhase represents the current phase of Jaeger instances
// +k8s:openapi-gen=true
type JaegerPhase string

const (
// FlagPlatformKubernetes represents the value for the 'platform' flag for Kubernetes
// +k8s:openapi-gen=true
Expand Down Expand Up @@ -67,6 +71,14 @@ const (
// AnnotationProvisionedKafkaValue is a label to be added to Kafkas that have been provisioned by Jaeger
// +k8s:openapi-gen=true
AnnotationProvisionedKafkaValue string = "true"

// JaegerPhaseFailed indicates the overall phase of a failed Jaeger instance
// +k8s:openapi-gen=true
JaegerPhaseFailed JaegerPhase = "Failed"

// JaegerPhaseRunning indicates the overall phase of a running Jaeger instance
// +k8s:openapi-gen=true
JaegerPhaseRunning JaegerPhase = "Running"
)

// JaegerSpec defines the desired state of Jaeger
Expand Down Expand Up @@ -109,13 +121,17 @@ type JaegerSpec struct {
// JaegerStatus defines the observed state of Jaeger
// +k8s:openapi-gen=true
type JaegerStatus struct {
Version string `json:"version"`
Version string `json:"version"`
Phase JaegerPhase `json:"phase"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// Jaeger is the Schema for the jaegers API
// +k8s:openapi-gen=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.phase",description="Instance's status"
// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".status.version",description="Jaeger Version"
type Jaeger struct {
metav1.TypeMeta `json:",inline"`

Expand Down
28 changes: 28 additions & 0 deletions pkg/controller/jaeger/jaeger_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ func (r *ReconcileJaeger) Reconcile(request reconcile.Request) (reconcile.Result

instance.Labels[v1.LabelOperatedBy] = identity
if err := r.client.Update(ctx, instance); err != nil {
// update the status to "Failed"
instance.Status.Phase = v1.JaegerPhaseFailed
if err := r.client.Status().Update(ctx, instance); err != nil {
// we let it return the real error later
logFields.WithError(err).Error("failed to store the failed status into the current CustomResource after setting the identity")
}

logFields.WithField(
"operator-identity", identity,
).WithError(err).Error("failed to set this operator as the manager of the instance")
Expand All @@ -160,12 +167,24 @@ func (r *ReconcileJaeger) Reconcile(request reconcile.Request) (reconcile.Result
})
list := &corev1.SecretList{}
if err := r.client.List(ctx, list, opts); err != nil {
instance.Status.Phase = v1.JaegerPhaseFailed
if err := r.client.Status().Update(ctx, instance); err != nil {
// we let it return the real error later
logFields.WithError(err).Error("failed to store the failed status into the current CustomResource after preconditions")
}
return reconcile.Result{}, tracing.HandleError(err, span)
}
str := r.runStrategyChooser(ctx, instance, list.Items)

updated, err := r.apply(ctx, *instance, str)
if err != nil {
// update the status to "Failed"
instance.Status.Phase = v1.JaegerPhaseFailed
if err := r.client.Status().Update(ctx, instance); err != nil {
// we let it return the real error later
logFields.WithError(err).Error("failed to store the failed status into the current CustomResource after the reconciliation")
}

logFields.WithError(err).Error("failed to apply the changes")
return reconcile.Result{}, tracing.HandleError(err, span)
}
Expand All @@ -179,6 +198,15 @@ func (r *ReconcileJaeger) Reconcile(request reconcile.Request) (reconcile.Result
}
}

// update the status to "Ready"
if instance.Status.Phase != v1.JaegerPhaseRunning {
instance.Status.Phase = v1.JaegerPhaseRunning
if err := r.client.Status().Update(ctx, instance); err != nil {
logFields.WithError(err).Error("failed to store the status into the current CustomResource")
return reconcile.Result{}, tracing.HandleError(err, span)
}
}

log.WithFields(log.Fields{
"namespace": request.Namespace,
"instance": request.Name,
Expand Down
10 changes: 7 additions & 3 deletions pkg/controller/jaeger/jaeger_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ func TestNewJaegerInstance(t *testing.T) {
assert.NoError(t, err)

// these are filled with default values
// TODO(jpkroehling): enable the assertion when the following issue is fixed:
// https://github.com/jaegertracing/jaeger-operator/issues/231
// assert.Equal(t, "custom-strategy", persisted.Spec.Strategy)
assert.Equal(t, v1.DeploymentStrategyAllInOne, persisted.Spec.Strategy)

// the status object got updated as well
assert.Equal(t, v1.JaegerPhaseRunning, persisted.Status.Phase)
}

func TestDeletedInstance(t *testing.T) {
Expand Down Expand Up @@ -145,6 +146,9 @@ func TestSkipOnNonOwnedCR(t *testing.T) {

// the only way to reliably test this is to verify that the operator didn't attempt to set the ownership field
assert.Equal(t, "another-identity", persisted.Labels[v1.LabelOperatedBy])

// condition shouldn't be touched when the object belongs to another operator
assert.Equal(t, v1.JaegerPhase(""), persisted.Status.Phase)
}

func getReconciler(objs []runtime.Object) (*ReconcileJaeger, client.Client) {
Expand Down

0 comments on commit b690e2a

Please sign in to comment.