Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sgalsaleh committed Oct 5, 2023
1 parent 9eec3b6 commit 41160a3
Show file tree
Hide file tree
Showing 3 changed files with 1,319 additions and 14 deletions.
6 changes: 0 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1525,12 +1525,6 @@ github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqn
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
github.com/replicatedhq/kotskinds v0.0.0-20230724164735-f83482cc9cfe h1:3AJInd06UxzqHmgy8+24CPsT2tYSE0zToJZyuX9q+MA=
github.com/replicatedhq/kotskinds v0.0.0-20230724164735-f83482cc9cfe/go.mod h1:QjhIUu3+OmHZ09u09j3FCoTt8F3BYtQglS+OLmftu9I=
github.com/replicatedhq/kotskinds v0.0.0-20230921181252-176885c4c65d h1:P1PY8o/pvb9B+cCFepYUGhqzoAFYe9H0pz0SKq2GJR0=
github.com/replicatedhq/kotskinds v0.0.0-20230921181252-176885c4c65d/go.mod h1:QjhIUu3+OmHZ09u09j3FCoTt8F3BYtQglS+OLmftu9I=
github.com/replicatedhq/kotskinds v0.0.0-20230925145827-c8f611d61fc1 h1:DqyT2B0ud9S1p78oTGV4mjtVvo3GqjyLbc17SS77kec=
github.com/replicatedhq/kotskinds v0.0.0-20230925145827-c8f611d61fc1/go.mod h1:QjhIUu3+OmHZ09u09j3FCoTt8F3BYtQglS+OLmftu9I=
github.com/replicatedhq/kotskinds v0.0.0-20231004174055-e6676d808a82 h1:QniKgIpcXu4wBMM4xIXGz+lkAU+hSIXFuVM+vxkNk0Y=
github.com/replicatedhq/kotskinds v0.0.0-20231004174055-e6676d808a82/go.mod h1:QjhIUu3+OmHZ09u09j3FCoTt8F3BYtQglS+OLmftu9I=
github.com/replicatedhq/kurlkinds v1.3.6 h1:/dhS32cSSZR4yS4vA8EquBvz+VgJCyTqBO9Xw+6eI4M=
Expand Down
34 changes: 26 additions & 8 deletions pkg/upstream/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ func buildReplicatedValues(u *types.Upstream, options types.WriteOptions) (map[s
"airgap": options.IsAirgap,
}

// only add the license if this is an airgap install
// because the airgap builder doesn't have the license context
if u.License != nil && options.IsAirgap {
// only add the license if this is an airgap install
// because the airgap builder doesn't have the license context
replicatedValues["license"] = MustMarshalLicense(u.License)
replicatedValues["license"] = string(MustMarshalLicense(u.License))
}

return replicatedValues, nil
Expand All @@ -288,6 +288,9 @@ func addGlobalReplicatedValues(doc *yaml.Node, u *types.Upstream, options types.
if err != nil {
return errors.Wrap(err, "build global replicated values")
}
if len(globalReplicatedValues) == 0 {
return nil
}

targetNode := doc
hasGlobal := false
Expand Down Expand Up @@ -353,14 +356,28 @@ func buildGlobalReplicatedValues(u *types.Upstream, options types.WriteOptions)
globalReplicatedValues["licenseID"] = u.License.Spec.LicenseID
globalReplicatedValues["licenseType"] = u.License.Spec.LicenseType

licenseFields := map[string]interface{}{}
for k, v := range u.License.Spec.Entitlements {
// TODO: support individual license field signatures
licenseFields[k] = v
licenseFields[k].(map[string]interface{})["name"] = k
// we marshal and then unmarshal entitlements into an interface to evaluate entitlement values
// and end up with a single value instead of (intVal, boolVal, strVal, and type)
marshalledEntitlements, err := json.Marshal(u.License.Spec.Entitlements)
if err != nil {
return nil, errors.Wrap(err, "failed to marshal entitlements")
}

var licenseFields map[string]interface{}
if err := json.Unmarshal(marshalledEntitlements, &licenseFields); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal entitlements")
}

// add the field name if missing
for k, v := range licenseFields {
if name, ok := v.(map[string]interface{})["name"]; !ok || name == "" {
licenseFields[k].(map[string]interface{})["name"] = k
}
}

globalReplicatedValues["licenseFields"] = licenseFields

// add docker config json
auth := fmt.Sprintf("%s:%s", u.License.Spec.LicenseID, u.License.Spec.LicenseID)
encodedAuth := base64.StdEncoding.EncodeToString([]byte(auth))
dockercfg := map[string]interface{}{
Expand All @@ -378,6 +395,7 @@ func buildGlobalReplicatedValues(u *types.Upstream, options types.WriteOptions)
if err != nil {
return nil, errors.Wrap(err, "failed to marshal dockercfg")
}

globalReplicatedValues["dockerconfigjson"] = base64.StdEncoding.EncodeToString(b)
}

Expand Down
Loading

0 comments on commit 41160a3

Please sign in to comment.