Skip to content

Commit

Permalink
Add OCI source for provider ConfigMap preparation
Browse files Browse the repository at this point in the history
Signed-off-by: Danil-Grigorev <[email protected]>
  • Loading branch information
Danil-Grigorev committed Jan 14, 2025
1 parent 7d39b00 commit e202fd3
Show file tree
Hide file tree
Showing 19 changed files with 331 additions and 24 deletions.
8 changes: 8 additions & 0 deletions api/v1alpha1/provider_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func (src *BootstrapProvider) ConvertTo(dstRaw conversion.Hub) error {

dst.Spec.ManifestPatches = restored.Spec.ManifestPatches
dst.Spec.AdditionalDeployments = restored.Spec.AdditionalDeployments
dst.Spec.FetchConfig.OCI = restored.Spec.FetchConfig.OCI

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

dst.Spec.ManifestPatches = restored.Spec.ManifestPatches
dst.Spec.AdditionalDeployments = restored.Spec.AdditionalDeployments
dst.Spec.FetchConfig.OCI = restored.Spec.FetchConfig.OCI

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

dst.Spec.ManifestPatches = restored.Spec.ManifestPatches
dst.Spec.AdditionalDeployments = restored.Spec.AdditionalDeployments
dst.Spec.FetchConfig.OCI = restored.Spec.FetchConfig.OCI

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

dst.Spec.ManifestPatches = restored.Spec.ManifestPatches
dst.Spec.AdditionalDeployments = restored.Spec.AdditionalDeployments
dst.Spec.FetchConfig.OCI = restored.Spec.FetchConfig.OCI

return nil
}
Expand Down Expand Up @@ -495,6 +499,10 @@ func Convert_v1alpha2_ContainerSpec_To_v1alpha1_ContainerSpec(in *operatorv1.Con
return nil
}

func Convert_v1alpha2_FetchConfiguration_To_v1alpha1_FetchConfiguration(in *operatorv1.FetchConfiguration, out *FetchConfiguration, s apimachineryconversion.Scope) error {
return autoConvert_v1alpha2_FetchConfiguration_To_v1alpha1_FetchConfiguration(in, out, s)
}

func toImageMeta(imageURL string) *ImageMeta {
im := ImageMeta{}

Expand Down
20 changes: 16 additions & 4 deletions api/v1alpha1/provider_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,28 @@ func TestFuzzyConversion(t *testing.T) {
Scheme: scheme,
Hub: &operatorv1.CoreProvider{},
Spoke: &CoreProvider{},
FuzzerFuncs: []fuzzer.FuzzerFuncs{imageMetaFuzzFunc, imageURLFuzzFunc, secretConfigFuzzFunc},
FuzzerFuncs: []fuzzer.FuzzerFuncs{imageMetaFuzzFunc, imageURLFuzzFunc, ociFuzzFunc, secretConfigFuzzFunc},
}))

t.Run("for ControlPlaneProvider", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Scheme: scheme,
Hub: &operatorv1.ControlPlaneProvider{},
Spoke: &ControlPlaneProvider{},
FuzzerFuncs: []fuzzer.FuzzerFuncs{imageMetaFuzzFunc, imageURLFuzzFunc, secretConfigFuzzFunc},
FuzzerFuncs: []fuzzer.FuzzerFuncs{imageMetaFuzzFunc, imageURLFuzzFunc, ociFuzzFunc, secretConfigFuzzFunc},
}))

t.Run("for BootstrapProvider", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Scheme: scheme,
Hub: &operatorv1.BootstrapProvider{},
Spoke: &BootstrapProvider{},
FuzzerFuncs: []fuzzer.FuzzerFuncs{imageMetaFuzzFunc, imageURLFuzzFunc, secretConfigFuzzFunc},
FuzzerFuncs: []fuzzer.FuzzerFuncs{imageMetaFuzzFunc, imageURLFuzzFunc, ociFuzzFunc, secretConfigFuzzFunc},
}))

t.Run("for InfrastructureProvider", utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
Scheme: scheme,
Hub: &operatorv1.InfrastructureProvider{},
Spoke: &InfrastructureProvider{},
FuzzerFuncs: []fuzzer.FuzzerFuncs{imageMetaFuzzFunc, imageURLFuzzFunc, secretConfigFuzzFunc},
FuzzerFuncs: []fuzzer.FuzzerFuncs{imageMetaFuzzFunc, imageURLFuzzFunc, ociFuzzFunc, secretConfigFuzzFunc},
}))
}

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

func ociFuzzFunc(_ runtimeserializer.CodecFactory) []interface{} {
return []interface{}{
ociFuzzer,
}
}

func ociFuzzer(in *operatorv1.FetchConfiguration, c fuzz.Continue) {
c.FuzzNoCustom(in)

in.OCI = ""
}

