Cloud provider GCP: add Secrets / Volumes / VolumeMounts / Env to cluster-autoscaler deployment

This commit is contained in:
Malte Poll 2022-03-29 13:26:27 +02:00 committed by Malte Poll
parent 203ae6df96
commit 97685648a4
2 changed files with 51 additions and 0 deletions

View File

@ -1,5 +1,11 @@
package gcp package gcp
import (
"github.com/edgelesssys/constellation/coordinator/core"
"github.com/edgelesssys/constellation/coordinator/kubernetes/k8sapi/resources"
k8s "k8s.io/api/core/v1"
)
// Autoscaler holds the GCP cluster-autoscaler configuration. // Autoscaler holds the GCP cluster-autoscaler configuration.
type Autoscaler struct{} type Autoscaler struct{}
@ -8,6 +14,46 @@ func (a *Autoscaler) Name() string {
return "gce" return "gce"
} }
// Secrets returns a list of secrets to deploy together with the k8s cluster-autoscaler.
func (a *Autoscaler) Secrets(instance core.Instance, cloudServiceAccountURI string) (resources.Secrets, error) {
return resources.Secrets{}, nil
}
// Volumes returns a list of volumes to deploy together with the k8s cluster-autoscaler.
func (a *Autoscaler) Volumes() []k8s.Volume {
return []k8s.Volume{
{
Name: "gcekey",
VolumeSource: k8s.VolumeSource{
Secret: &k8s.SecretVolumeSource{
SecretName: "gcekey",
},
},
},
}
}
// VolumeMounts returns a list of volume mounts to deploy together with the k8s cluster-autoscaler.
func (a *Autoscaler) VolumeMounts() []k8s.VolumeMount {
return []k8s.VolumeMount{
{
Name: "gcekey",
ReadOnly: true,
MountPath: "/var/secrets/google",
},
}
}
// Env returns a list of k8s environment key-value pairs to deploy together with the k8s cluster-autoscaler.
func (a *Autoscaler) Env() []k8s.EnvVar {
return []k8s.EnvVar{
{
Name: "GOOGLE_APPLICATION_CREDENTIALS",
Value: "/var/secrets/google/key.json",
},
}
}
// Supported is used to determine if we support autoscaling for the cloud provider. // Supported is used to determine if we support autoscaling for the cloud provider.
func (a *Autoscaler) Supported() bool { func (a *Autoscaler) Supported() bool {
return true return true

View File

@ -3,6 +3,7 @@ package gcp
import ( import (
"testing" "testing"
"github.com/edgelesssys/constellation/coordinator/core"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -11,5 +12,9 @@ func TestTrivialAutoscalerFunctions(t *testing.T) {
autoscaler := Autoscaler{} autoscaler := Autoscaler{}
assert.NotEmpty(autoscaler.Name()) assert.NotEmpty(autoscaler.Name())
assert.Empty(autoscaler.Secrets(core.Instance{}, ""))
assert.NotEmpty(autoscaler.Volumes())
assert.NotEmpty(autoscaler.VolumeMounts())
assert.NotEmpty(autoscaler.Env())
assert.True(autoscaler.Supported()) assert.True(autoscaler.Supported())
} }