constellation/internal/versions/components/components.go
Markus Rudy a1dbd13f95 versions: consolidate various types of Components
There used to be three definitions of a Component type, and conversion
routines between the three. Since the use case is always the same, and
the Component semantics are defined by versions.go and the installer, it
seems appropriate to define the Component type there and import it in
the necessary places.
2023-12-11 14:26:54 +01:00

38 lines
769 B
Go

/*
Copyright (c) Edgeless Systems GmbH
SPDX-License-Identifier: AGPL-3.0-only
*/
package components
import (
"crypto/sha256"
"errors"
"fmt"
"strings"
)
// Components is a list of Kubernetes components.
type Components []*Component
// GetHash returns the hash over all component hashes.
func (c Components) GetHash() string {
sha := sha256.New()
for _, component := range c {
sha.Write([]byte(component.Hash))
}
return fmt.Sprintf("sha256:%x", sha.Sum(nil))
}
// GetKubeadmComponent returns the kubeadm component.
func (c Components) GetKubeadmComponent() (*Component, error) {
for _, component := range c {
if strings.Contains(component.GetUrl(), "kubeadm") {
return component, nil
}
}
return nil, errors.New("kubeadm component not found")
}