-
Notifications
You must be signed in to change notification settings - Fork 231
operator: use infrastructure.config.openshfit.io for platformtype #256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
looks like storage field need to be set here or dropped from the CRD def @abhinavdahiya
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also I don't see status on the CRD def? |
||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -60,86 +49,21 @@ 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 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't this function now just return
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. didn't want to change more than required. :) |
||
| 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 | ||
| } | ||
| return "", fmt.Errorf("no platform provider found on install config") | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/AWS/kubemark