mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-25 15:39:37 -05:00
cli: helm: move csp into ChartLoader object
This commit is contained in:
parent
1728633646
commit
4855b20093
@ -52,6 +52,7 @@ const (
|
|||||||
|
|
||||||
// ChartLoader loads embedded helm charts.
|
// ChartLoader loads embedded helm charts.
|
||||||
type ChartLoader struct {
|
type ChartLoader struct {
|
||||||
|
csp cloudprovider.Provider
|
||||||
joinServiceImage string
|
joinServiceImage string
|
||||||
keyServiceImage string
|
keyServiceImage string
|
||||||
ccmImage string
|
ccmImage string
|
||||||
@ -78,6 +79,7 @@ func NewLoader(csp cloudprovider.Provider, k8sVersion versions.ValidK8sVersion)
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &ChartLoader{
|
return &ChartLoader{
|
||||||
|
csp: csp,
|
||||||
joinServiceImage: versions.JoinImage,
|
joinServiceImage: versions.JoinImage,
|
||||||
keyServiceImage: versions.KeyServiceImage,
|
keyServiceImage: versions.KeyServiceImage,
|
||||||
ccmImage: ccmImage,
|
ccmImage: ccmImage,
|
||||||
@ -103,7 +105,7 @@ func AvailableServiceVersions() (string, error) {
|
|||||||
|
|
||||||
// Load the embedded helm charts.
|
// Load the embedded helm charts.
|
||||||
func (i *ChartLoader) Load(config *config.Config, conformanceMode bool, masterSecret, salt []byte) ([]byte, error) {
|
func (i *ChartLoader) Load(config *config.Config, conformanceMode bool, masterSecret, salt []byte) ([]byte, error) {
|
||||||
ciliumRelease, err := i.loadCilium(config.GetProvider())
|
ciliumRelease, err := i.loadCilium()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("loading cilium: %w", err)
|
return nil, fmt.Errorf("loading cilium: %w", err)
|
||||||
}
|
}
|
||||||
@ -114,12 +116,12 @@ func (i *ChartLoader) Load(config *config.Config, conformanceMode bool, masterSe
|
|||||||
return nil, fmt.Errorf("loading cilium: %w", err)
|
return nil, fmt.Errorf("loading cilium: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
operatorRelease, err := i.loadOperators(config.GetProvider())
|
operatorRelease, err := i.loadOperators()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("loading operators: %w", err)
|
return nil, fmt.Errorf("loading operators: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
conServicesRelease, err := i.loadConstellationServices(config.GetProvider())
|
conServicesRelease, err := i.loadConstellationServices()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("loading constellation-services: %w", err)
|
return nil, fmt.Errorf("loading constellation-services: %w", err)
|
||||||
}
|
}
|
||||||
@ -137,14 +139,14 @@ func (i *ChartLoader) Load(config *config.Config, conformanceMode bool, masterSe
|
|||||||
}
|
}
|
||||||
|
|
||||||
// loadCilium prepares a helm release for use in a helm install action.
|
// loadCilium prepares a helm release for use in a helm install action.
|
||||||
func (i *ChartLoader) loadCilium(csp cloudprovider.Provider) (helm.Release, error) {
|
func (i *ChartLoader) loadCilium() (helm.Release, error) {
|
||||||
chart, err := loadChartsDir(helmFS, ciliumPath)
|
chart, err := loadChartsDir(helmFS, ciliumPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return helm.Release{}, fmt.Errorf("loading cilium chart: %w", err)
|
return helm.Release{}, fmt.Errorf("loading cilium chart: %w", err)
|
||||||
}
|
}
|
||||||
values, err := i.loadCiliumValues(csp)
|
values, err := i.loadCiliumValues()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return helm.Release{}, err
|
return helm.Release{}, fmt.Errorf("loading cilium values: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
chartRaw, err := i.marshalChart(chart)
|
chartRaw, err := i.marshalChart(chart)
|
||||||
@ -157,9 +159,9 @@ func (i *ChartLoader) loadCilium(csp cloudprovider.Provider) (helm.Release, erro
|
|||||||
|
|
||||||
// loadCiliumValues is used to separate the marshalling step from the loading step.
|
// loadCiliumValues is used to separate the marshalling step from the loading step.
|
||||||
// This reduces the time unit tests take to execute.
|
// This reduces the time unit tests take to execute.
|
||||||
func (i *ChartLoader) loadCiliumValues(csp cloudprovider.Provider) (map[string]any, error) {
|
func (i *ChartLoader) loadCiliumValues() (map[string]any, error) {
|
||||||
var values map[string]any
|
var values map[string]any
|
||||||
switch csp {
|
switch i.csp {
|
||||||
case cloudprovider.AWS:
|
case cloudprovider.AWS:
|
||||||
values = awsVals
|
values = awsVals
|
||||||
case cloudprovider.Azure:
|
case cloudprovider.Azure:
|
||||||
@ -169,7 +171,7 @@ func (i *ChartLoader) loadCiliumValues(csp cloudprovider.Provider) (map[string]a
|
|||||||
case cloudprovider.QEMU:
|
case cloudprovider.QEMU:
|
||||||
values = qemuVals
|
values = qemuVals
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unknown csp: %s", csp)
|
return nil, fmt.Errorf("unknown csp: %s", i.csp)
|
||||||
}
|
}
|
||||||
|
|
||||||
return values, nil
|
return values, nil
|
||||||
@ -275,12 +277,12 @@ func (i *ChartLoader) loadCertManagerValues() map[string]any {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ChartLoader) loadOperators(csp cloudprovider.Provider) (helm.Release, error) {
|
func (i *ChartLoader) loadOperators() (helm.Release, error) {
|
||||||
chart, err := loadChartsDir(helmFS, conOperatorsPath)
|
chart, err := loadChartsDir(helmFS, conOperatorsPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return helm.Release{}, fmt.Errorf("loading operators chart: %w", err)
|
return helm.Release{}, fmt.Errorf("loading operators chart: %w", err)
|
||||||
}
|
}
|
||||||
values, err := i.loadOperatorsValues(csp)
|
values, err := i.loadOperatorsValues()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return helm.Release{}, err
|
return helm.Release{}, err
|
||||||
}
|
}
|
||||||
@ -295,7 +297,7 @@ func (i *ChartLoader) loadOperators(csp cloudprovider.Provider) (helm.Release, e
|
|||||||
|
|
||||||
// loadOperatorsHelper is used to separate the marshalling step from the loading step.
|
// loadOperatorsHelper is used to separate the marshalling step from the loading step.
|
||||||
// This reduces the time unit tests take to execute.
|
// This reduces the time unit tests take to execute.
|
||||||
func (i *ChartLoader) loadOperatorsValues(csp cloudprovider.Provider) (map[string]any, error) {
|
func (i *ChartLoader) loadOperatorsValues() (map[string]any, error) {
|
||||||
values := map[string]any{
|
values := map[string]any{
|
||||||
"constellation-operator": map[string]any{
|
"constellation-operator": map[string]any{
|
||||||
"controllerManager": map[string]any{
|
"controllerManager": map[string]any{
|
||||||
@ -312,7 +314,7 @@ func (i *ChartLoader) loadOperatorsValues(csp cloudprovider.Provider) (map[strin
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
switch csp {
|
switch i.csp {
|
||||||
case cloudprovider.Azure:
|
case cloudprovider.Azure:
|
||||||
conOpVals, ok := values["constellation-operator"].(map[string]any)
|
conOpVals, ok := values["constellation-operator"].(map[string]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -359,12 +361,12 @@ func (i *ChartLoader) loadOperatorsValues(csp cloudprovider.Provider) (map[strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
// loadConstellationServices prepares a helm release for use in a helm install action.
|
// loadConstellationServices prepares a helm release for use in a helm install action.
|
||||||
func (i *ChartLoader) loadConstellationServices(csp cloudprovider.Provider) (helm.Release, error) {
|
func (i *ChartLoader) loadConstellationServices() (helm.Release, error) {
|
||||||
chart, err := loadChartsDir(helmFS, conServicesPath)
|
chart, err := loadChartsDir(helmFS, conServicesPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return helm.Release{}, fmt.Errorf("loading constellation-services chart: %w", err)
|
return helm.Release{}, fmt.Errorf("loading constellation-services chart: %w", err)
|
||||||
}
|
}
|
||||||
values, err := i.loadConstellationServicesValues(csp)
|
values, err := i.loadConstellationServicesValues()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return helm.Release{}, err
|
return helm.Release{}, err
|
||||||
}
|
}
|
||||||
@ -379,7 +381,7 @@ func (i *ChartLoader) loadConstellationServices(csp cloudprovider.Provider) (hel
|
|||||||
|
|
||||||
// loadConstellationServicesHelper is used to separate the marshalling step from the loading step.
|
// loadConstellationServicesHelper is used to separate the marshalling step from the loading step.
|
||||||
// This reduces the time unit tests take to execute.
|
// This reduces the time unit tests take to execute.
|
||||||
func (i *ChartLoader) loadConstellationServicesValues(csp cloudprovider.Provider) (map[string]any, error) {
|
func (i *ChartLoader) loadConstellationServicesValues() (map[string]any, error) {
|
||||||
values := map[string]any{
|
values := map[string]any{
|
||||||
"global": map[string]any{
|
"global": map[string]any{
|
||||||
"keyServicePort": constants.KeyServicePort,
|
"keyServicePort": constants.KeyServicePort,
|
||||||
@ -396,18 +398,18 @@ func (i *ChartLoader) loadConstellationServicesValues(csp cloudprovider.Provider
|
|||||||
"measurementsFilename": constants.MeasurementsFilename,
|
"measurementsFilename": constants.MeasurementsFilename,
|
||||||
},
|
},
|
||||||
"join-service": map[string]any{
|
"join-service": map[string]any{
|
||||||
"csp": csp.String(),
|
"csp": i.csp.String(),
|
||||||
"image": i.joinServiceImage,
|
"image": i.joinServiceImage,
|
||||||
},
|
},
|
||||||
"ccm": map[string]any{
|
"ccm": map[string]any{
|
||||||
"csp": csp.String(),
|
"csp": i.csp.String(),
|
||||||
},
|
},
|
||||||
"autoscaler": map[string]any{
|
"autoscaler": map[string]any{
|
||||||
"csp": csp.String(),
|
"csp": i.csp.String(),
|
||||||
"image": i.autoscalerImage,
|
"image": i.autoscalerImage,
|
||||||
},
|
},
|
||||||
"verification-service": map[string]any{
|
"verification-service": map[string]any{
|
||||||
"csp": csp.String(),
|
"csp": i.csp.String(),
|
||||||
"image": i.verificationServiceImage,
|
"image": i.verificationServiceImage,
|
||||||
},
|
},
|
||||||
"gcp-guest-agent": map[string]any{
|
"gcp-guest-agent": map[string]any{
|
||||||
@ -418,7 +420,7 @@ func (i *ChartLoader) loadConstellationServicesValues(csp cloudprovider.Provider
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
switch csp {
|
switch i.csp {
|
||||||
case cloudprovider.Azure:
|
case cloudprovider.Azure:
|
||||||
ccmVals, ok := values["ccm"].(map[string]any)
|
ccmVals, ok := values["ccm"].(map[string]any)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -35,8 +35,8 @@ func TestLoad(t *testing.T) {
|
|||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
|
||||||
chartLoader := ChartLoader{}
|
|
||||||
config := &config.Config{Provider: config.ProviderConfig{GCP: &config.GCPConfig{}}}
|
config := &config.Config{Provider: config.ProviderConfig{GCP: &config.GCPConfig{}}}
|
||||||
|
chartLoader := ChartLoader{csp: config.GetProvider()}
|
||||||
release, err := chartLoader.Load(config, true, []byte("secret"), []byte("salt"))
|
release, err := chartLoader.Load(config, true, []byte("secret"), []byte("salt"))
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
|
|
||||||
@ -89,6 +89,7 @@ func TestConstellationServices(t *testing.T) {
|
|||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
|
||||||
chartLoader := ChartLoader{
|
chartLoader := ChartLoader{
|
||||||
|
csp: tc.config.GetProvider(),
|
||||||
joinServiceImage: "joinServiceImage",
|
joinServiceImage: "joinServiceImage",
|
||||||
keyServiceImage: "keyServiceImage",
|
keyServiceImage: "keyServiceImage",
|
||||||
ccmImage: tc.ccmImage,
|
ccmImage: tc.ccmImage,
|
||||||
@ -100,7 +101,7 @@ func TestConstellationServices(t *testing.T) {
|
|||||||
}
|
}
|
||||||
chart, err := loadChartsDir(helmFS, conServicesPath)
|
chart, err := loadChartsDir(helmFS, conServicesPath)
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
values, err := chartLoader.loadConstellationServicesValues(tc.config.GetProvider())
|
values, err := chartLoader.loadConstellationServicesValues()
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
err = extendConstellationServicesValues(values, tc.config, []byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), []byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
|
err = extendConstellationServicesValues(values, tc.config, []byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), []byte("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
@ -160,6 +161,7 @@ func TestOperators(t *testing.T) {
|
|||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
|
||||||
chartLoader := ChartLoader{
|
chartLoader := ChartLoader{
|
||||||
|
csp: tc.csp,
|
||||||
joinServiceImage: "joinServiceImage",
|
joinServiceImage: "joinServiceImage",
|
||||||
keyServiceImage: "keyServiceImage",
|
keyServiceImage: "keyServiceImage",
|
||||||
ccmImage: "ccmImage",
|
ccmImage: "ccmImage",
|
||||||
@ -170,7 +172,7 @@ func TestOperators(t *testing.T) {
|
|||||||
}
|
}
|
||||||
chart, err := loadChartsDir(helmFS, conOperatorsPath)
|
chart, err := loadChartsDir(helmFS, conOperatorsPath)
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
vals, err := chartLoader.loadOperatorsValues(tc.csp)
|
vals, err := chartLoader.loadOperatorsValues()
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
|
|
||||||
options := chartutil.ReleaseOptions{
|
options := chartutil.ReleaseOptions{
|
||||||
|
Loading…
Reference in New Issue
Block a user