2023-01-06 06:04:36 -05:00
|
|
|
/*
|
|
|
|
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.
|
2023-12-11 02:08:55 -05:00
|
|
|
type Components []*Component
|
2023-01-06 06:04:36 -05:00
|
|
|
|
|
|
|
// 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.
|
2023-12-11 02:08:55 -05:00
|
|
|
func (c Components) GetKubeadmComponent() (*Component, error) {
|
2023-01-06 06:04:36 -05:00
|
|
|
for _, component := range c {
|
2023-12-11 02:08:55 -05:00
|
|
|
if strings.Contains(component.GetUrl(), "kubeadm") {
|
2023-01-06 06:04:36 -05:00
|
|
|
return component, nil
|
|
|
|
}
|
|
|
|
}
|
2023-12-11 02:08:55 -05:00
|
|
|
return nil, errors.New("kubeadm component not found")
|
2023-01-06 06:04:36 -05:00
|
|
|
}
|