Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ test-e2e: ## Run openshift specific e2e test
deploy-kubemark:
kustomize build config | kubectl apply -f -
kustomize build | kubectl apply -f -
kubectl apply -f config/kubemark-install-config.yaml
kubectl apply -f config/kubemark-config-infra.yaml

.PHONY: test
test: ## Run tests
Expand Down
36 changes: 25 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,22 +161,36 @@ INFO: For development and testing purposes only
$ kustomize build config | kubectl apply -f -
```

3. Create `cluster-config-v1` configmap to tell the MAO to deploy `kubemark` provider:
3. Create `cluster` `infrastructure.config.openshift.io` to tell the MAO to deploy `kubemark` provider:
```yaml
apiVersion: v1
kind: ConfigMap
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: cluster-config-v1
namespace: kube-system
data:
install-config: |-
platform:
kubemark: {}
name: infrastructures.config.openshift.io
spec:
group: config.openshift.io
names:
kind: Infrastructure
listKind: InfrastructureList
plural: infrastructures
singular: infrastructure
scope: Cluster
versions:
- name: v1
served: true
storage: true
---
apiVersion: config.openshift.io/v1
kind: Infrastructure
metadata:
name: cluster
status:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be status or spec? Seems configurables should be in spec not status.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

platform: kubemark
```

The file is already present under `config/kubemark-install-config.yaml` so it's sufficient to run:
The file is already present under `config/kubemark-config-infra.yaml` so it's sufficient to run:
```sh
$ kubectl apply -f config/kubemark-install-config.yaml
$ kubectl apply -f config/kubemark-config-infra.yaml
```

## CI & tests
Expand Down
23 changes: 23 additions & 0 deletions config/kubemark-config-infra.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: infrastructures.config.openshift.io
spec:
group: config.openshift.io
names:
kind: Infrastructure
listKind: InfrastructureList
plural: infrastructures
singular: infrastructure
scope: Cluster
versions:
- name: v1
served: true
storage: true
---
apiVersion: config.openshift.io/v1
kind: Infrastructure
metadata:
name: cluster
status:
platform: kubemark
9 changes: 0 additions & 9 deletions config/kubemark-install-config.yaml

This file was deleted.

8 changes: 8 additions & 0 deletions install/0000_30_machine-api-operator_08_rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ rules:
- get
- update

- apiGroups:
- config.openshift.io
resources:
- infrastructures
- infrastructures/status
verbs:
- get

- apiGroups:
- apps
resources:
Expand Down
74 changes: 12 additions & 62 deletions pkg/operator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,15 @@ import (
"fmt"
"io/ioutil"

"github.com/ghodss/yaml"

"bytes"
"reflect"
"text/template"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
configv1 "github.com/openshift/api/config/v1"
)

const (
// TODO(alberto): move to "quay.io/openshift/origin-kubemark-machine-controllers:v4.0.0" once available
clusterAPIControllerKubemark = "docker.io/gofed/kubemark-machine-controllers:v1.0"
// ClusterConfigNamespace is the namespace containing the cluster config
ClusterConfigNamespace = "kube-system"
// ClusterConfigName is the name of the cluster config configmap
ClusterConfigName = "cluster-config-v1"
// InstallConfigKey is the key in the cluster config configmap containing yaml installConfig data
InstallConfigKey = "install-config"
// AWSPlatformType is used to install on AWS
AWSProvider = Provider("aws")
// LibvirtPlatformType is used to install of libvirt
Expand Down Expand Up @@ -93,61 +82,22 @@ type InstallPlatform struct {
None interface{} `json:"none,omitempty"`
}

func getInstallConfig(client kubernetes.Interface) (*InstallConfig, error) {
cm, err := client.CoreV1().ConfigMaps(ClusterConfigNamespace).Get(ClusterConfigName, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("failed getting clusterconfig %s/%s: %v", ClusterConfigNamespace, ClusterConfigName, err)
}

return getInstallConfigFromClusterConfig(cm)
}

// getInstallConfigFromClusterConfig builds an install config from the cluster config.
func getInstallConfigFromClusterConfig(clusterConfig *corev1.ConfigMap) (*InstallConfig, error) {
icYaml, ok := clusterConfig.Data[InstallConfigKey]
if !ok {
return nil, fmt.Errorf("missing %q in configmap", InstallConfigKey)
}
var ic InstallConfig
if err := yaml.Unmarshal([]byte(icYaml), &ic); err != nil {
return nil, fmt.Errorf("invalid InstallConfig: %v yaml: %s", err, icYaml)
}
return &ic, nil
}

func getProviderFromInstallConfig(installConfig *InstallConfig) (Provider, error) {
v := reflect.ValueOf(installConfig.InstallPlatform)
var nonNilFields int

for i := 0; i < v.NumField(); i++ {
if v.Field(i).Interface() != nil {
nonNilFields = nonNilFields + 1
}
if nonNilFields > 1 {
return "", fmt.Errorf("more than one platform provider given")
}
}

if installConfig.AWS != nil {
func getProviderFromInfrastructure(infra *configv1.Infrastructure) (Provider, error) {
switch infra.Status.Platform {
case configv1.AWSPlatform:
return AWSProvider, nil
}
if installConfig.Libvirt != nil {
case configv1.LibvirtPlatform:
return LibvirtProvider, nil
}
if installConfig.OpenStack != nil {
case configv1.OpenStackPlatform:
return OpenStackProvider, nil
}
if installConfig.Kubemark != nil {
return KubemarkProvider, nil
}
if installConfig.BareMetal != nil {
return BareMetalProvider, nil
}
if installConfig.Azure != nil {
case configv1.AzurePlatform:
return AzureProvider, nil
}
if installConfig.None != nil {
case configv1.NonePlatform:
return NoneProvider, nil
case configv1.PlatformType("kubemark"):
return KubemarkProvider, nil
case configv1.PlatformType("baremetal"):
return BareMetalProvider, nil
}
return "", fmt.Errorf("no platform provider found on install config")
}
Expand Down
157 changes: 36 additions & 121 deletions pkg/operator/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package operator
import (
"testing"

v1 "k8s.io/api/core/v1"
configv1 "github.com/openshift/api/config/v1"
)

var (
Expand All @@ -16,148 +16,63 @@ var (
expectedAzureImage = "quay.io/openshift/origin-azure-machine-controllers:v4.0.0"
)

func TestInstallConfigFromClusterConfig(t *testing.T) {
data := make(map[string]string)
data[InstallConfigKey] = `
admin:
email: test
password: test
sshKey: |
test
baseDomain: a-domain.com
clusterID: a7265676-7dc3-4ff3-8759-f2d6e3934e76
machines:
- name: master
platform: {}
replicas: 3
- name: worker
platform: {}
replicas: 3
metadata:
creationTimestamp: null
name: test
networking:
podCIDR: 10.2.0.0/16
serviceCIDR: 10.3.0.0/16
type: flannel
platform:
aws:
region: us-east-1
vpcCIDRBlock: 10.0.0.0/16
vpcID: ""
pullSecret: “"
`
cfg := v1.ConfigMap{
Data: data,
}

res, err := getInstallConfigFromClusterConfig(&cfg)
if err != nil {
t.Errorf("failed to get install config: %v", err)
}
if res.InstallPlatform.AWS != nil && res.InstallPlatform.Libvirt == nil && res.InstallPlatform.OpenStack == nil && res.InstallPlatform.BareMetal == nil {
t.Logf("got install config successfully: %+v", res)
} else {
t.Errorf("failed to getInstallConfigFromClusterConfig. Expected aws to be not nil, got: %+v", res)
}
}

func TestGetProviderFromInstallConfig(t *testing.T) {
var notNil = "not nil"
func TestGetProviderFromInfrastructure(t *testing.T) {
tests := []struct {
ic *InstallConfig
infra *configv1.Infrastructure
expected Provider
}{{
ic: &InstallConfig{
InstallPlatform{
AWS: notNil,
Libvirt: nil,
OpenStack: nil,
BareMetal: nil,
infra: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
Platform: configv1.AWSPlatform,
},
},
expected: AWSProvider,
},
{
ic: &InstallConfig{
InstallPlatform{
AWS: nil,
Libvirt: notNil,
OpenStack: nil,
BareMetal: nil,
},
}, {
infra: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
Platform: configv1.LibvirtPlatform,
},
expected: LibvirtProvider,
},
{
ic: &InstallConfig{
InstallPlatform{
AWS: nil,
Libvirt: nil,
OpenStack: nil,
None: notNil,
},
expected: LibvirtProvider,
}, {
infra: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
Platform: configv1.NonePlatform,
},
expected: NoneProvider,
},
{
ic: &InstallConfig{
InstallPlatform{
AWS: nil,
Libvirt: nil,
OpenStack: notNil,
BareMetal: nil,
},
expected: NoneProvider,
}, {
infra: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
Platform: configv1.OpenStackPlatform,
},
expected: OpenStackProvider,
},
{
ic: &InstallConfig{
InstallPlatform{
AWS: nil,
Libvirt: nil,
OpenStack: nil,
BareMetal: notNil,
},
expected: OpenStackProvider,
}, {
infra: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
Platform: configv1.PlatformType("baremetal"),
},
expected: BareMetalProvider,
},
{
ic: &InstallConfig{
InstallPlatform{
AWS: nil,
Libvirt: nil,
OpenStack: nil,
BareMetal: nil,
Azure: notNil,
},
expected: BareMetalProvider,
}, {
infra: &configv1.Infrastructure{
Status: configv1.InfrastructureStatus{
Platform: configv1.AzurePlatform,
},
expected: AzureProvider,
}}
},
expected: AzureProvider,
}}

for _, test := range tests {
res, err := getProviderFromInstallConfig(test.ic)
res, err := getProviderFromInfrastructure(test.infra)
if err != nil {
t.Errorf("failed getProviderFromInstallConfig: %v", err)
t.Errorf("failed getProviderFromInfrastructure: %v", err)
}
if test.expected != res {
t.Errorf("failed getProviderFromInstallConfig. Expected: %q, got: %q", test.expected, res)
t.Errorf("failed getProviderFromInfrastructure. Expected: %q, got: %q", test.expected, res)
}
}

// More than one installPlatform should error
ic := &InstallConfig{
InstallPlatform{
AWS: nil,
Libvirt: notNil,
OpenStack: notNil,
BareMetal: nil,
},
}
res, err := getProviderFromInstallConfig(ic)
if err == nil {
t.Errorf("failed getProviderFromInstallConfig. Expected error, got: %v", res)
}
}

func TestGetImagesFromJSONFile(t *testing.T) {
Expand Down
Loading