diff --git a/cmd/flux/create_source_oci.go b/cmd/flux/create_source_oci.go index 57d1a4728f0f4295b88d8429e7efc7a8f1c234e9..2481fe7d033daddad719807956a76230b19dd484 100644 --- a/cmd/flux/create_source_oci.go +++ b/cmd/flux/create_source_oci.go @@ -33,6 +33,7 @@ import ( sourcev1 "github.com/fluxcd/source-controller/api/v1beta2" + "github.com/fluxcd/flux2/internal/flags" "github.com/fluxcd/flux2/internal/utils" ) @@ -58,11 +59,19 @@ type sourceOCIRepositoryFlags struct { serviceAccount string certSecretRef string ignorePaths []string + provider flags.SourceOCIProvider } -var sourceOCIRepositoryArgs = sourceOCIRepositoryFlags{} +var sourceOCIRepositoryArgs = newSourceOCIFlags() + +func newSourceOCIFlags() sourceOCIRepositoryFlags { + return sourceOCIRepositoryFlags{ + provider: flags.SourceOCIProvider(sourcev1.GenericOCIProvider), + } +} func init() { + createSourceOCIRepositoryCmd.Flags().Var(&sourceOCIRepositoryArgs.provider, "provider", sourceBucketArgs.provider.Description()) createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.url, "url", "", "the OCI repository URL") createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.tag, "tag", "", "the OCI artifact tag") createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.semver, "tag-semver", "", "the OCI artifact tag semver range") @@ -104,7 +113,8 @@ func createSourceOCIRepositoryCmdRun(cmd *cobra.Command, args []string) error { Labels: sourceLabels, }, Spec: sourcev1.OCIRepositorySpec{ - URL: sourceOCIRepositoryArgs.url, + Provider: sourceOCIRepositoryArgs.provider.String(), + URL: sourceOCIRepositoryArgs.url, Interval: metav1.Duration{ Duration: createArgs.interval, }, diff --git a/internal/flags/source_bucket_provider.go b/internal/flags/source_bucket_provider.go index f5c62c719cc325cdf0c50b2f6d39c8f6f2f84870..6e2bfaa5cffddfe76d2b8fa65dc76e6a2dcfd55d 100644 --- a/internal/flags/source_bucket_provider.go +++ b/internal/flags/source_bucket_provider.go @@ -24,7 +24,12 @@ import ( sourcev1 "github.com/fluxcd/source-controller/api/v1beta2" ) -var supportedSourceBucketProviders = []string{sourcev1.GenericBucketProvider, sourcev1.AmazonBucketProvider} +var supportedSourceBucketProviders = []string{ + sourcev1.GenericBucketProvider, + sourcev1.AmazonBucketProvider, + sourcev1.AzureBucketProvider, + sourcev1.GoogleBucketProvider, +} type SourceBucketProvider string diff --git a/internal/flags/source_oci_provider.go b/internal/flags/source_oci_provider.go new file mode 100644 index 0000000000000000000000000000000000000000..5f5067abc737da6626dc1c93a23f9afd0639578f --- /dev/null +++ b/internal/flags/source_oci_provider.go @@ -0,0 +1,62 @@ +/* +Copyright 2022 The Flux authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package flags + +import ( + "fmt" + "strings" + + "github.com/fluxcd/flux2/internal/utils" + sourcev1 "github.com/fluxcd/source-controller/api/v1beta2" +) + +var supportedSourceOCIProviders = []string{ + sourcev1.GenericOCIProvider, + sourcev1.AmazonOCIProvider, + sourcev1.AzureOCIProvider, + sourcev1.GoogleOCIProvider, +} + +type SourceOCIProvider string + +func (p *SourceOCIProvider) String() string { + return string(*p) +} + +func (p *SourceOCIProvider) Set(str string) error { + if strings.TrimSpace(str) == "" { + return fmt.Errorf("no source OCI provider given, please specify %s", + p.Description()) + } + if !utils.ContainsItemString(supportedSourceOCIProviders, str) { + return fmt.Errorf("source OCI provider '%s' is not supported, must be one of: %v", + str, strings.Join(supportedSourceOCIProviders, ", ")) + } + *p = SourceOCIProvider(str) + return nil +} + +func (p *SourceOCIProvider) Type() string { + return "sourceOCIProvider" +} + +func (p *SourceOCIProvider) Description() string { + return fmt.Sprintf( + "the OCI provider name, available options are: (%s)", + strings.Join(supportedSourceOCIProviders, ", "), + ) +} diff --git a/manifests/bases/source-controller/kustomization.yaml b/manifests/bases/source-controller/kustomization.yaml index 921ebff12c33817c12a92fc341c198b1ce126d43..2e882adaa6c9e2b693fd3f3c75e1db4734893298 100644 --- a/manifests/bases/source-controller/kustomization.yaml +++ b/manifests/bases/source-controller/kustomization.yaml @@ -15,4 +15,4 @@ patchesJson6902: # TODO: remove the hardcoded image when OCIRepository is released images: - name: fluxcd/source-controller - newTag: oci-102e9a94 + newTag: oci-d95db940