1
0
mirror of synced 2026-02-06 19:05:55 +00:00

Add source namespace to create commands

Signed-off-by: Stefan Prodan <stefan.prodan@gmail.com>
This commit is contained in:
Stefan Prodan
2021-03-29 11:03:31 +03:00
parent e5066c3712
commit b54fd2c6b3
8 changed files with 78 additions and 24 deletions

View File

@@ -28,8 +28,9 @@ import (
var supportedHelmChartSourceKinds = []string{sourcev1.HelmRepositoryKind, sourcev1.GitRepositoryKind, sourcev1.BucketKind}
type HelmChartSource struct {
Kind string
Name string
Kind string
Name string
Namespace string
}
func (s *HelmChartSource) String() string {
@@ -45,7 +46,7 @@ func (s *HelmChartSource) Set(str string) error {
s.Description())
}
sourceKind, sourceName := utils.ParseObjectKindName(str)
sourceKind, sourceName, sourceNamespace := utils.ParseObjectKindNameNamespace(str)
if sourceKind == "" || sourceName == "" {
return fmt.Errorf("invalid helm chart source '%s', must be in format <kind>/<name>", str)
}
@@ -55,8 +56,9 @@ func (s *HelmChartSource) Set(str string) error {
sourceKind, strings.Join(supportedHelmChartSourceKinds, ", "))
}
s.Name = sourceName
s.Kind = cleanSourceKind
s.Name = sourceName
s.Namespace = sourceNamespace
return nil
}
@@ -67,7 +69,7 @@ func (s *HelmChartSource) Type() string {
func (s *HelmChartSource) Description() string {
return fmt.Sprintf(
"source that contains the chart in the format '<kind>/<name>', "+
"source that contains the chart in the format '<kind>/<name>.<namespace>', "+
"where kind must be one of: (%s)",
strings.Join(supportedHelmChartSourceKinds, ", "),
)

View File

@@ -28,8 +28,9 @@ import (
var supportedKustomizationSourceKinds = []string{sourcev1.GitRepositoryKind, sourcev1.BucketKind}
type KustomizationSource struct {
Kind string
Name string
Kind string
Name string
Namespace string
}
func (s *KustomizationSource) String() string {
@@ -45,7 +46,7 @@ func (s *KustomizationSource) Set(str string) error {
s.Description())
}
sourceKind, sourceName := utils.ParseObjectKindName(str)
sourceKind, sourceName, sourceNamespace := utils.ParseObjectKindNameNamespace(str)
if sourceName == "" {
return fmt.Errorf("no name given for source of kind '%s'", sourceKind)
}
@@ -61,8 +62,9 @@ func (s *KustomizationSource) Set(str string) error {
sourceKind, strings.Join(supportedKustomizationSourceKinds, ", "))
}
s.Name = sourceName
s.Kind = cleanSourceKind
s.Name = sourceName
s.Namespace = sourceNamespace
return nil
}
@@ -73,7 +75,7 @@ func (s *KustomizationSource) Type() string {
func (s *KustomizationSource) Description() string {
return fmt.Sprintf(
"source that contains the Kubernetes manifests in the format '[<kind>/]<name>', "+
"source that contains the Kubernetes manifests in the format '[<kind>/]<name>.<namespace>', "+
"where kind must be one of: (%s), if kind is not specified it defaults to GitRepository",
strings.Join(supportedKustomizationSourceKinds, ", "),
)

View File

@@ -216,9 +216,10 @@ func ContainsEqualFoldItemString(s []string, e string) (string, bool) {
return "", false
}
func ParseObjectKindName(input string) (string, string) {
kind := ""
name := input
// ParseObjectKindName extracts the kind and name of a resource
// based on the '<kind>/<name>' format
func ParseObjectKindName(input string) (kind, name string) {
name = input
parts := strings.Split(input, "/")
if len(parts) == 2 {
kind, name = parts[0], parts[1]
@@ -226,6 +227,23 @@ func ParseObjectKindName(input string) (string, string) {
return kind, name
}
// ParseObjectKindNameNamespace extracts the kind, name and namespace of a resource
// based on the '<kind>/<name>.<namespace>' format
func ParseObjectKindNameNamespace(input string) (kind, name, namespace string) {
name = input
parts := strings.Split(input, "/")
if len(parts) == 2 {
kind, name = parts[0], parts[1]
}
if nn := strings.Split(name, "."); len(nn) > 1 {
name = strings.Join(nn[:len(nn)-1], ".")
namespace = nn[len(nn)-1]
}
return kind, name, namespace
}
func MakeDependsOn(deps []string) []dependency.CrossNamespaceDependencyReference {
refs := []dependency.CrossNamespaceDependencyReference{}
for _, dep := range deps {