Skip to content

Commit 701d763

Browse files
author
Danil-Grigorev
committed
Add bootstrap resources for Azure and AzureStackHub
1 parent a60cae2 commit 701d763

5 files changed

Lines changed: 103 additions & 1 deletion

File tree

pkg/cloud/azure/azure.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package azure
2+
3+
import (
4+
"embed"
5+
6+
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/cloud/common"
7+
corev1 "k8s.io/api/core/v1"
8+
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
9+
"sigs.k8s.io/controller-runtime/pkg/client"
10+
)
11+
12+
var (
13+
//go:embed bootstrap/*
14+
azureBootstrapFS embed.FS
15+
16+
azureBootstrapResoureces []client.Object
17+
azureBootstrapSources = []common.ObjectSource{
18+
{Object: &corev1.Pod{}, Path: "bootstrap/pod.yaml"},
19+
}
20+
)
21+
22+
func init() {
23+
var err error
24+
azureBootstrapResoureces, err = common.ReadResources(azureBootstrapFS, azureBootstrapSources)
25+
utilruntime.Must(err)
26+
}
27+
28+
// GetBootstrapResources returns a list static pods for provisioning CCM on bootstrap node for Azure
29+
func GetBootstrapResources() []client.Object {
30+
resources := make([]client.Object, len(azureBootstrapResoureces))
31+
for i := range azureBootstrapResoureces {
32+
resources[i] = azureBootstrapResoureces[i].DeepCopyObject().(client.Object)
33+
}
34+
35+
return resources
36+
}

pkg/cloud/azure/azure_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package azure
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestGetBootstrapResources(t *testing.T) {
10+
resources := GetBootstrapResources()
11+
assert.Len(t, resources, 1)
12+
13+
var names, kinds []string
14+
for _, r := range resources {
15+
names = append(names, r.GetName())
16+
kinds = append(kinds, r.GetObjectKind().GroupVersionKind().Kind)
17+
}
18+
19+
assert.Contains(t, names, "azure-cloud-controller-manager")
20+
assert.Contains(t, kinds, "Pod")
21+
}

pkg/cloud/azure/bootstrap/pod.yaml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: v1
2+
kind: Pod
3+
metadata:
4+
name: azure-cloud-controller-manager
5+
namespace: kube-system
6+
spec:
7+
priorityClassName: system-node-critical
8+
hostNetwork: true
9+
containers:
10+
- name: cloud-controller-manager
11+
image: mcr.microsoft.com/oss/kubernetes/azure-cloud-controller-manager:v1.0.0
12+
imagePullPolicy: IfNotPresent
13+
command: ["cloud-controller-manager"]
14+
args:
15+
- --cloud-provider=azure
16+
- --controllers=cloud-node # run cloud-node controller only for Node initialization
17+
- --kubeconfig=/etc/kubernetes/secrets/kubeconfig
18+
- --cloud-config=/etc/config/cloud.conf
19+
- --leader-elect=false
20+
- --port=10267
21+
- -v=2
22+
livenessProbe:
23+
httpGet:
24+
path: /healthz
25+
port: 10267
26+
initialDelaySeconds: 20
27+
periodSeconds: 10
28+
timeoutSeconds: 5
29+
volumeMounts:
30+
- name: secrets
31+
mountPath: /etc/kubernetes/secrets
32+
- name: config
33+
mountPath: /etc/config
34+
volumes:
35+
- name: secrets
36+
hostPath:
37+
path: /etc/kubernetes/bootstrap-secrets
38+
- name: config
39+
hostPath:
40+
path: /etc/kubernetes/bootstrap-configs

pkg/cloud/cloud.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cloud
33
import (
44
configv1 "github.com/openshift/api/config/v1"
55
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/cloud/aws"
6+
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/cloud/azure"
67
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/cloud/openstack"
78
"k8s.io/klog"
89
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -37,6 +38,8 @@ func GetBootstrapResources(platform configv1.PlatformType) []client.Object {
3738
switch platform {
3839
case configv1.AWSPlatformType:
3940
return aws.GetBootstrapResources()
41+
case configv1.AzurePlatformType:
42+
return azure.GetBootstrapResources()
4043
default:
4144
klog.Warning("No recognized cloud provider platform found in infrastructure")
4245
return nil

pkg/cloud/cloud_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
configv1 "github.com/openshift/api/config/v1"
77
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/cloud/aws"
8+
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/cloud/azure"
89
"github.com/openshift/cluster-cloud-controller-manager-operator/pkg/cloud/openstack"
910
"github.com/stretchr/testify/assert"
1011
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -88,8 +89,9 @@ func TestGetBootstrapResources(t *testing.T) {
8889
name: "GCP resources are empty, as the platform is not yet supported",
8990
platform: configv1.GCPPlatformType,
9091
}, {
91-
name: "Azure resources are empty, as the platform is not yet supported",
92+
name: "Azure resources returned as expected",
9293
platform: configv1.AzurePlatformType,
94+
expected: azure.GetBootstrapResources(),
9395
}, {
9496
name: "VSphere resources are empty, as the platform is not yet supported",
9597
platform: configv1.VSpherePlatformType,

0 commit comments

Comments
 (0)