Skip to content

Commit

Permalink
initial pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig O'Donnell committed Oct 3, 2023
1 parent f9f80b2 commit 16c8269
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pkg/upstream/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ func WriteUpstream(u *types.Upstream, options types.WriteOptions) error {
if archives.IsTGZ(file.Content) {
// this is a helm chart, so we need to check if it is or contains the replicated-sdk
reader := bytes.NewReader(file.Content)
replicatedSDKChartName, isReplicatedSDK, err := FindReplicatedSDKChart(reader, u.ReplicatedChartNames)
replicatedSDKChartName, isSubchart, err := FindReplicatedSDKChart(reader, u.ReplicatedChartNames)
if err != nil {
return errors.Wrap(err, "failed to find replicated-sdk subchart")
}

if replicatedSDKChartName != "" {
updatedContent, err := configureReplicatedSDK(file.Content, u, replicatedSDKChartName, isReplicatedSDK)
updatedContent, err := configureReplicatedSDK(file.Content, u, replicatedSDKChartName, isSubchart)
if err != nil {
return errors.Wrap(err, "failed to configure replicated sdk")
}
Expand Down Expand Up @@ -233,7 +233,7 @@ func maybeEncryptIdentityConfig(identityConfig *kotsv1beta1.IdentityConfig) ([]b
return b.Bytes(), nil
}

// FindReplicatedSDKChart will look for a chart with the name "replicated" or "replicated-sdk" in the archive
// FindReplicatedSDKChart will look for a chart with one of the replicatedChartNames
// and return the name of the chart and whether it is the parent chart or a subchart
func FindReplicatedSDKChart(archive io.Reader, replicatedChartNames []string) (string, bool, error) {
replicatedChartNamesMap := map[string]bool{}
Expand Down Expand Up @@ -275,8 +275,8 @@ func FindReplicatedSDKChart(archive io.Reader, replicatedChartNames []string) (s
if replicatedChartNamesMap[chartInfo.ChartName] {
// check if the sdk is the parent chart or a subchart based on the path
replicatedSDKChartName := chartInfo.ChartName
isReplicatedSDK := !strings.Contains(filepath.Dir(header.Name), string(os.PathSeparator))
return replicatedSDKChartName, isReplicatedSDK, nil
isSubchart := !strings.Contains(filepath.Dir(header.Name), string(os.PathSeparator))
return replicatedSDKChartName, isSubchart, nil
}
}
}
Expand All @@ -285,7 +285,7 @@ func FindReplicatedSDKChart(archive io.Reader, replicatedChartNames []string) (s
return "", false, nil
}

func configureReplicatedSDK(chartContent []byte, u *types.Upstream, replicatedSDKChartName string, isReplicatedSDK bool) ([]byte, error) {
func configureReplicatedSDK(chartContent []byte, u *types.Upstream, replicatedSDKChartName string, isSubchart bool) ([]byte, error) {
reader := bytes.NewReader(chartContent)
unrenderedContents, pathInArchive, extractedArchiveRoot, err := findTopLevelChartValues(reader)
if err != nil {
Expand All @@ -298,7 +298,7 @@ func configureReplicatedSDK(chartContent []byte, u *types.Upstream, replicatedSD
return nil, errors.Wrap(err, "failed to get clientset")
}

renderedValuesContents, err := renderValuesYAMLForLicense(clientset, store.GetStore(), unrenderedContents, u, replicatedSDKChartName, isReplicatedSDK)
renderedValuesContents, err := renderValuesYAMLForLicense(clientset, store.GetStore(), unrenderedContents, u, replicatedSDKChartName, isSubchart)
if err != nil {
return nil, errors.Wrap(err, "render values.yaml")
}
Expand Down Expand Up @@ -411,7 +411,7 @@ type LicenseFieldSignature struct {
V1 string `json:"v1,omitempty" yaml:"v1,omitempty"` // this is a base64 encoded string because yaml.Unmarshal doesn't automatically convert base64 to []byte like json.Unmarshal does
}

func renderValuesYAMLForLicense(clientset kubernetes.Interface, kotsStore store.Store, unrenderedContents []byte, u *types.Upstream, replicatedSDKChartName string, isReplicatedSDK bool) ([]byte, error) {
func renderValuesYAMLForLicense(clientset kubernetes.Interface, kotsStore store.Store, unrenderedContents []byte, u *types.Upstream, replicatedSDKChartName string, isSubchart bool) ([]byte, error) {
var licenseBytes []byte
var licenseFields map[string]LicenseField
var dockerCfgJson string
Expand Down Expand Up @@ -494,7 +494,7 @@ func renderValuesYAMLForLicense(clientset kubernetes.Interface, kotsStore store.
}
}

if isReplicatedSDK {
if isSubchart {
err := addReplicatedValuesForSDK(valuesNodes.Content[0], replicatedOpts, "", true)
if err != nil {
return nil, errors.Wrap(err, "add values for the replicated sdk chart")
Expand Down

0 comments on commit 16c8269

Please sign in to comment.