Skip to content

Commit 6a31fe3

Browse files
authored
Merge pull request #683 from Danil-Grigorev/oci-provider-source
✨ Add OCI source for provider ConfigMap preparation
2 parents 53d263b + 2959930 commit 6a31fe3

36 files changed

+1897
-81
lines changed

api/v1alpha1/provider_conversion.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func (src *BootstrapProvider) ConvertTo(dstRaw conversion.Hub) error {
4646

4747
dst.Spec.ManifestPatches = restored.Spec.ManifestPatches
4848
dst.Spec.AdditionalDeployments = restored.Spec.AdditionalDeployments
49+
dst.Spec.FetchConfig.OCI = restored.Spec.FetchConfig.OCI
4950

5051
return nil
5152
}
@@ -108,6 +109,7 @@ func (src *ControlPlaneProvider) ConvertTo(dstRaw conversion.Hub) error {
108109

109110
dst.Spec.ManifestPatches = restored.Spec.ManifestPatches
110111
dst.Spec.AdditionalDeployments = restored.Spec.AdditionalDeployments
112+
dst.Spec.FetchConfig.OCI = restored.Spec.FetchConfig.OCI
111113

112114
return nil
113115
}
@@ -170,6 +172,7 @@ func (src *CoreProvider) ConvertTo(dstRaw conversion.Hub) error {
170172

171173
dst.Spec.ManifestPatches = restored.Spec.ManifestPatches
172174
dst.Spec.AdditionalDeployments = restored.Spec.AdditionalDeployments
175+
dst.Spec.FetchConfig.OCI = restored.Spec.FetchConfig.OCI
173176

174177
return nil
175178
}
@@ -232,6 +235,7 @@ func (src *InfrastructureProvider) ConvertTo(dstRaw conversion.Hub) error {
232235

233236
dst.Spec.ManifestPatches = restored.Spec.ManifestPatches
234237
dst.Spec.AdditionalDeployments = restored.Spec.AdditionalDeployments
238+
dst.Spec.FetchConfig.OCI = restored.Spec.FetchConfig.OCI
235239

236240
return nil
237241
}
@@ -495,6 +499,10 @@ func Convert_v1alpha2_ContainerSpec_To_v1alpha1_ContainerSpec(in *operatorv1.Con
495499
return nil
496500
}
497501

502+
func Convert_v1alpha2_FetchConfiguration_To_v1alpha1_FetchConfiguration(in *operatorv1.FetchConfiguration, out *FetchConfiguration, s apimachineryconversion.Scope) error {
503+
return autoConvert_v1alpha2_FetchConfiguration_To_v1alpha1_FetchConfiguration(in, out, s)
504+
}
505+
498506
func toImageMeta(imageURL string) *ImageMeta {
499507
im := ImageMeta{}
500508

api/v1alpha1/provider_conversion_test.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,28 @@ func TestFuzzyConversion(t *testing.T) {
4040
Scheme: scheme,
4141
Hub: &operatorv1.CoreProvider{},
4242
Spoke: &CoreProvider{},
43-
FuzzerFuncs: []fuzzer.FuzzerFuncs{imageMetaFuzzFunc, imageURLFuzzFunc, secretConfigFuzzFunc},
43+
FuzzerFuncs: []fuzzer.FuzzerFuncs{imageMetaFuzzFunc, imageURLFuzzFunc, ociFuzzFunc, secretConfigFuzzFunc},
4444
}))
4545

4646
t.Run("for ControlPlaneProvider", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
4747
Scheme: scheme,
4848
Hub: &operatorv1.ControlPlaneProvider{},
4949
Spoke: &ControlPlaneProvider{},
50-
FuzzerFuncs: []fuzzer.FuzzerFuncs{imageMetaFuzzFunc, imageURLFuzzFunc, secretConfigFuzzFunc},
50+
FuzzerFuncs: []fuzzer.FuzzerFuncs{imageMetaFuzzFunc, imageURLFuzzFunc, ociFuzzFunc, secretConfigFuzzFunc},
5151
}))
5252

5353
t.Run("for BootstrapProvider", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
5454
Scheme: scheme,
5555
Hub: &operatorv1.BootstrapProvider{},
5656
Spoke: &BootstrapProvider{},
57-
FuzzerFuncs: []fuzzer.FuzzerFuncs{imageMetaFuzzFunc, imageURLFuzzFunc, secretConfigFuzzFunc},
57+
FuzzerFuncs: []fuzzer.FuzzerFuncs{imageMetaFuzzFunc, imageURLFuzzFunc, ociFuzzFunc, secretConfigFuzzFunc},
5858
}))
5959

6060
t.Run("for InfrastructureProvider", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
6161
Scheme: scheme,
6262
Hub: &operatorv1.InfrastructureProvider{},
6363
Spoke: &InfrastructureProvider{},
64-
FuzzerFuncs: []fuzzer.FuzzerFuncs{imageMetaFuzzFunc, imageURLFuzzFunc, secretConfigFuzzFunc},
64+
FuzzerFuncs: []fuzzer.FuzzerFuncs{imageMetaFuzzFunc, imageURLFuzzFunc, ociFuzzFunc, secretConfigFuzzFunc},
6565
}))
6666
}
6767

@@ -80,6 +80,18 @@ func secretConfigFuzzer(in *operatorv1.SecretReference, c fuzz.Continue) {
8080
}
8181
}
8282

