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

Fix status apply #15

Closed
Closed
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
8 changes: 6 additions & 2 deletions apis/components/v1/dashboard_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
const (
DashboardInstanceName = "default-dashboard"
)

// DashboardSpec defines the desired state of Dashboard
type DashboardSpec struct {
Expand All @@ -39,6 +40,9 @@ type DashboardStatus struct {
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster
// +kubebuilder:validation:XValidation:rule="self.metadata.name == 'default-dashboard'",message="Dashboard name must be default-dashboard"
// +kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].status`,description="Ready"
// +kubebuilder:printcolumn:name="Reason",type=string,JSONPath=`.status.conditions[?(@.type=="Ready")].reason`,description="Reason"

// Dashboard is the Schema for the dashboards API
type Dashboard struct {
Expand Down
14 changes: 13 additions & 1 deletion config/crd/bases/components.opendatahub.io_dashboards.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,16 @@ spec:
singular: dashboard
scope: Cluster
versions:
- name: v1
- additionalPrinterColumns:
- description: Ready
jsonPath: .status.conditions[?(@.type=="Ready")].status
name: Ready
type: string
- description: Reason
jsonPath: .status.conditions[?(@.type=="Ready")].reason
name: Reason
type: string
name: v1
schema:
openAPIV3Schema:
description: Dashboard is the Schema for the dashboards API
Expand Down Expand Up @@ -148,6 +157,9 @@ spec:
- phase
type: object
type: object
x-kubernetes-validations:
- message: Dashboard name must be default-dashboard
rule: self.metadata.name == 'default-dashboard'
served: true
storage: true
subresources:
Expand Down
7 changes: 3 additions & 4 deletions controllers/components/dashboard_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ import (
)

const (
ComponentName = "dashboard"
DashboardInstanceName = "default-dashboard"
ComponentName = "dashboard"
)

var (
Expand Down Expand Up @@ -117,7 +116,7 @@ func CreateDashboardInstance(dsc *dscv1.DataScienceCluster) *componentsv1.Dashbo
APIVersion: "components.opendatahub.io/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: DashboardInstanceName,
Name: componentsv1.DashboardInstanceName,
},
Spec: componentsv1.DashboardSpec{
DSCDashboard: dsc.Spec.Components.Dashboard,
Expand Down Expand Up @@ -168,7 +167,7 @@ func CreateDashboardInstance(dsc *dscv1.DataScienceCluster) *componentsv1.Dashbo
func watchDashboardResources(_ context.Context, a client.Object) []reconcile.Request {
if a.GetLabels()["app.opendatahub.io/dashboard"] == "true" {
return []reconcile.Request{{
NamespacedName: types.NamespacedName{Name: DashboardInstanceName},
NamespacedName: types.NamespacedName{Name: componentsv1.DashboardInstanceName},
}}
}
return nil
Expand Down
8 changes: 7 additions & 1 deletion pkg/controller/actions/action_update_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package actions
import (
"context"
"fmt"
"k8s.io/apimachinery/pkg/api/meta"

appsv1 "k8s.io/api/apps/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -70,6 +71,9 @@ func (a *UpdateStatusAction) Execute(ctx context.Context, rr *types.Reconciliati
}
}

s := obj.GetStatus()
s.Phase = "Ready"

conditionReady := metav1.Condition{
Type: status.ConditionTypeReady,
Status: metav1.ConditionTrue,
Expand All @@ -80,9 +84,11 @@ func (a *UpdateStatusAction) Execute(ctx context.Context, rr *types.Reconciliati
if len(deployments.Items) > 0 && ready != len(deployments.Items) {
conditionReady.Status = metav1.ConditionFalse
conditionReady.Reason = DeploymentsNotReadyReason

s.Phase = "NotReady"
}

status.SetStatusCondition(obj, conditionReady)
meta.SetStatusCondition(&s.Conditions, conditionReady)

return nil
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/controller/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ type Client struct {
}

func (c *Client) Apply(ctx context.Context, obj ctrlCli.Object, opts ...ctrlCli.PatchOption) error {
// remove not required fields
obj.SetManagedFields(nil)

err := c.Client.Patch(ctx, obj, ctrlCli.Apply, opts...)
if err != nil {
return fmt.Errorf("unable to pactch object %s: %w", obj, err)
Expand All @@ -41,9 +44,12 @@ func (c *Client) Apply(ctx context.Context, obj ctrlCli.Object, opts ...ctrlCli.
}

func (c *Client) ApplyStatus(ctx context.Context, obj ctrlCli.Object, opts ...ctrlCli.SubResourcePatchOption) error {
// remove not required fields
obj.SetManagedFields(nil)

err := c.Client.Status().Patch(ctx, obj, ctrlCli.Apply, opts...)
if err != nil {
return fmt.Errorf("unable to pactch object %s: %w", obj, err)
return fmt.Errorf("unable to pactch object status %s: %w", obj, err)
}

return nil
Expand Down
Loading