Skip to content

Commit 7d7012c

Browse files
Post rebase fixes
Signed-off-by: Danil-Grigorev <[email protected]>
1 parent 7cb2f24 commit 7d7012c

File tree

8 files changed

+45
-30
lines changed

8 files changed

+45
-30
lines changed

cmd/plugin/cmd/preload.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
kerrors "k8s.io/apimachinery/pkg/util/errors"
2828
"oras.land/oras-go/v2/registry/remote/auth"
2929
operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2"
30+
"sigs.k8s.io/cluster-api-operator/internal/controller/generic"
3031
"sigs.k8s.io/cluster-api-operator/internal/controller/phases"
3132
"sigs.k8s.io/cluster-api-operator/util"
3233
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
@@ -237,13 +238,13 @@ func preloadExisting(ctx context.Context, cl client.Client) ([]*corev1.ConfigMap
237238
configMaps := []*corev1.ConfigMap{}
238239

239240
for _, list := range operatorv1.ProviderLists {
240-
list, ok := list.(genericProviderList)
241+
list, ok := list.(generic.ProviderList)
241242
if !ok {
242243
log.V(5).Info("Expected to get GenericProviderList")
243244
continue
244245
}
245246

246-
list, ok = list.DeepCopyObject().(genericProviderList)
247+
list, ok = list.DeepCopyObject().(generic.ProviderList)
247248
if !ok {
248249
log.V(5).Info("Expected to get GenericProviderList")
249250
continue
@@ -257,7 +258,7 @@ func preloadExisting(ctx context.Context, cl client.Client) ([]*corev1.ConfigMap
257258
return configMaps, kerrors.NewAggregate(errors)
258259
}
259260

260-
func fetchProviders(ctx context.Context, cl client.Client, providerList genericProviderList) ([]*corev1.ConfigMap, error) {
261+
func fetchProviders(ctx context.Context, cl client.Client, providerList generic.ProviderList) ([]*corev1.ConfigMap, error) {
261262
configMaps := []*corev1.ConfigMap{}
262263

263264
if err := retryWithExponentialBackoff(ctx, newReadBackoff(), func(ctx context.Context) error {

internal/controller/image_overrides_test.go renamed to internal/controller/phases/image_overrides_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package controller
17+
package phases
1818

1919
import (
2020
"fmt"

internal/controller/phases/manifests_downloader.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ func (p *PhaseReconciler[P, G]) DownloadManifests(ctx context.Context, phase G)
6666

6767
log.Info("Downloading provider manifests")
6868

69-
if p.providerConfig.URL() != fakeURL {
70-
p.repo, err = util.RepositoryFactory(ctx, p.providerConfig, p.configClient.Variables())
69+
if p.ProviderConfig.URL() != fakeURL {
70+
p.Repo, err = util.RepositoryFactory(ctx, p.ProviderConfig, p.ConfigClient.Variables())
7171
if err != nil {
7272
err = fmt.Errorf("failed to create repo from provider url for provider %q: %w", p.provider.GetName(), err)
7373

@@ -77,9 +77,9 @@ func (p *PhaseReconciler[P, G]) DownloadManifests(ctx context.Context, phase G)
7777

7878
spec := phase.GetProvider().GetSpec()
7979

80-
if spec.Version == "" && p.repo != nil {
80+
if spec.Version == "" && p.Repo != nil {
8181
// User didn't set the version, try to get repository default.
82-
spec.Version = p.repo.DefaultVersion()
82+
spec.Version = p.Repo.DefaultVersion()
8383

8484
// Add version to the provider spec.
8585
phase.GetProvider().SetSpec(spec)
@@ -89,12 +89,12 @@ func (p *PhaseReconciler[P, G]) DownloadManifests(ctx context.Context, phase G)
8989

9090
// Fetch the provider metadata and components yaml files from the provided repository GitHub/GitLab or OCI source
9191
if p.provider.GetSpec().FetchConfig != nil && p.provider.GetSpec().FetchConfig.OCI != "" {
92-
configMap, err = OCIConfigMap(ctx, p.provider, OCIAuthentication(p.configClient.Variables()))
92+
configMap, err = OCIConfigMap(ctx, p.provider, OCIAuthentication(p.ConfigClient.Variables()))
9393
if err != nil {
9494
return reconcile.Result{}, wrapPhaseError(err, operatorv1.ComponentsFetchErrorReason, operatorv1.ProviderInstalledCondition)
9595
}
9696
} else {
97-
configMap, err = RepositoryConfigMap(ctx, p.provider, p.repo)
97+
configMap, err = RepositoryConfigMap(ctx, p.provider, p.Repo)
9898
if err != nil {
9999
err = fmt.Errorf("failed to create config map for provider %q: %w", p.provider.GetName(), err)
100100

internal/controller/phases/manifests_downloader_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,6 @@ func TestProviderDownloadWithOverrides(t *testing.T) {
126126
_, err = p.Fetch(ctx, phase)
127127
g.Expect(err).ToNot(HaveOccurred())
128128

129-
g.Expect(p.components.Images()).To(HaveExactElements([]string{"registry.k8s.io/cluster-api/cluster-api-controller:v1.4.3"}))
130-
g.Expect(p.components.Version()).To(Equal("v1.4.3"))
129+
g.Expect(p.Components.Images()).To(HaveExactElements([]string{"registry.k8s.io/cluster-api/cluster-api-controller:v1.4.3"}))
130+
g.Expect(p.Components.Version()).To(Equal("v1.4.3"))
131131
}

internal/controller/phases/phases.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ type PhaseReconciler[P generic.Provider, G generic.Group[P]] struct {
6060

6161
ctrlClient client.Client
6262
ctrlConfig *rest.Config
63-
repo repository.Repository
64-
contract string
65-
options repository.ComponentsOptions
66-
providerConfig configclient.Provider
67-
configClient configclient.Client
63+
Repo repository.Repository
64+
Contract string
65+
Options repository.ComponentsOptions
66+
ProviderConfig configclient.Provider
67+
ConfigClient configclient.Client
6868
overridesClient configclient.Client
69-
components repository.Components
69+
Components repository.Components
7070
clusterctlProvider *clusterctlv1.Provider
7171
}
7272

@@ -188,7 +188,7 @@ func (p *PhaseReconciler[P, G]) InitializePhaseReconciler(ctx context.Context, p
188188
overrideProviders = providers
189189
}
190190

191-
reader, err := p.secretReader(ctx, overrideProviders...)
191+
reader, err := secretReader(ctx, phase, overrideProviders...)
192192
if err != nil {
193193
return reconcile.Result{}, err
194194
}
@@ -314,7 +314,7 @@ func secretReader[P generic.Provider](ctx context.Context, phase generic.Group[P
314314
return nil, err
315315
}
316316

317-
if provider.Type() == clusterctlv1.ProviderType(p.provider.GetType()) && provider.Name() == p.provider.GetName() {
317+
if provider.Type() == clusterctlv1.ProviderType(phase.GetProvider().GetType()) && provider.Name() == phase.GetProvider().GetName() {
318318
isCustom = false
319319
}
320320
}
@@ -332,11 +332,11 @@ func secretReader[P generic.Provider](ctx context.Context, phase generic.Group[P
332332
// To register a new provider from the config map, we need to specify a URL with a valid
333333
// format. However, since we're using data from a local config map, URLs are not needed.
334334
// As a workaround, we add a fake but well-formatted URL.
335-
return mr.AddProvider(p.provider.GetName(), util.ClusterctlProviderType(p.provider), fakeURL)
335+
return mr.AddProvider(phase.GetProvider().GetName(), util.ClusterctlProviderType(phase.GetProvider()), fakeURL)
336336
}
337337

338-
if isCustom && p.provider.GetSpec().FetchConfig.OCI != "" {
339-
return mr.AddProvider(p.provider.GetName(), util.ClusterctlProviderType(p.provider), fakeURL)
338+
if isCustom && phase.GetProvider().GetSpec().FetchConfig.OCI != "" {
339+
return mr.AddProvider(phase.GetProvider().GetName(), util.ClusterctlProviderType(phase.GetProvider()), fakeURL)
340340
}
341341
}
342342

@@ -527,7 +527,7 @@ func (p *PhaseReconciler[P, G]) Fetch(ctx context.Context, phase G) (reconcile.R
527527
}
528528

529529
// Apply image overrides to the provider manifests.
530-
if err := repository.AlterComponents(p.components, imageOverrides(p.components.ManifestLabel(), p.overridesClient)); err != nil {
530+
if err := repository.AlterComponents(p.Components, imageOverrides(p.Components.ManifestLabel(), p.overridesClient)); err != nil {
531531
return reconcile.Result{}, wrapPhaseError(err, operatorv1.ComponentsFetchErrorReason, operatorv1.ProviderInstalledCondition)
532532
}
533533

internal/controller/phases/preflight_checks_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import (
3333

3434
operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2"
3535
"sigs.k8s.io/cluster-api-operator/internal/controller/generic"
36-
"sigs.k8s.io/cluster-api-operator/internal/controller/phases"
3736
"sigs.k8s.io/cluster-api-operator/internal/controller/providers"
3837
)
3938

@@ -462,7 +461,7 @@ func TestInfrastructurePreflightChecks(t *testing.T) {
462461

463462
rec := providercontroller.NewProviderControllerWrapper(
464463
providers.NewInfrastructureProviderReconciler(newConnector(fakeclient)),
465-
phases.NewPhase,
464+
NewPhase,
466465
false,
467466
)
468467

internal/controller/provider_controller_wrapper.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (r *ProviderControllerWrapper[P, R]) Reconcile(ctx context.Context, provide
129129
}
130130

131131
// Check if spec hash stays the same and don't go further in this case.
132-
specHash, err := calculateHash(ctx, r.Client, r.Provider)
132+
specHash, err := calculateHash(ctx, r.Reconciler.GetClient(), r.Provider)
133133
if err != nil {
134134
return ctrl.Result{}, err
135135
}
@@ -149,7 +149,7 @@ func (r *ProviderControllerWrapper[P, R]) Reconcile(ctx context.Context, provide
149149
// Set the spec hash annotation if reconciliation was successful or reset it otherwise.
150150
if res.IsZero() && err == nil {
151151
// Recalculate spec hash in case it was changed during reconciliation process.
152-
specHash, err := calculateHash(ctx, r.Client, r.Provider)
152+
specHash, err := calculateHash(ctx, r.Reconciler.GetClient(), r.Provider)
153153
if err != nil {
154154
return ctrl.Result{}, err
155155
}
@@ -221,7 +221,7 @@ func (r *ProviderControllerWrapper[P, R]) reconcileDelete(ctx context.Context, p
221221
return r.reconcilePhases(ctx, provider, r.Reconciler.ReconcileDelete(ctx, provider))
222222
}
223223

224-
func addConfigSecretToHash(ctx context.Context, k8sClient client.Client, hash hash.Hash, provider genericprovider.GenericProvider) error {
224+
func addConfigSecretToHash(ctx context.Context, k8sClient client.Client, hash hash.Hash, provider generic.Provider) error {
225225
if provider.GetSpec().ConfigSecret != nil {
226226
secret := &corev1.Secret{
227227
ObjectMeta: metav1.ObjectMeta{
@@ -262,7 +262,7 @@ func addObjectToHash(hash hash.Hash, object interface{}) error {
262262
return nil
263263
}
264264

265-
func calculateHash(ctx context.Context, k8sClient client.Client, provider genericprovider.GenericProvider) (string, error) {
265+
func calculateHash(ctx context.Context, k8sClient client.Client, provider generic.Provider) (string, error) {
266266
hash := sha256.New()
267267

268268
err := addObjectToHash(hash, provider.GetSpec())

internal/controller/suite_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ import (
2222
"testing"
2323
"time"
2424

25+
"k8s.io/apimachinery/pkg/runtime"
26+
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
2527
"sigs.k8s.io/cluster-api-operator/internal/controller/phases"
2628
"sigs.k8s.io/cluster-api-operator/internal/controller/providers"
2729
"sigs.k8s.io/cluster-api-operator/internal/envtest"
2830
ctrl "sigs.k8s.io/controller-runtime"
2931
"sigs.k8s.io/controller-runtime/pkg/controller"
32+
33+
corev1 "k8s.io/api/core/v1"
34+
operatorv1 "sigs.k8s.io/cluster-api-operator/api/v1alpha2"
35+
clusterctlv1 "sigs.k8s.io/cluster-api/cmd/clusterctl/api/v1alpha3"
3036
)
3137

3238
const (
@@ -39,6 +45,15 @@ var (
3945
ctx = ctrl.SetupSignalHandler()
4046
)
4147

48+
func setupScheme() *runtime.Scheme {
49+
scheme := runtime.NewScheme()
50+
utilruntime.Must(corev1.AddToScheme(scheme))
51+
utilruntime.Must(operatorv1.AddToScheme(scheme))
52+
utilruntime.Must(clusterctlv1.AddToScheme(scheme))
53+
54+
return scheme
55+
}
56+
4257
func TestMain(m *testing.M) {
4358
fmt.Println("Creating new test environment")
4459

0 commit comments

Comments
 (0)