Skip to content

Commit

Permalink
Introduce InfrastructureConfigFromCluster and use it instead of api call
Browse files Browse the repository at this point in the history
  • Loading branch information
Kostov6 committed Sep 24, 2024
1 parent 96c494f commit f2381ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
12 changes: 12 additions & 0 deletions pkg/apis/aws/helper/scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ func CloudProfileConfigFromCluster(cluster *controller.Cluster) (*api.CloudProfi
return cloudProfileConfig, nil
}

// InfrastructureConfigFromCluster decodes the provider specific infrastructure configuration for a shoot cluster
func InfrastructureConfigFromCluster(cluster *controller.Cluster) (*api.InfrastructureConfig, error) {
var infrastructureConfig *api.InfrastructureConfig
if cluster != nil && cluster.Shoot != nil && cluster.Shoot.Spec.Provider.InfrastructureConfig != nil && cluster.Shoot.Spec.Provider.InfrastructureConfig.Raw != nil {
infrastructureConfig = &api.InfrastructureConfig{}
if _, _, err := decoder.Decode(cluster.Shoot.Spec.Provider.InfrastructureConfig.Raw, nil, infrastructureConfig); err != nil {
return nil, fmt.Errorf("could not decode infrastructureConfig of shoot '%s': %w", k8sclient.ObjectKeyFromObject(cluster.Shoot), err)
}
}
return infrastructureConfig, nil
}

// InfrastructureConfigFromInfrastructure extracts the InfrastructureConfig from the
// ProviderConfig section of the given Infrastructure.
func InfrastructureConfigFromInfrastructure(infra *extensionsv1alpha1.Infrastructure) (*api.InfrastructureConfig, error) {
Expand Down
19 changes: 2 additions & 17 deletions pkg/webhook/controlplane/ensurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,7 @@ func (e *ensurer) EnsureKubeletServiceUnitOptions(ctx context.Context, gctx gcon
}

if k8sGreaterEqual127 {
infra := &extensionsv1alpha1.Infrastructure{}
if err := e.client.Get(ctx, client.ObjectKey{
Namespace: cluster.ObjectMeta.Name,
Name: cluster.Shoot.Name,
}, infra); err != nil {
return nil, err
}
infraConfig, err := helper.InfrastructureConfigFromInfrastructure(infra)
infraConfig, err := helper.InfrastructureConfigFromCluster(cluster)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -570,15 +563,7 @@ func (e *ensurer) EnsureAdditionalFiles(ctx context.Context, gctx gcontext.Garde
return nil
}

infra := &extensionsv1alpha1.Infrastructure{}
if err := e.client.Get(ctx, client.ObjectKey{
Namespace: cluster.ObjectMeta.Name,
Name: cluster.Shoot.Name,
}, infra); err != nil {
return err
}

infraConfig, err := helper.InfrastructureConfigFromInfrastructure(infra)
infraConfig, err := helper.InfrastructureConfigFromCluster(cluster)
if err != nil {
return err
}
Expand Down

0 comments on commit f2381ba

Please sign in to comment.