Skip to content

Commit

Permalink
Merge pull request #243 from web-seven/bugfix/237-post-policy
Browse files Browse the repository at this point in the history
fixed registry policy early init
  • Loading branch information
evghen1 authored Nov 13, 2024
2 parents 7a57398 + 52c84e2 commit 657027f
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions internal/registry/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,37 @@ func (r *Registry) CreateLocal(ctx context.Context, client *kubernetes.Clientset
appsv1.AddToScheme(scheme)
ctrlClient, _ := ctrl.New(configClient, ctrl.Options{Scheme: scheme})
for _, res := range []ctrl.Object{deploy, svc} {
_, err := controllerutil.CreateOrUpdate(ctx, ctrlClient, res, func() error {
if res == svc {
_, err := controllerutil.CreateOrUpdate(ctx, ctrlClient, res, func() error { return nil })
if err != nil {
return err
}
}

timeout := time.After(30 * time.Second)
ticker := time.NewTicker(1 * time.Second)
deployIsReady := false
for !deployIsReady {
select {
case <-timeout:
return errors.New("local registry to not comes ready")
case <-ticker.C:
deploy, err = client.AppsV1().
Deployments(namespace.Namespace).
Get(ctx, deploy.GetName(), v1.GetOptions{})
if err != nil {
return err
}
deployIsReady = deploy.Status.ReadyReplicas > 0

if deployIsReady {
logger.Debug("Installing policy controller")
err = policy.AddPolicyConroller(ctx, configClient, policy.DefaultPolicyController)
if err != nil {
logger.Warnln("Policy controller has issues, without it, local registry could not work normally.")
return err
}
logger.Debug("Policy controller installed.")

logger.Debug("Installing policies")
err = policy.AddRegistryPolicy(ctx,
configClient,
Expand All @@ -142,28 +164,6 @@ func (r *Registry) CreateLocal(ctx context.Context, client *kubernetes.Clientset
}
logger.Debug("Policies installed.")
}
return nil
})
if err != nil {
return err
}
}

timeout := time.After(30 * time.Second)
ticker := time.NewTicker(1 * time.Second)
deployIsReady := false
for !deployIsReady {
select {
case <-timeout:
return errors.New("local registry to not comes ready")
case <-ticker.C:
deploy, err = client.AppsV1().
Deployments(namespace.Namespace).
Get(ctx, deploy.GetName(), v1.GetOptions{})
if err != nil {
return err
}
deployIsReady = deploy.Status.ReadyReplicas > 0
}
}

Expand Down

0 comments on commit 657027f

Please sign in to comment.