Skip to content
Closed
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:
platform: AWS
```

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.

104 changes: 17 additions & 87 deletions pkg/operator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,13 @@ 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 (
// 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 All @@ -33,7 +22,9 @@ const (
KubemarkProvider = Provider("kubemark")
// BareMetalPlatformType is used for install using managed Bare Metal
BareMetalProvider = Provider("baremetal")
NoneProvider = Provider("none")
// VSpherePlatformType is used for install on vSphere
VSphereProvider = Provider("vsphere")
NoneProvider = Provider("none")
)

type Provider string
Expand All @@ -60,85 +51,22 @@ type Images struct {
ClusterAPIControllerBareMetal string `json:"clusterAPIControllerBareMetal"`
}

// InstallConfig contains the mao relevant config coming from the install config, i.e provider
type InstallConfig struct {
InstallPlatform `json:"platform"`
}

// InstallPlatform is the configuration for the specific platform upon which to perform
// the installation. Only one of the platform configuration should be set
type InstallPlatform struct {
// AWS is the configuration used when running on AWS
AWS interface{} `json:"aws,omitempty"`

// Libvirt is the configuration used when running on libvirt
Libvirt interface{} `json:"libvirt,omitempty"`

// OpenStack is the configuration used when running on OpenStack
OpenStack interface{} `json:"openstack,omitempty"`

// Kubemark is the configuration used when running with Kubemark
Kubemark interface{} `json:"kubemark,omitempty"`

// BareMetal is the configuration used when running on managed Bare Metal
BareMetal interface{} `json:"baremetal,omitempty"`

// None is the configuration used when running on unmanaged UPI
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 {
case configv1.NonePlatform:
return NoneProvider, nil
case configv1.PlatformType("kubemark"):
return KubemarkProvider, nil
}
if installConfig.BareMetal != nil {
case configv1.PlatformType("baremetal"):
return BareMetalProvider, nil
}
if installConfig.None != nil {
return NoneProvider, nil
case configv1.VSpherePlatform:
return VSphereProvider, nil
}
return "", fmt.Errorf("no platform provider found on install config")
}
Expand Down Expand Up @@ -168,6 +96,8 @@ func getProviderControllerFromImages(provider Provider, images Images) (string,
return images.ClusterAPIControllerKubemark, nil
case BareMetalProvider:
return images.ClusterAPIControllerBareMetal, nil
case VSphereProvider:
return "vSphere", nil
case NoneProvider:
return "None", nil
}
Expand Down
Loading