Skip to content
Snippets Groups Projects
Unverified Commit 08401f62 authored by Stefan Prodan's avatar Stefan Prodan
Browse files

Add OCI provider arg

parent 69e26ca1
Branches
Tags
No related merge requests found
...@@ -33,6 +33,7 @@ import ( ...@@ -33,6 +33,7 @@ import (
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2" sourcev1 "github.com/fluxcd/source-controller/api/v1beta2"
"github.com/fluxcd/flux2/internal/flags"
"github.com/fluxcd/flux2/internal/utils" "github.com/fluxcd/flux2/internal/utils"
) )
...@@ -58,11 +59,19 @@ type sourceOCIRepositoryFlags struct { ...@@ -58,11 +59,19 @@ type sourceOCIRepositoryFlags struct {
serviceAccount string serviceAccount string
certSecretRef string certSecretRef string
ignorePaths []string ignorePaths []string
provider flags.SourceOCIProvider
} }
var sourceOCIRepositoryArgs = sourceOCIRepositoryFlags{} var sourceOCIRepositoryArgs = newSourceOCIFlags()
func newSourceOCIFlags() sourceOCIRepositoryFlags {
return sourceOCIRepositoryFlags{
provider: flags.SourceOCIProvider(sourcev1.GenericOCIProvider),
}
}
func init() { 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.url, "url", "", "the OCI repository URL")
createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.tag, "tag", "", "the OCI artifact tag") createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.tag, "tag", "", "the OCI artifact tag")
createSourceOCIRepositoryCmd.Flags().StringVar(&sourceOCIRepositoryArgs.semver, "tag-semver", "", "the OCI artifact tag semver range") 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 { ...@@ -104,7 +113,8 @@ func createSourceOCIRepositoryCmdRun(cmd *cobra.Command, args []string) error {
Labels: sourceLabels, Labels: sourceLabels,
}, },
Spec: sourcev1.OCIRepositorySpec{ Spec: sourcev1.OCIRepositorySpec{
URL: sourceOCIRepositoryArgs.url, Provider: sourceOCIRepositoryArgs.provider.String(),
URL: sourceOCIRepositoryArgs.url,
Interval: metav1.Duration{ Interval: metav1.Duration{
Duration: createArgs.interval, Duration: createArgs.interval,
}, },
......
...@@ -24,7 +24,12 @@ import ( ...@@ -24,7 +24,12 @@ import (
sourcev1 "github.com/fluxcd/source-controller/api/v1beta2" 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 type SourceBucketProvider string
......
/*
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, ", "),
)
}
...@@ -15,4 +15,4 @@ patchesJson6902: ...@@ -15,4 +15,4 @@ patchesJson6902:
# TODO: remove the hardcoded image when OCIRepository is released # TODO: remove the hardcoded image when OCIRepository is released
images: images:
- name: fluxcd/source-controller - name: fluxcd/source-controller
newTag: oci-102e9a94 newTag: oci-d95db940
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment