Skip to content

Commit

Permalink
fix: do CAPI init once if several infra providers are defined
Browse files Browse the repository at this point in the history
And fail if no providers were set.

Signed-off-by: Artem Chernyshev <[email protected]>
  • Loading branch information
Unix4ever committed Sep 6, 2021
1 parent 83353b6 commit c20b1a8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
31 changes: 21 additions & 10 deletions pkg/capi/capi.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,27 @@ func (clusterAPI *Manager) Install(ctx context.Context) error {
return err
}

var (
shouldRunInit bool
installed bool
)

if len(clusterAPI.options.InfrastructureProviders) == 0 {
return fmt.Errorf("should have at least one infrastructure provider installed")
}

providers := make([]string, len(clusterAPI.options.InfrastructureProviders))
for i, provider := range clusterAPI.options.InfrastructureProviders {
providers[i] = provider.Name()

if installed, err = provider.IsInstalled(ctx, clusterAPI.clientset); err != nil {
return err
}

if !installed {
shouldRunInit = true
}

if provider.Version() != "" {
providers[i] += ":" + provider.Version()
}
Expand All @@ -167,19 +184,13 @@ func (clusterAPI *Manager) Install(ctx context.Context) error {
LogUsageInstructions: false,
}

for _, provider := range clusterAPI.options.InfrastructureProviders {
var installed bool

if installed, err = provider.IsInstalled(ctx, clusterAPI.clientset); err != nil {
if shouldRunInit {
if _, err = clusterAPI.client.Init(opts); err != nil {
return err
}
}

if !installed {
if _, err = clusterAPI.client.Init(opts); err != nil {
return err
}
}

for _, provider := range clusterAPI.options.InfrastructureProviders {
if err = provider.WaitReady(ctx, clusterAPI.clientset); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/capi/infrastructure/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (s *AWSProvider) WaitReady(ctx context.Context, clientset *kubernetes.Clien
return retry.ExpectedError(err)
}

if deployment.Status.ReadyReplicas != deployment.Status.Replicas {
if deployment.Status.ReadyReplicas != deployment.Status.Replicas || deployment.Status.ReadyReplicas == 0 {
return retry.ExpectedError(fmt.Errorf("%d of %d replicas ready", deployment.Status.ReadyReplicas, deployment.Status.Replicas))
}

Expand Down

0 comments on commit c20b1a8

Please sign in to comment.