diff --git a/cmd/flux/create_source_oci.go b/cmd/flux/create_source_oci.go index 57d1a472..2481fe7d 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 f5c62c71..6e2bfaa5 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 00000000..5f5067ab --- /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 921ebff1..2e882ada 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