Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rafalgalaw committed Nov 30, 2023
1 parent 2f8ab83 commit 6a30799
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 26 deletions.
38 changes: 27 additions & 11 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

garmoperatorv1alpha1 "github.com/mercedes-benz/garm-operator/api/v1alpha1"
"github.com/mercedes-benz/garm-operator/internal/controller"
garmClient "github.com/mercedes-benz/garm-operator/pkg/client"
"github.com/mercedes-benz/garm-operator/pkg/config"
"github.com/mercedes-benz/garm-operator/pkg/flags"
)
Expand Down Expand Up @@ -102,6 +103,19 @@ func main() {
os.Exit(1)
}

baseClient := garmClient.New(&garmClient.GarmScopeParams{
BaseURL: config.Config.Garm.Server,
Username: config.Config.Garm.Username,
Password: config.Config.Garm.Password,
Debug: false,
})

err = baseClient.Login()
if err != nil {
setupLog.Error(err, "unable to Login into GARM Client")
os.Exit(1)
}

if err = (&controller.EnterpriseReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Expand All @@ -119,17 +133,19 @@ func main() {
os.Exit(1)
}

if err = (&garmoperatorv1alpha1.Pool{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Pool")
os.Exit(1)
}
if err = (&garmoperatorv1alpha1.Image{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Image")
os.Exit(1)
}
if err = (&garmoperatorv1alpha1.Repository{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Repository")
os.Exit(1)
if os.Getenv("CREATE_WEBHOOK") == "true" {
if err = (&garmoperatorv1alpha1.Pool{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Pool")
os.Exit(1)
}
if err = (&garmoperatorv1alpha1.Image{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Image")
os.Exit(1)
}
if err = (&garmoperatorv1alpha1.Repository{}).SetupWebhookWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create webhook", "webhook", "Repository")
os.Exit(1)
}
}

if err = (&controller.OrganizationReconciler{
Expand Down
3 changes: 3 additions & 0 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ spec:
- --garm-username=$GARM_SERVER_USERNAME
- --garm-password=$GARM_SERVER_PASSWORD
- --operator-watch-namespace=$OPERATOR_WATCH_NAMESPACE
env:
- name: CREATE_WEBHOOK
value: "true"
image: controller:latest
name: manager
securityContext:
Expand Down
13 changes: 12 additions & 1 deletion internal/controller/runner_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"time"

"github.com/cloudbase/garm/client/instances"
"github.com/cloudbase/garm/client/pools"
"github.com/cloudbase/garm/params"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -158,6 +159,13 @@ func (r *RunnerReconciler) updateRunnerStatus(ctx context.Context, runner *garmo
log := log.FromContext(ctx)
log.Info("Update runner status...")

poolClient := garmClient.NewPoolClient(garmClient.Instance())
poolName := garmRunner.PoolID
pool, err := poolClient.GetPool(pools.NewGetPoolParams().WithPoolID(garmRunner.PoolID))
if err == nil {
poolName = pool.Payload.ProviderName + "/" + pool.Payload.Flavor
}

runner.Status.ID = garmRunner.ID
runner.Status.ProviderID = garmRunner.ProviderID
runner.Status.AgentID = garmRunner.AgentID
Expand All @@ -169,7 +177,7 @@ func (r *RunnerReconciler) updateRunnerStatus(ctx context.Context, runner *garmo
runner.Status.Addresses = garmRunner.Addresses
runner.Status.Status = garmRunner.Status
runner.Status.InstanceStatus = garmRunner.RunnerStatus
runner.Status.PoolID = garmRunner.PoolID
runner.Status.PoolID = poolName
runner.Status.ProviderFault = garmRunner.ProviderFault
runner.Status.GitHubRunnerGroup = garmRunner.GitHubRunnerGroup

Expand Down Expand Up @@ -228,6 +236,9 @@ func (r *RunnerReconciler) EnqueueRunnerInstances(ctx context.Context, eventChan
}

for _, p := range pools.Items {
if p.Status.ID == "" {
continue
}
poolRunners, err := instanceClient.ListPoolInstances(instances.NewListPoolInstancesParams().WithPoolID(p.Status.ID))
if err != nil {
return err
Expand Down
28 changes: 14 additions & 14 deletions pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ func (i *baseClient) Client() *client.GarmAPI {
return i.client
}

func (i *baseClient) Login() error {
metrics.TotalGarmCalls.WithLabelValues("Login").Inc()
cli, authInfoWriter, err := newGarmClient(*i.garmScopeParams)
if err != nil {
metrics.GarmCallErrors.WithLabelValues("Login").Inc()
return err
}

i.authInfoWriter = authInfoWriter
i.client = cli

return nil
}

var baseClientInstance BaseClient

func New(garmScopeParams *GarmScopeParams) BaseClient {
Expand Down Expand Up @@ -127,20 +141,6 @@ func newGarmClient(garmParams GarmScopeParams) (*client.GarmAPI, *runtime.Client
return apiCli, &authInfoWriter, nil
}

func (i *baseClient) Login() error {
metrics.TotalGarmCalls.WithLabelValues("Login").Inc()
cli, authInfoWriter, err := newGarmClient(*i.garmScopeParams)
if err != nil {
metrics.GarmCallErrors.WithLabelValues("Login").Inc()
return err
}

i.authInfoWriter = authInfoWriter
i.client = cli

return nil
}

func IsNotFoundError(err interface{}) bool {
apiErr, ok := err.(runtime.ClientResponseStatus)
if !ok {
Expand Down

0 comments on commit 6a30799

Please sign in to comment.