-
Notifications
You must be signed in to change notification settings - Fork 613
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Flux CLI change to add provider field to GitRepository spec.
- Add provider flag to `flux create source git` command with supported values: azure, generic. - Unit tests validating the generated yaml and error conditions. Signed-off-by: Dipti Pai <[email protected]>
- Loading branch information
Showing
7 changed files
with
146 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
cmd/flux/testdata/create_source_git/source-git-provider-azure.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
apiVersion: source.toolkit.fluxcd.io/v1 | ||
kind: GitRepository | ||
metadata: | ||
name: podinfo | ||
namespace: flux-system | ||
spec: | ||
interval: 1m0s | ||
provider: azure | ||
ref: | ||
branch: test | ||
url: https://dev.azure.com/foo/bar/_git/podinfo |
12 changes: 12 additions & 0 deletions
12
cmd/flux/testdata/create_source_git/source-git-provider-generic.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
apiVersion: source.toolkit.fluxcd.io/v1 | ||
kind: GitRepository | ||
metadata: | ||
name: podinfo | ||
namespace: flux-system | ||
spec: | ||
interval: 1m0s | ||
provider: generic | ||
ref: | ||
branch: test | ||
url: https://github.com/stefanprodan/podinfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
Copyright 2024 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/v2/internal/utils" | ||
sourcev1 "github.com/fluxcd/source-controller/api/v1" | ||
) | ||
|
||
var supportedSourceGitProviders = []string{ | ||
sourcev1.GitProviderGeneric, | ||
sourcev1.GitProviderAzure, | ||
} | ||
|
||
type SourceGitProvider string | ||
|
||
func (p *SourceGitProvider) String() string { | ||
return string(*p) | ||
} | ||
|
||
func (p *SourceGitProvider) Set(str string) error { | ||
if strings.TrimSpace(str) == "" { | ||
return fmt.Errorf("no source Git provider given, please specify %s", | ||
p.Description()) | ||
} | ||
if !utils.ContainsItemString(supportedSourceGitProviders, str) { | ||
return fmt.Errorf("source Git provider '%s' is not supported, must be one of: %v", | ||
str, strings.Join(supportedSourceGitProviders, ", ")) | ||
} | ||
*p = SourceGitProvider(str) | ||
return nil | ||
} | ||
|
||
func (p *SourceGitProvider) Type() string { | ||
return strings.Join(supportedSourceGitProviders, "|") | ||
} | ||
|
||
func (p *SourceGitProvider) Description() string { | ||
return fmt.Sprintf( | ||
"the Git provider name, available options are: (%s)", | ||
strings.Join(supportedSourceGitProviders, ", "), | ||
) | ||
} |