func imageURLFuzzFunc(_ runtimeserializer.CodecFactory) []interface{} {
return []interface{}{
imageURLFuzzer,
Expand Down
36 changes: 24 additions & 12 deletions api/v1alpha1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions api/v1alpha2/provider_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ type FetchConfiguration struct {
// +optional
URL string `json:"url,omitempty"`

// OCI to be used for fetching the provider’s components and metadata from an OCI artifact.
// You must set `providerSpec.Version` field for operator to pick up desired version of the release from GitHub.
// If the providerSpec.Version is missing, latest provider version from clusterctl defaults is used.
// +optional
OCI string `json:"oci,omitempty"`

// Selector to be used for fetching provider’s components and metadata from
// ConfigMaps stored inside the cluster. Each ConfigMap is expected to contain
// components and metadata for a specific version only.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2750,6 +2750,12 @@ spec:
For example, the infrastructure name `aws` will fetch artifacts from
https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases.
properties:
oci:
description: |-
OCI to be used for fetching the provider’s components and metadata from an OCI artifact.
You must set `providerSpec.Version` field for operator to pick up desired version of the release from GitHub.
If the providerSpec.Version is missing, latest provider version from clusterctl defaults is used.
type: string
selector:
description: |-
Selector to be used for fetching provider’s components and metadata from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4380,6 +4380,12 @@ spec:
For example, the infrastructure name `aws` will fetch artifacts from
https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases.
properties:
oci:
description: |-
OCI to be used for fetching the provider’s components and metadata from an OCI artifact.
You must set `providerSpec.Version` field for operator to pick up desired version of the release from GitHub.
If the providerSpec.Version is missing, latest provider version from clusterctl defaults is used.
type: string
selector:
description: |-
Selector to be used for fetching provider’s components and metadata from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4382,6 +4382,12 @@ spec:
For example, the infrastructure name `aws` will fetch artifacts from
https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases.
properties:
oci:
description: |-
OCI to be used for fetching the provider’s components and metadata from an OCI artifact.
You must set `providerSpec.Version` field for operator to pick up desired version of the release from GitHub.
If the providerSpec.Version is missing, latest provider version from clusterctl defaults is used.
type: string
selector:
description: |-
Selector to be used for fetching provider’s components and metadata from
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/operator.cluster.x-k8s.io_coreproviders.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4380,6 +4380,12 @@ spec:
For example, the infrastructure name `aws` will fetch artifacts from
https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases.
properties:
oci:
description: |-
OCI to be used for fetching the provider’s components and metadata from an OCI artifact.
You must set `providerSpec.Version` field for operator to pick up desired version of the release from GitHub.
If the providerSpec.Version is missing, latest provider version from clusterctl defaults is used.
type: string
selector:
description: |-
Selector to be used for fetching provider’s components and metadata from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4382,6 +4382,12 @@ spec:
For example, the infrastructure name `aws` will fetch artifacts from
https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases.
properties:
oci:
description: |-
OCI to be used for fetching the provider’s components and metadata from an OCI artifact.
You must set `providerSpec.Version` field for operator to pick up desired version of the release from GitHub.
If the providerSpec.Version is missing, latest provider version from clusterctl defaults is used.
type: string
selector:
description: |-
Selector to be used for fetching provider’s components and metadata from
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/operator.cluster.x-k8s.io_ipamproviders.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2750,6 +2750,12 @@ spec:
For example, the infrastructure name `aws` will fetch artifacts from
https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases.
properties:
oci:
description: |-
OCI to be used for fetching the provider’s components and metadata from an OCI artifact.
You must set `providerSpec.Version` field for operator to pick up desired version of the release from GitHub.
If the providerSpec.Version is missing, latest provider version from clusterctl defaults is used.
type: string
selector:
description: |-
Selector to be used for fetching provider’s components and metadata from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2752,6 +2752,12 @@ spec:
For example, the infrastructure name `aws` will fetch artifacts from
https://github.com/kubernetes-sigs/cluster-api-provider-aws/releases.
properties:
oci:
description: |-
OCI to be used for fetching the provider’s components and metadata from an OCI artifact.
You must set `providerSpec.Version` field for operator to pick up desired version of the release from GitHub.
If the providerSpec.Version is missing, latest provider version from clusterctl defaults is used.
type: string
selector:
description: |-
Selector to be used for fetching provider’s components and metadata from
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/google/go-github/v52 v52.0.0
github.com/google/gofuzz v1.2.0
github.com/onsi/gomega v1.36.1
github.com/opencontainers/image-spec v1.1.0
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
golang.org/x/oauth2 v0.24.0
Expand All @@ -23,6 +24,7 @@ require (
k8s.io/component-base v0.31.4
k8s.io/klog/v2 v2.130.1
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
oras.land/oras-go/v2 v2.5.0
sigs.k8s.io/cluster-api v1.9.0
sigs.k8s.io/controller-runtime v0.19.3
sigs.k8s.io/yaml v1.4.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ github.com/onsi/gomega v1.36.1 h1:bJDPBO7ibjxcbHMgSCoo4Yj18UWbKDlLwX1x9sybDcw=
github.com/onsi/gomega v1.36.1/go.mod h1:PvZbdDc8J6XJEpDK4HCuRBm8a6Fzp9/DmhC9C7yFlog=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
github.com/opencontainers/image-spec v1.1.0/go.mod h1:W4s4sFTMaBeK1BQLXbG4AdM2szdn85PY75RI83NrTrM=
github.com/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down Expand Up @@ -407,6 +409,8 @@ k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 h1:BZqlfIlq5YbRMFko6/PM7F
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340/go.mod h1:yD4MZYeKMBwQKVht279WycxKyM84kkAx2DPrTXaeb98=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
oras.land/oras-go/v2 v2.5.0 h1:o8Me9kLY74Vp5uw07QXPiitjsw7qNXi8Twd+19Zf02c=
oras.land/oras-go/v2 v2.5.0/go.mod h1:z4eisnLP530vwIOUOJeBIj0aGI0L1C3d53atvCBqZHg=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 h1:2770sDpzrjjsAtVhSeUFseziht227YAWYHLGNM8QPwY=
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3/go.mod h1:Ve9uj1L+deCXFrPOk1LpFXqTg7LCFzFso6PA48q/XZw=
sigs.k8s.io/cluster-api v1.9.0 h1:Iud4Zj8R/t7QX5Rvs9/V+R8HDLbf7QPVemrWfZi4g54=
Expand Down
Loading

0 comments on commit e202fd3

Please sign in to comment.