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

Added basic status to CR{D} #802

Merged
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
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: Jaeger 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 that the Jaeger instance failed to be provisioned
// +k8s:openapi-gen=true
JaegerPhaseFailed JaegerPhase = "Failed"

// JaegerPhaseRunning indicates that the Jaeger instance is ready and running
// +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="Jaeger 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 running status into the current CustomResource")
return reconcile.Result{}, tracing.HandleError(err, span)
}
}

log.WithFields(log.Fields{
"namespace": request.Namespace,
"instance": request.Name,
Expand Down
8 changes: 5 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,7 @@ 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])
assert.Equal(t, v1.JaegerPhase(""), persisted.Status.Phase)
}

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