Skip to content

Commit

Permalink
feat: add poolBalancerType field to enterprise, org and repo
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalgalaw committed Sep 10, 2024
1 parent a59683d commit 1060ecd
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 31 deletions.
4 changes: 3 additions & 1 deletion api/v1alpha1/enterprise_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package v1alpha1

import (
"github.com/cloudbase/garm/params"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand All @@ -14,7 +15,8 @@ type EnterpriseSpec struct {
CredentialsRef corev1.TypedLocalObjectReference `json:"credentialsRef"`

// WebhookSecretRef represents a secret that should be used for the webhook
WebhookSecretRef SecretRef `json:"webhookSecretRef"`
WebhookSecretRef SecretRef `json:"webhookSecretRef"`
PoolBalancerType params.PoolBalancerType `json:"poolBalancerType,omitempty"`
}

// EnterpriseStatus defines the observed state of Enterprise
Expand Down
4 changes: 3 additions & 1 deletion api/v1alpha1/organization_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package v1alpha1

import (
"github.com/cloudbase/garm/params"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand All @@ -14,7 +15,8 @@ type OrganizationSpec struct {
CredentialsRef corev1.TypedLocalObjectReference `json:"credentialsRef"`

// WebhookSecretRef represents a secret that should be used for the webhook
WebhookSecretRef SecretRef `json:"webhookSecretRef"`
WebhookSecretRef SecretRef `json:"webhookSecretRef"`
PoolBalancerType params.PoolBalancerType `json:"poolBalancerType,omitempty"`
}

// OrganizationStatus defines the observed state of Organization
Expand Down
4 changes: 3 additions & 1 deletion api/v1alpha1/repository_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package v1alpha1

import (
"github.com/cloudbase/garm/params"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Expand All @@ -15,7 +16,8 @@ type RepositorySpec struct {
Owner string `json:"owner"`

// WebhookSecretRef represents a secret that should be used for the webhook
WebhookSecretRef SecretRef `json:"webhookSecretRef"`
WebhookSecretRef SecretRef `json:"webhookSecretRef"`
PoolBalancerType params.PoolBalancerType `json:"poolBalancerType,omitempty"`
}

// RepositoryStatus defines the observed state of Repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ spec:
- name
type: object
x-kubernetes-map-type: atomic
poolBalancerType:
type: string
webhookSecretRef:
description: WebhookSecretRef represents a secret that should be used
for the webhook
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ spec:
- name
type: object
x-kubernetes-map-type: atomic
poolBalancerType:
type: string
webhookSecretRef:
description: WebhookSecretRef represents a secret that should be used
for the webhook
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ spec:
x-kubernetes-map-type: atomic
owner:
type: string
poolBalancerType:
type: string
webhookSecretRef:
description: WebhookSecretRef represents a secret that should be used
for the webhook
Expand Down
20 changes: 11 additions & 9 deletions internal/controller/enterprise_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ func (r *EnterpriseReconciler) reconcileNormal(ctx context.Context, client garmC
}

// update enterprise anytime
garmEnterprise, err = r.updateEnterprise(ctx, client, garmEnterprise.ID, webhookSecret, credentials.Name)
garmEnterprise, err = r.updateEnterprise(ctx, client, garmEnterprise.ID, params.UpdateEntityParams{
CredentialsName: credentials.Name,
WebhookSecret: webhookSecret,
PoolBalancerType: enterprise.Spec.PoolBalancerType,
})
if err != nil {
event.Error(r.Recorder, enterprise, err.Error())
conditions.MarkFalse(enterprise, conditions.ReadyCondition, conditions.GarmAPIErrorReason, err.Error())
Expand Down Expand Up @@ -175,9 +179,10 @@ func (r *EnterpriseReconciler) createEnterprise(ctx context.Context, client garm
retValue, err := client.CreateEnterprise(
enterprises.NewCreateEnterpriseParams().
WithBody(params.CreateEnterpriseParams{
Name: enterprise.Name,
CredentialsName: enterprise.GetCredentialsName(),
WebhookSecret: webhookSecret, // gh hook secret
Name: enterprise.Name,
CredentialsName: enterprise.GetCredentialsName(),
WebhookSecret: webhookSecret, // gh hook secret
PoolBalancerType: enterprise.Spec.PoolBalancerType,
}))
if err != nil {
log.V(1).Info(fmt.Sprintf("client.CreateEnterprise error: %s", err))
Expand All @@ -192,18 +197,15 @@ func (r *EnterpriseReconciler) createEnterprise(ctx context.Context, client garm
return retValue.Payload, nil
}

func (r *EnterpriseReconciler) updateEnterprise(ctx context.Context, client garmClient.EnterpriseClient, statusID, webhookSecret, credentialsName string) (params.Enterprise, error) {
func (r *EnterpriseReconciler) updateEnterprise(ctx context.Context, client garmClient.EnterpriseClient, statusID string, updateParams params.UpdateEntityParams) (params.Enterprise, error) {
log := log.FromContext(ctx)
log.V(1).Info("update credentials and webhook secret in garm enterprise")

// update credentials and webhook secret
retValue, err := client.UpdateEnterprise(
enterprises.NewUpdateEnterpriseParams().
WithEnterpriseID(statusID).
WithBody(params.UpdateEntityParams{
CredentialsName: credentialsName,
WebhookSecret: webhookSecret, // gh hook secret
}))
WithBody(updateParams))
if err != nil {
log.V(1).Info(fmt.Sprintf("client.UpdateEnterprise error: %s", err))
return params.Enterprise{}, err
Expand Down
20 changes: 11 additions & 9 deletions internal/controller/organization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ func (r *OrganizationReconciler) reconcileNormal(ctx context.Context, client gar
}

// update organization anytime
garmOrganization, err = r.updateOrganization(ctx, client, garmOrganization.ID, webhookSecret, credentials.Name)
garmOrganization, err = r.updateOrganization(ctx, client, garmOrganization.ID, params.UpdateEntityParams{
CredentialsName: credentials.Name,
WebhookSecret: webhookSecret,
PoolBalancerType: organization.Spec.PoolBalancerType,
})
if err != nil {
event.Error(r.Recorder, organization, err.Error())
conditions.MarkFalse(organization, conditions.ReadyCondition, conditions.GarmAPIErrorReason, err.Error())
Expand Down Expand Up @@ -173,9 +177,10 @@ func (r *OrganizationReconciler) createOrganization(ctx context.Context, client
retValue, err := client.CreateOrganization(
organizations.NewCreateOrgParams().
WithBody(params.CreateOrgParams{
Name: organization.Name,
CredentialsName: organization.GetCredentialsName(),
WebhookSecret: webhookSecret, // gh hook secret
Name: organization.Name,
CredentialsName: organization.GetCredentialsName(),
WebhookSecret: webhookSecret, // gh hook secret
PoolBalancerType: organization.Spec.PoolBalancerType,
}))
if err != nil {
log.V(1).Info(fmt.Sprintf("client.CreateOrganization error: %s", err))
Expand All @@ -190,18 +195,15 @@ func (r *OrganizationReconciler) createOrganization(ctx context.Context, client
return retValue.Payload, nil
}

func (r *OrganizationReconciler) updateOrganization(ctx context.Context, client garmClient.OrganizationClient, statusID, webhookSecret, credentialsName string) (params.Organization, error) {
func (r *OrganizationReconciler) updateOrganization(ctx context.Context, client garmClient.OrganizationClient, statusID string, updateParams params.UpdateEntityParams) (params.Organization, error) {
log := log.FromContext(ctx)
log.V(1).Info("update credentials and webhook secret in garm organization")

// update credentials and webhook secret
retValue, err := client.UpdateOrganization(
organizations.NewUpdateOrgParams().
WithOrgID(statusID).
WithBody(params.UpdateEntityParams{
CredentialsName: credentialsName,
WebhookSecret: webhookSecret, // gh hook secret
}))
WithBody(updateParams))
if err != nil {
log.V(1).Info(fmt.Sprintf("client.UpdateOrganization error: %s", err))
return params.Organization{}, err
Expand Down
22 changes: 12 additions & 10 deletions internal/controller/repository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ func (r *RepositoryReconciler) reconcileNormal(ctx context.Context, client garmC
}

// update repository anytime
garmRepository, err = r.updateRepository(ctx, client, garmRepository.ID, webhookSecret, credentials.Name)
garmRepository, err = r.updateRepository(ctx, client, garmRepository.ID, params.UpdateEntityParams{
CredentialsName: credentials.Name,
WebhookSecret: webhookSecret,
PoolBalancerType: repository.Spec.PoolBalancerType,
})
if err != nil {
event.Error(r.Recorder, repository, err.Error())
conditions.MarkFalse(repository, conditions.ReadyCondition, conditions.GarmAPIErrorReason, err.Error())
Expand Down Expand Up @@ -173,10 +177,11 @@ func (r *RepositoryReconciler) createRepository(ctx context.Context, client garm
retValue, err := client.CreateRepository(
repositories.NewCreateRepoParams().
WithBody(params.CreateRepoParams{
Name: repository.Name,
CredentialsName: repository.GetCredentialsName(),
Owner: repository.Spec.Owner,
WebhookSecret: webhookSecret, // gh hook secret
Name: repository.Name,
CredentialsName: repository.GetCredentialsName(),
Owner: repository.Spec.Owner,
WebhookSecret: webhookSecret, // gh hook secret
PoolBalancerType: repository.Spec.PoolBalancerType,
}))
if err != nil {
log.V(1).Info(fmt.Sprintf("client.CreateRepository error: %s", err))
Expand All @@ -191,18 +196,15 @@ func (r *RepositoryReconciler) createRepository(ctx context.Context, client garm
return retValue.Payload, nil
}

func (r *RepositoryReconciler) updateRepository(ctx context.Context, client garmClient.RepositoryClient, statusID, webhookSecret, credentialsName string) (params.Repository, error) {
func (r *RepositoryReconciler) updateRepository(ctx context.Context, client garmClient.RepositoryClient, statusID string, updateParams params.UpdateEntityParams) (params.Repository, error) {
log := log.FromContext(ctx)
log.V(1).Info("update credentials and webhook secret in garm repository")

// update credentials and webhook secret
retValue, err := client.UpdateRepository(
repositories.NewUpdateRepoParams().
WithRepoID(statusID).
WithBody(params.UpdateEntityParams{
CredentialsName: credentialsName,
WebhookSecret: webhookSecret, // gh hook secret
}))
WithBody(updateParams))
if err != nil {
log.V(1).Info(fmt.Sprintf("client.UpdateRepository error: %s", err))
return params.Repository{}, err
Expand Down

0 comments on commit 1060ecd

Please sign in to comment.