83+
func ociFuzzFunc(_ runtimeserializer.CodecFactory) []interface{} {
84+
return []interface{}{
85+
ociFuzzer,
86+
}
87+
}
88+
89+
func ociFuzzer(in *operatorv1.FetchConfiguration, c fuzz.Continue) {
90+
c.FuzzNoCustom(in)
91+
92+
in.OCI = ""
93+
}
94+
8395
func imageURLFuzzFunc(_ runtimeserializer.CodecFactory) []interface{} {
8496
return []interface{}{
8597
imageURLFuzzer,

api/v1alpha1/zz_generated.conversion.go

Lines changed: 24 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha2/provider_types.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,11 @@ type ContainerSpec struct {
210210
}
211211

212212
// FetchConfiguration determines the way to fetch the components and metadata for the provider.
213+
// +kubebuilder:validation:XValidation:rule="[has(self.oci), has(self.url), has(self.selector)].exists_one(x,x)", message="Must specify one and only one of {oci, url, selector}"
213214
type FetchConfiguration struct {
215+
// OCI configurations to be used for fetching the provider’s components and metadata from an OCI artifact.
216+
OCIConfiguration `json:",inline"`
217+
214218
// URL to be used for fetching the provider’s components and metadata from a remote Github repository.
215219
// For example, https://github.com/{owner}/{repository}/releases
216220
// You must set `providerSpec.Version` field for operator to pick up
@@ -227,6 +231,14 @@ type FetchConfiguration struct {
227231
Selector *metav1.LabelSelector `json:"selector,omitempty"`
228232
}
229233

234+
type OCIConfiguration struct {
235+
// OCI to be used for fetching the provider’s components and metadata from an OCI artifact.
236+
// You must set `providerSpec.Version` field for operator to pick up desired version of the release from GitHub.
237+
// If the providerSpec.Version is missing, latest provider version from clusterctl defaults is used.
238+
// +optional
239+
OCI string `json:"oci,omitempty"`
240+
}
241+
230242
// ProviderStatus defines the observed state of the Provider.
231243
type ProviderStatus struct {
232244
// Contract will contain the core provider contract that the provider is

api/v1alpha2/zz_generated.deepcopy.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/plugin/cmd/init.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,8 @@ func deployCAPIOperator(ctx context.Context, opts *initOptions) error {
453453
return nil
454454
}
455455

456-
// createGenericProvider creates a generic provider.
457-
func createGenericProvider(ctx context.Context, client ctrlclient.Client, providerType clusterctlv1.ProviderType, providerInput, defaultNamespace, configSecretName, configSecretNamespace string) (operatorv1.GenericProvider, error) {
456+
// templateGenericProvider prepares the provider manifest based on provided provider string.
457+
func templateGenericProvider(providerType clusterctlv1.ProviderType, providerInput, defaultNamespace, configSecretName, configSecretNamespace string) (operatorv1.GenericProvider, error) {
458458
// Parse the provider string
459459
// Format is <provider-name>:<optional-namespace>:<optional-version>
460460
// Example: aws:capa-system:v2.1.5 -> name: aws, namespace: capa-system, version: v2.1.5
@@ -498,8 +498,6 @@ func createGenericProvider(ctx context.Context, client ctrlclient.Client, provid
498498
spec := provider.GetSpec()
499499
spec.Version = version
500500
provider.SetSpec(spec)
501-
} else {
502-
version = latestVersion
503501
}
504502

505503
// Set config secret
@@ -517,19 +515,29 @@ func createGenericProvider(ctx context.Context, client ctrlclient.Client, provid
517515
provider.SetSpec(spec)
518516
}
519517

518+
return provider, nil
519+
}
520+
521+
// createGenericProvider creates a generic provider.
522+
func createGenericProvider(ctx context.Context, client ctrlclient.Client, providerType clusterctlv1.ProviderType, providerInput, defaultNamespace, configSecretName, configSecretNamespace string) (operatorv1.GenericProvider, error) {
523+
provider, err := templateGenericProvider(providerType, providerInput, defaultNamespace, configSecretName, configSecretNamespace)
524+
if err != nil {
525+
return nil, err
526+
}
527+
520528
// Ensure that desired namespace exists
521-
if err := EnsureNamespaceExists(ctx, client, namespace); err != nil {
529+
if err := EnsureNamespaceExists(ctx, client, provider.GetNamespace()); err != nil {
522530
return nil, fmt.Errorf("cannot ensure that namespace exists: %w", err)
523531
}
524532

525-
log.Info("Installing provider", "Type", provider.GetType(), "Name", name, "Version", version, "Namespace", namespace)
533+
log.Info("Installing provider", "Type", provider.GetType(), "Name", provider.GetName(), "Version", provider.GetSpec().Version, "Namespace", provider.GetNamespace())
526534

527535
// Create the provider
528536
if err := wait.ExponentialBackoff(backoffOpts, func() (bool, error) {
529537
if err := client.Create(ctx, provider); err != nil {
530538
// If the provider already exists, return immediately and do not retry.
531539
if apierrors.IsAlreadyExists(err) {
532-
log.Info("Provider already exists, skipping creation", "Type", provider.GetType(), "Name", name, "Version", version, "Namespace", namespace)
540+
log.Info("Provider already exists, skipping creation", "Type", provider.GetType(), "Name", provider.GetName(), "Version", provider.GetSpec().Version, "Namespace", provider.GetNamespace())
533541

534542
return true, err
535543
}

cmd/plugin/cmd/init_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ func TestInitProviders(t *testing.T) {
265265
opts: &initOptions{
266266
coreProvider: "cluster-api:capi-system:v1.8.0",
267267
infrastructureProviders: []string{
268-
"cluster-api:capi-system:v1.8.0",
269268
"aws:capa-operator-system",
270269
"docker:capd-operator-system",
271270
},

0 commit comments

Comments
 (0)