mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-05-08 17:25:14 -04:00
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.
This commit is contained in:
parent
a8fb6c5af0
commit
a1dbd13f95
25 changed files with 454 additions and 379 deletions
|
@ -11,63 +11,10 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/edgelesssys/constellation/v2/bootstrapper/initproto"
|
||||
"github.com/edgelesssys/constellation/v2/joinservice/joinproto"
|
||||
)
|
||||
|
||||
// Component is a Kubernetes component.
|
||||
type Component struct {
|
||||
URL string
|
||||
Hash string
|
||||
InstallPath string
|
||||
Extract bool
|
||||
}
|
||||
|
||||
// Components is a list of Kubernetes components.
|
||||
type Components []Component
|
||||
|
||||
// NewComponentsFromInitProto converts a protobuf KubernetesVersion to Components.
|
||||
func NewComponentsFromInitProto(protoComponents []*initproto.KubernetesComponent) Components {
|
||||
components := Components{}
|
||||
for _, protoComponent := range protoComponents {
|
||||
if protoComponent == nil {
|
||||
continue
|
||||
}
|
||||
components = append(components, Component{URL: protoComponent.Url, Hash: protoComponent.Hash, InstallPath: protoComponent.InstallPath, Extract: protoComponent.Extract})
|
||||
}
|
||||
return components
|
||||
}
|
||||
|
||||
// NewComponentsFromJoinProto converts a protobuf KubernetesVersion to Components.
|
||||
func NewComponentsFromJoinProto(protoComponents []*joinproto.KubernetesComponent) Components {
|
||||
components := Components{}
|
||||
for _, protoComponent := range protoComponents {
|
||||
if protoComponent == nil {
|
||||
continue
|
||||
}
|
||||
components = append(components, Component{URL: protoComponent.Url, Hash: protoComponent.Hash, InstallPath: protoComponent.InstallPath, Extract: protoComponent.Extract})
|
||||
}
|
||||
return components
|
||||
}
|
||||
|
||||
// ToInitProto converts Components to a protobuf KubernetesVersion.
|
||||
func (c Components) ToInitProto() []*initproto.KubernetesComponent {
|
||||
protoComponents := []*initproto.KubernetesComponent{}
|
||||
for _, component := range c {
|
||||
protoComponents = append(protoComponents, &initproto.KubernetesComponent{Url: component.URL, Hash: component.Hash, InstallPath: component.InstallPath, Extract: component.Extract})
|
||||
}
|
||||
return protoComponents
|
||||
}
|
||||
|
||||
// ToJoinProto converts Components to a protobuf KubernetesVersion.
|
||||
func (c Components) ToJoinProto() []*joinproto.KubernetesComponent {
|
||||
protoComponents := []*joinproto.KubernetesComponent{}
|
||||
for _, component := range c {
|
||||
protoComponents = append(protoComponents, &joinproto.KubernetesComponent{Url: component.URL, Hash: component.Hash, InstallPath: component.InstallPath, Extract: component.Extract})
|
||||
}
|
||||
return protoComponents
|
||||
}
|
||||
type Components []*Component
|
||||
|
||||
// GetHash returns the hash over all component hashes.
|
||||
func (c Components) GetHash() string {
|
||||
|
@ -80,11 +27,11 @@ func (c Components) GetHash() string {
|
|||
}
|
||||
|
||||
// GetKubeadmComponent returns the kubeadm component.
|
||||
func (c Components) GetKubeadmComponent() (Component, error) {
|
||||
func (c Components) GetKubeadmComponent() (*Component, error) {
|
||||
for _, component := range c {
|
||||
if strings.Contains(component.URL, "kubeadm") {
|
||||
if strings.Contains(component.GetUrl(), "kubeadm") {
|
||||
return component, nil
|
||||
}
|
||||
}
|
||||
return Component{}, errors.New("kubeadm component not found")
|
||||
return nil, errors.New("kubeadm component not found")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue