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 3 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
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
module github.com/mercedes-benz/garm-operator

go 1.21.5
go 1.21.8

require (
github.com/cloudbase/garm v0.1.4
Expand Down Expand Up @@ -56,7 +56,7 @@ require (
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-github/v57 v57.0.0 // indirect
Expand Down Expand Up @@ -99,7 +99,7 @@ require (
golang.org/x/time v0.3.0 // indirect
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.32.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaS
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/gnostic-models v0.6.8 h1:yo/ABAfM5IMRsS1VnXjTBvUb61tFIHozhlYvRgGre9I=
github.com/google/gnostic-models v0.6.8/go.mod h1:5n7qKqH0f5wFt+aWF8CW6pZLLNOfYuF5OpfBSENuI8U=
Expand Down Expand Up @@ -272,6 +274,8 @@ google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp0
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
18 changes: 10 additions & 8 deletions internal/controller/enterprise_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,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 +105,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 +117,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 +126,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.ComponentNotReadyReason, "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,7 +210,7 @@ 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)

Expand All @@ -219,14 +221,14 @@ func (r *EnterpriseReconciler) reconcileDelete(ctx context.Context, scope garmCl
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
36 changes: 18 additions & 18 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.ComponentNotReadyReason),
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.ComponentNotReadyReason),
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.ComponentNotReadyReason),
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.ComponentNotReadyReason),
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.ComponentNotReadyReason),
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.ComponentNotReadyReason),
Status: metav1.ConditionFalse,
Message: "Pool Manager is not running",
LastTransitionTime: metav1.NewTime(time.Now()),
},
{
Expand Down
Loading
Loading