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: print-columns and ready condition aggregate #104

Merged
merged 6 commits into from
May 13, 2024
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ generate-doctoc: mdtoc ## Generate documentation table of contents
##@ Local Development

.PHONY: kind-cluster
kind-cluster: ## Create a new kind cluster designed for local development
kind-cluster: kind ## Create a new kind cluster designed for local development
hack/kind-with-registry.sh

.PHONY: delete-kind-cluster
Expand Down
5 changes: 3 additions & 2 deletions api/v1alpha1/enterprise_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ type EnterpriseStatus struct {
//+kubebuilder:resource:path=enterprises,scope=Namespaced,categories=garm,shortName=ent
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="ID",type="string",JSONPath=".status.id",description="Enterprise ID"
//+kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.poolManagerIsRunning",description="Status of the referenced pool"
//+kubebuilder:printcolumn:name="Error",type="string",JSONPath=".status.poolManagerFailureReason",description="Error description",priority=1
//+kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
//+kubebuilder:printcolumn:name="Error",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].message",priority=1
//+kubebuilder:printcolumn:name="Pool_Manager_Failure",type="string",JSONPath=`.status.conditions[?(@.reason=='PoolManagerFailure')].message`,priority=1
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of Enterprise"

// Enterprise is the Schema for the enterprises API
Expand Down
5 changes: 3 additions & 2 deletions api/v1alpha1/organization_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ type OrganizationStatus struct {
//+kubebuilder:resource:path=organizations,scope=Namespaced,categories=garm,shortName=org
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="ID",type="string",JSONPath=".status.id",description="Organization ID"
//+kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.poolManagerIsRunning",description="Status of the referenced pool"
//+kubebuilder:printcolumn:name="Error",type="string",JSONPath=".status.poolManagerFailureReason",description="Error description",priority=1
//+kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
//+kubebuilder:printcolumn:name="Error",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].message",priority=1
//+kubebuilder:printcolumn:name="Pool_Manager_Failure",type="string",JSONPath=`.status.conditions[?(@.reason=='PoolManagerFailure')].message`,priority=1
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of Organization"

// Organization is the Schema for the organizations API
Expand Down
5 changes: 3 additions & 2 deletions api/v1alpha1/pool_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (p *Pool) GetConditions() []metav1.Condition {

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:subresource:scale:specpath=.spec.minIdleRunners,statuspath=.status.idleRunners,selectorpath=.status.selector
//+kubebuilder:subresource:scale:specpath=.spec.minIdleRunners,statuspath=.status.longRunningIdleRunners,selectorpath=.status.selector
//+kubebuilder:resource:path=pools,scope=Namespaced,categories=garm
//+kubebuilder:printcolumn:name="ID",type=string,JSONPath=`.status.id`
//+kubebuilder:printcolumn:name="MinIdleRunners",type=string,JSONPath=`.spec.minIdleRunners`
Expand All @@ -72,7 +72,8 @@ func (p *Pool) GetConditions() []metav1.Condition {
//+kubebuilder:printcolumn:name="Provider",type=string,JSONPath=`.spec.providerName`,priority=1
//+kubebuilder:printcolumn:name="ScopeType",type=string,JSONPath=`.spec.githubScopeRef.kind`,priority=1
//+kubebuilder:printcolumn:name="ScopeName",type=string,JSONPath=`.spec.githubScopeRef.name`,priority=1
//+kubebuilder:printcolumn:name="Error",type=string,JSONPath=`.status.lastSyncError`,priority=1
//+kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
//+kubebuilder:printcolumn:name="Error",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].message",priority=1
//+kubebuilder:printcolumn:name="Enabled",type=boolean,JSONPath=`.spec.enabled`,priority=1
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"

Expand Down
5 changes: 3 additions & 2 deletions api/v1alpha1/repository_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ type RepositoryStatus struct {
//+kubebuilder:resource:path=repositories,scope=Namespaced,categories=garm,shortName=repo
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="ID",type="string",JSONPath=".status.id",description="Repository ID"
//+kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.poolManagerIsRunning",description="Status of the referenced pool"
//+kubebuilder:printcolumn:name="Error",type="string",JSONPath=".status.poolManagerFailureReason",description="Error description",priority=1
//+kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
//+kubebuilder:printcolumn:name="Error",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].message",priority=1
//+kubebuilder:printcolumn:name="Pool_Manager_Failure",type="string",JSONPath=`.status.conditions[?(@.reason=='PoolManagerFailure')].message`,priority=1
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of Repository"

// Repository is the Schema for the repositories API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ spec:
jsonPath: .status.id
name: ID
type: string
- description: Status of the referenced pool
jsonPath: .status.poolManagerIsRunning
- jsonPath: .status.conditions[?(@.type=='Ready')].status
name: Ready
type: string
- description: Error description
jsonPath: .status.poolManagerFailureReason
- jsonPath: .status.conditions[?(@.type=='Ready')].message
name: Error
priority: 1
type: string
- jsonPath: .status.conditions[?(@.reason=='PoolManagerFailure')].message
name: Pool_Manager_Failure
priority: 1
type: string
- description: Time duration since creation of Enterprise
jsonPath: .metadata.creationTimestamp
name: Age
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ spec:
jsonPath: .status.id
name: ID
type: string
- description: Status of the referenced pool
jsonPath: .status.poolManagerIsRunning
- jsonPath: .status.conditions[?(@.type=='Ready')].status
name: Ready
type: string
- description: Error description
jsonPath: .status.poolManagerFailureReason
- jsonPath: .status.conditions[?(@.type=='Ready')].message
name: Error
priority: 1
type: string
- jsonPath: .status.conditions[?(@.reason=='PoolManagerFailure')].message
name: Pool_Manager_Failure
priority: 1
type: string
- description: Time duration since creation of Organization
jsonPath: .metadata.creationTimestamp
name: Age
Expand Down
7 changes: 5 additions & 2 deletions config/crd/bases/garm-operator.mercedes-benz.com_pools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ spec:
name: ScopeName
priority: 1
type: string
- jsonPath: .status.lastSyncError
- jsonPath: .status.conditions[?(@.type=='Ready')].status
name: Ready
type: string
- jsonPath: .status.conditions[?(@.type=='Ready')].message
name: Error
priority: 1
type: string
Expand Down Expand Up @@ -233,5 +236,5 @@ spec:
scale:
labelSelectorPath: .status.selector
specReplicasPath: .spec.minIdleRunners
statusReplicasPath: .status.idleRunners
statusReplicasPath: .status.longRunningIdleRunners
status: {}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ spec:
jsonPath: .status.id
name: ID
type: string
- description: Status of the referenced pool
jsonPath: .status.poolManagerIsRunning
- jsonPath: .status.conditions[?(@.type=='Ready')].status
name: Ready
type: string
- description: Error description
jsonPath: .status.poolManagerFailureReason
- jsonPath: .status.conditions[?(@.type=='Ready')].message
name: Error
priority: 1
type: string
- jsonPath: .status.conditions[?(@.reason=='PoolManagerFailure')].message
name: Pool_Manager_Failure
priority: 1
type: string
- description: Time duration since creation of Repository
jsonPath: .metadata.creationTimestamp
name: Age
Expand Down
23 changes: 13 additions & 10 deletions internal/controller/enterprise_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ func (r *EnterpriseReconciler) reconcileNormal(ctx context.Context, client garmC

webhookSecret, err := secret.FetchRef(ctx, r.Client, &enterprise.Spec.WebhookSecretRef, enterprise.Namespace)
if err != nil {
conditions.MarkFalse(enterprise, conditions.ReadyCondition, conditions.ReconcileErrorReason, err.Error())
conditions.MarkFalse(enterprise, conditions.ReadyCondition, conditions.FetchingSecretRefFailedReason, err.Error())
conditions.MarkFalse(enterprise, conditions.SecretReference, conditions.FetchingSecretRefFailedReason, err.Error())
conditions.MarkUnknown(enterprise, conditions.PoolManager, conditions.UnknownReason, conditions.GarmServerNotReconciledYetMsg)
if err := r.Status().Update(ctx, enterprise); err != nil {
return ctrl.Result{}, err
}
Expand All @@ -93,7 +94,7 @@ func (r *EnterpriseReconciler) reconcileNormal(ctx context.Context, client garmC
garmEnterprise, err := r.getExistingGarmEnterprise(ctx, client, enterprise)
if err != nil {
event.Error(r.Recorder, enterprise, err.Error())
conditions.MarkFalse(enterprise, conditions.ReadyCondition, conditions.ReconcileErrorReason, err.Error())
conditions.MarkFalse(enterprise, conditions.ReadyCondition, conditions.GarmAPIErrorReason, err.Error())
if err := r.Status().Update(ctx, enterprise); err != nil {
return ctrl.Result{}, err
}
Expand All @@ -105,7 +106,7 @@ func (r *EnterpriseReconciler) reconcileNormal(ctx context.Context, client garmC
garmEnterprise, err = r.createEnterprise(ctx, client, enterprise, webhookSecret)
if err != nil {
event.Error(r.Recorder, enterprise, err.Error())
conditions.MarkFalse(enterprise, conditions.ReadyCondition, conditions.ReconcileErrorReason, err.Error())
conditions.MarkFalse(enterprise, conditions.ReadyCondition, conditions.GarmAPIErrorReason, err.Error())
if err := r.Status().Update(ctx, enterprise); err != nil {
return ctrl.Result{}, err
}
Expand All @@ -117,7 +118,7 @@ func (r *EnterpriseReconciler) reconcileNormal(ctx context.Context, client garmC
garmEnterprise, err = r.updateEnterprise(ctx, client, garmEnterprise.ID, webhookSecret, enterprise.Spec.CredentialsName)
if err != nil {
event.Error(r.Recorder, enterprise, err.Error())
conditions.MarkFalse(enterprise, conditions.ReadyCondition, conditions.ReconcileErrorReason, err.Error())
conditions.MarkFalse(enterprise, conditions.ReadyCondition, conditions.GarmAPIErrorReason, err.Error())
if err := r.Status().Update(ctx, enterprise); err != nil {
return ctrl.Result{}, err
}
Expand All @@ -126,12 +127,14 @@ func (r *EnterpriseReconciler) reconcileNormal(ctx context.Context, client garmC

// set and update enterprise status
enterprise.Status.ID = garmEnterprise.ID
conditions.MarkTrue(enterprise, conditions.PoolManager, conditions.PoolManagerRunningReason, garmEnterprise.PoolManagerStatus.FailureReason)
conditions.MarkTrue(enterprise, conditions.ReadyCondition, conditions.SuccessfulReconcileReason, "")
conditions.MarkTrue(enterprise, conditions.PoolManager, conditions.PoolManagerRunningReason, "")

if !garmEnterprise.PoolManagerStatus.IsRunning {
conditions.MarkFalse(enterprise, conditions.ReadyCondition, conditions.PoolManagerFailureReason, "Pool Manager is not running")
conditions.MarkFalse(enterprise, conditions.PoolManager, conditions.PoolManagerFailureReason, garmEnterprise.PoolManagerStatus.FailureReason)
}

conditions.MarkTrue(enterprise, conditions.ReadyCondition, conditions.SuccessfulReconcileReason, "")
if err := r.Status().Update(ctx, enterprise); err != nil {
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -208,25 +211,25 @@ func (r *EnterpriseReconciler) getExistingGarmEnterprise(ctx context.Context, cl
return params.Enterprise{}, nil
}

func (r *EnterpriseReconciler) reconcileDelete(ctx context.Context, scope garmClient.EnterpriseClient, enterprise *garmoperatorv1alpha1.Enterprise) (ctrl.Result, error) {
func (r *EnterpriseReconciler) reconcileDelete(ctx context.Context, client garmClient.EnterpriseClient, enterprise *garmoperatorv1alpha1.Enterprise) (ctrl.Result, error) {
log := log.FromContext(ctx)
log.WithValues("enterprise", enterprise.Name)

log.Info("starting enterprise deletion")
event.Deleting(r.Recorder, enterprise, "starting enterprise deletion")
conditions.MarkFalse(enterprise, conditions.ReadyCondition, conditions.DeletingReason, "Deleting Enterprise")
conditions.MarkFalse(enterprise, conditions.ReadyCondition, conditions.DeletingReason, conditions.DeletingEnterpriseMsg)
if err := r.Status().Update(ctx, enterprise); err != nil {
return ctrl.Result{}, err
}

err := scope.DeleteEnterprise(
err := client.DeleteEnterprise(
enterprises.NewDeleteEnterpriseParams().
WithEnterpriseID(enterprise.Status.ID),
)
if err != nil {
log.V(1).Info(fmt.Sprintf("client.DeleteEnterprise error: %s", err))
event.Error(r.Recorder, enterprise, err.Error())
conditions.MarkFalse(enterprise, conditions.ReadyCondition, conditions.ReconcileErrorReason, err.Error())
conditions.MarkFalse(enterprise, conditions.ReadyCondition, conditions.GarmAPIErrorReason, err.Error())
if err := r.Status().Update(ctx, enterprise); err != nil {
return ctrl.Result{}, err
}
Expand Down
45 changes: 26 additions & 19 deletions internal/controller/enterprise_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ func TestEnterpriseReconciler_reconcileNormal(t *testing.T) {
Conditions: []metav1.Condition{
{
Type: string(conditions.ReadyCondition),
Reason: string(conditions.SuccessfulReconcileReason),
Status: metav1.ConditionTrue,
Message: "",
Reason: string(conditions.PoolManagerFailureReason),
Status: metav1.ConditionFalse,
Message: "Pool Manager is not running",
LastTransitionTime: metav1.NewTime(time.Now()),
},
{
Expand Down Expand Up @@ -187,9 +187,9 @@ func TestEnterpriseReconciler_reconcileNormal(t *testing.T) {
Conditions: []metav1.Condition{
{
Type: string(conditions.ReadyCondition),
Reason: string(conditions.SuccessfulReconcileReason),
Status: metav1.ConditionTrue,
Message: "",
Reason: string(conditions.PoolManagerFailureReason),
Status: metav1.ConditionFalse,
Message: "Pool Manager is not running",
LastTransitionTime: metav1.NewTime(time.Now()),
},
{
Expand Down Expand Up @@ -274,9 +274,9 @@ func TestEnterpriseReconciler_reconcileNormal(t *testing.T) {
Conditions: []metav1.Condition{
{
Type: string(conditions.ReadyCondition),
Reason: string(conditions.SuccessfulReconcileReason),
Status: metav1.ConditionTrue,
Message: "",
Reason: string(conditions.PoolManagerFailureReason),
Status: metav1.ConditionFalse,
Message: "Pool Manager is not running",
LastTransitionTime: metav1.NewTime(time.Now()),
},
{
Expand Down Expand Up @@ -370,9 +370,9 @@ func TestEnterpriseReconciler_reconcileNormal(t *testing.T) {
Conditions: []metav1.Condition{
{
Type: string(conditions.ReadyCondition),
Reason: string(conditions.SuccessfulReconcileReason),
Status: metav1.ConditionTrue,
Message: "",
Reason: string(conditions.PoolManagerFailureReason),
Status: metav1.ConditionFalse,
Message: "Pool Manager is not running",
LastTransitionTime: metav1.NewTime(time.Now()),
},
{
Expand Down Expand Up @@ -475,9 +475,9 @@ func TestEnterpriseReconciler_reconcileNormal(t *testing.T) {
Conditions: []metav1.Condition{
{
Type: string(conditions.ReadyCondition),
Reason: string(conditions.SuccessfulReconcileReason),
Status: metav1.ConditionTrue,
Message: "",
Reason: string(conditions.PoolManagerFailureReason),
Status: metav1.ConditionFalse,
Message: "Pool Manager is not running",
LastTransitionTime: metav1.NewTime(time.Now()),
},
{
Expand Down Expand Up @@ -583,9 +583,9 @@ func TestEnterpriseReconciler_reconcileNormal(t *testing.T) {
Conditions: []metav1.Condition{
{
Type: string(conditions.ReadyCondition),
Reason: string(conditions.SuccessfulReconcileReason),
Status: metav1.ConditionTrue,
Message: "",
Reason: string(conditions.PoolManagerFailureReason),
Status: metav1.ConditionFalse,
Message: "Pool Manager is not running",
LastTransitionTime: metav1.NewTime(time.Now()),
},
{
Expand Down Expand Up @@ -676,11 +676,18 @@ func TestEnterpriseReconciler_reconcileNormal(t *testing.T) {
Conditions: []metav1.Condition{
{
Type: string(conditions.ReadyCondition),
Reason: string(conditions.ReconcileErrorReason),
Reason: string(conditions.FetchingSecretRefFailedReason),
Status: metav1.ConditionFalse,
Message: "secrets \"my-webhook-secret\" not found",
LastTransitionTime: metav1.NewTime(time.Now()),
},
{
Type: string(conditions.PoolManager),
Reason: string(conditions.UnknownReason),
Status: metav1.ConditionUnknown,
Message: "GARM server not reconciled yet",
LastTransitionTime: metav1.NewTime(time.Now()),
},
{
Type: string(conditions.SecretReference),
Reason: string(conditions.FetchingSecretRefFailedReason),
Expand Down
Loading
Loading