mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-15 02:44:24 -05:00
a1dbd13f95
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.
38 lines
769 B
Go
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")
|
|
}
|