Skip to content

Commit

Permalink
fix: vcluster create merge values & default values
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianKramm committed May 8, 2024
1 parent b952e87 commit 819d918
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 34 deletions.
33 changes: 26 additions & 7 deletions config/default_extra_values.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,34 @@ func applyK8SExtraValues(vConfig *Config, options *ExtraValuesOptions) error {
}

func parseImage(image string) Image {
splitTag := strings.SplitN(image, ":", 2)
if len(splitTag) == 2 {
return Image{
Repository: splitTag[0],
Tag: splitTag[1],
}
registry, repository, tag := SplitImage(image)
return Image{
Registry: registry,
Repository: repository,
Tag: tag,
}
}

func SplitImage(image string) (string, string, string) {
imageSplitted := strings.Split(image, ":")
if len(imageSplitted) == 1 {
return "", "", ""
}

// check if registry needs to be filled
registryAndRepository := strings.Join(imageSplitted[:len(imageSplitted)-1], ":")
parts := strings.Split(registryAndRepository, "/")
registry := ""
repository := strings.Join(parts, "/")
if len(parts) >= 2 && (strings.ContainsRune(parts[0], '.') || strings.ContainsRune(parts[0], ':')) {
// The first part of the repository is treated as the registry domain
// iff it contains a '.' or ':' character, otherwise it is all repository
// and the domain defaults to Docker Hub.
registry = parts[0]
repository = strings.Join(parts[1:], "/")
}

return Image{}
return registry, repository, imageSplitted[len(imageSplitted)-1]
}

func getImageByVersion(kubernetesVersion KubernetesVersion, versionImageMap map[string]string) (string, error) {
Expand Down
26 changes: 2 additions & 24 deletions config/legacyconfig/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -1073,37 +1073,15 @@ func convertStatefulSetImage(image string, into *config.StatefulSetImage) {
return
}

into.Registry, into.Repository, into.Tag = splitImage(image)
into.Registry, into.Repository, into.Tag = config.SplitImage(image)
}

func convertImage(image string, into *config.Image) {
if image == "" {
return
}

into.Registry, into.Repository, into.Tag = splitImage(image)
}

func splitImage(image string) (string, string, string) {
imageSplitted := strings.Split(image, ":")
if len(imageSplitted) == 1 {
return "", "", ""
}

// check if registry needs to be filled
registryAndRepository := strings.Join(imageSplitted[:len(imageSplitted)-1], ":")
parts := strings.Split(registryAndRepository, "/")
registry := ""
repository := strings.Join(parts, "/")
if len(parts) >= 2 && (strings.ContainsRune(parts[0], '.') || strings.ContainsRune(parts[0], ':')) {
// The first part of the repository is treated as the registry domain
// iff it contains a '.' or ':' character, otherwise it is all repository
// and the domain defaults to Docker Hub.
registry = parts[0]
repository = strings.Join(parts[1:], "/")
}

return registry, repository, imageSplitted[len(imageSplitted)-1]
into.Registry, into.Repository, into.Tag = config.SplitImage(image)
}

func mergeIntoMap(retMap map[string]string, arr []string) map[string]string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/create_helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ func CreateHelm(ctx context.Context, options *CreateOptions, globalFlags *flags.
// build extra values
var newExtraValues []string
for _, value := range cmd.Values {
decodedString, err := getBase64DecodedString(value)
// ignore decoding errors and treat it as non-base64 string
decodedString, err := getBase64DecodedString(value)
if err != nil {
newExtraValues = append(newExtraValues, value)
continue
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/create_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,12 @@ func mergeAllValues(setValues []string, valueFiles []string, chartValues string)
return "", fmt.Errorf("parse values file %s: %w", valuesFile, err)
}

strvals.MergeMaps(outValues, extraValues)
outValues = strvals.MergeMaps(outValues, extraValues)
}

// merge set
for _, set := range setValues {
err = strvals.ParseIntoString(set, outValues)
err = strvals.ParseInto(set, outValues)
if err != nil {
return "", fmt.Errorf("apply --set %s: %w", set, err)
}
Expand Down

0 comments on commit 819d918

Please sign in to comment.