mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-08 17:25:14 -04:00
cli: fix upgrades when using outdated Kubernetes patch version (#2718)
* Fix missing image for Constellation operators in our Helm charts if the desired Kubernetes patch version is no longer supported (but Kubernetes upgrades are skipped) * Correctly unmarshal Kubernetes Components list if the list uses an old format --------- Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
parent
724ee44466
commit
a1f67d0884
5 changed files with 130 additions and 1 deletions
|
@ -8,6 +8,7 @@ package components
|
|||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
@ -16,6 +17,53 @@ import (
|
|||
// Components is a list of Kubernetes components.
|
||||
type Components []*Component
|
||||
|
||||
type legacyComponent struct {
|
||||
URL string `json:"URL,omitempty"`
|
||||
Hash string `json:"Hash,omitempty"`
|
||||
InstallPath string `json:"InstallPath,omitempty"`
|
||||
Extract bool `json:"Extract,omitempty"`
|
||||
}
|
||||
|
||||
// UnmarshalJSON implements a custom JSON unmarshaler to ensure backwards compatibility
|
||||
// with older components lists which had a different format for all keys.
|
||||
func (c *Components) UnmarshalJSON(b []byte) error {
|
||||
var legacyComponents []*legacyComponent
|
||||
if err := json.Unmarshal(b, &legacyComponents); err != nil {
|
||||
return err
|
||||
}
|
||||
var components []*Component
|
||||
if err := json.Unmarshal(b, &components); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(legacyComponents) != len(components) {
|
||||
return errors.New("failed to unmarshal data: inconsistent number of components in list") // just a check, should never happen
|
||||
}
|
||||
|
||||
// If a value is not set in the new format,
|
||||
// it might have been set in the old format.
|
||||
// In this case, we copy the value from the old format.
|
||||
comps := make(Components, len(components))
|
||||
for idx := 0; idx < len(components); idx++ {
|
||||
comps[idx] = components[idx]
|
||||
if comps[idx].Url == "" {
|
||||
comps[idx].Url = legacyComponents[idx].URL
|
||||
}
|
||||
if comps[idx].Hash == "" {
|
||||
comps[idx].Hash = legacyComponents[idx].Hash
|
||||
}
|
||||
if comps[idx].InstallPath == "" {
|
||||
comps[idx].InstallPath = legacyComponents[idx].InstallPath
|
||||
}
|
||||
if !comps[idx].Extract {
|
||||
comps[idx].Extract = legacyComponents[idx].Extract
|
||||
}
|
||||
}
|
||||
|
||||
*c = comps
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetHash returns the hash over all component hashes.
|
||||
func (c Components) GetHash() string {
|
||||
sha := sha256.New()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue