2022-09-05 03:06:08 -04:00
|
|
|
/*
|
|
|
|
Copyright (c) Edgeless Systems GmbH
|
|
|
|
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
*/
|
|
|
|
|
2022-03-29 07:26:35 -04:00
|
|
|
package azure
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2022-09-21 07:47:57 -04:00
|
|
|
"github.com/edgelesssys/constellation/v2/internal/kubernetes"
|
2022-03-29 07:26:35 -04:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
k8s "k8s.io/api/core/v1"
|
|
|
|
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAutoscalerSecrets(t *testing.T) {
|
|
|
|
testCases := map[string]struct {
|
2022-06-28 10:08:05 -04:00
|
|
|
providerID string
|
2022-03-29 07:26:35 -04:00
|
|
|
cloudServiceAccountURI string
|
2022-08-29 08:30:20 -04:00
|
|
|
wantSecrets kubernetes.Secrets
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr bool
|
2022-03-29 07:26:35 -04:00
|
|
|
}{
|
|
|
|
"Secrets works": {
|
2022-06-29 10:17:23 -04:00
|
|
|
providerID: "azure:///subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachineScaleSets/scaleset/virtualMachines/instance-name",
|
2022-03-29 07:26:35 -04:00
|
|
|
cloudServiceAccountURI: "serviceaccount://azure?tenant_id=tenant-id&client_id=client-id&client_secret=client-secret",
|
2022-08-29 08:30:20 -04:00
|
|
|
wantSecrets: kubernetes.Secrets{
|
2022-03-29 07:26:35 -04:00
|
|
|
&k8s.Secret{
|
|
|
|
TypeMeta: meta.TypeMeta{
|
|
|
|
Kind: "Secret",
|
|
|
|
APIVersion: "v1",
|
|
|
|
},
|
|
|
|
ObjectMeta: meta.ObjectMeta{
|
|
|
|
Name: "cluster-autoscaler-azure",
|
|
|
|
Namespace: "kube-system",
|
|
|
|
},
|
|
|
|
Data: map[string][]byte{
|
|
|
|
"ClientID": []byte("client-id"),
|
|
|
|
"ClientSecret": []byte("client-secret"),
|
|
|
|
"ResourceGroup": []byte("resource-group"),
|
|
|
|
"SubscriptionID": []byte("subscription-id"),
|
|
|
|
"TenantID": []byte("tenant-id"),
|
|
|
|
"VMType": []byte("vmss"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"invalid providerID fails": {
|
2022-06-28 10:08:05 -04:00
|
|
|
providerID: "invalid",
|
|
|
|
wantErr: true,
|
2022-03-29 07:26:35 -04:00
|
|
|
},
|
|
|
|
"invalid cloudServiceAccountURI fails": {
|
2022-06-28 10:08:05 -04:00
|
|
|
providerID: "azure:///subscriptions/subscription-id/resourceGroups/resource-group/providers/Microsoft.Compute/virtualMachines/instance-name",
|
2022-03-29 07:26:35 -04:00
|
|
|
cloudServiceAccountURI: "invalid",
|
2022-04-26 10:54:05 -04:00
|
|
|
wantErr: true,
|
2022-03-29 07:26:35 -04:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for name, tc := range testCases {
|
|
|
|
t.Run(name, func(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
require := require.New(t)
|
|
|
|
|
|
|
|
autoscaler := Autoscaler{}
|
2022-06-28 10:08:05 -04:00
|
|
|
secrets, err := autoscaler.Secrets(tc.providerID, tc.cloudServiceAccountURI)
|
2022-04-26 10:54:05 -04:00
|
|
|
if tc.wantErr {
|
2022-03-29 07:26:35 -04:00
|
|
|
assert.Error(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
require.NoError(err)
|
2022-04-26 10:54:05 -04:00
|
|
|
assert.Equal(tc.wantSecrets, secrets)
|
2022-03-29 07:26:35 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestTrivialAutoscalerFunctions(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
autoscaler := Autoscaler{}
|
|
|
|
|
|
|
|
assert.NotEmpty(autoscaler.Name())
|
|
|
|
assert.Empty(autoscaler.Volumes())
|
|
|
|
assert.Empty(autoscaler.VolumeMounts())
|
|
|
|
assert.NotEmpty(autoscaler.Env())
|
|
|
|
assert.True(autoscaler.Supported())
|
|
|
|
}
|