diff --git a/Gopkg.lock b/Gopkg.lock index 4a248161d30..79c8a5b0801 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -722,6 +722,15 @@ pruneopts = "NUT" revision = "4b9f6ceb6598ebd4dd6c9385ef024abf7a18159b" +[[projects]] + branch = "master" + digest = "1:03edd2a5dd0223f295350eb81a0111ec3418b19c2d0ea8a6bb48537d80ceb2f5" + name = "github.com/openshift/machine-api-operator" + packages = ["pkg/apis/vsphereprovider/v1alpha1"] + pruneopts = "NUT" + revision = "463c63d746da60d953060af0f9846d89d9521105" + source = "github.com/openshift/machine-api-operator" + [[projects]] branch = "master" digest = "1:984213011d5efba011f598ddb50f39e1207d1bb04cc354c9877b4fecf1ab1c09" @@ -1454,6 +1463,7 @@ "github.com/openshift/cluster-api-provider-libvirt/pkg/apis/libvirtproviderconfig/v1beta1", "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1", "github.com/openshift/library-go/pkg/config/clusteroperator/v1helpers", + "github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider/v1alpha1", "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1", "github.com/ovirt/cluster-api-provider-ovirt/pkg/apis", "github.com/ovirt/cluster-api-provider-ovirt/pkg/apis/ovirtprovider/v1beta1", diff --git a/Gopkg.toml b/Gopkg.toml index fd3044b9e98..c8054158221 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -116,7 +116,7 @@ required = [ branch = "master" name = "golang.org/x/oauth2" -[[constraint]] +[[constraint]] branch = "master" name = "github.com/openshift/cluster-api-provider-gcp" @@ -124,7 +124,7 @@ required = [ branch = "master" name = "github.com/openshift/machine-config-operator" -[[constraint]] +[[constraint]] name = "github.com/containers/image" version = "2.0.0" @@ -144,3 +144,8 @@ required = [ [[constraint]] name = "github.com/ovirt/go-ovirt" version = "v4.3.9" + +[[constraint]] + branch = "master" + name = "github.com/openshift/machine-api-operator" + source = "github.com/openshift/machine-api-operator" diff --git a/data/data/vsphere/bootstrap/main.tf b/data/data/vsphere/bootstrap/main.tf new file mode 100644 index 00000000000..f39dfa9c944 --- /dev/null +++ b/data/data/vsphere/bootstrap/main.tf @@ -0,0 +1,33 @@ +resource "vsphere_virtual_machine" "vm" { + name = "${var.cluster_id}-bootstrap" + resource_pool_id = var.resource_pool + datastore_id = var.datastore + num_cpus = 4 + memory = 16384 + guest_id = var.guest_id + folder = var.folder + enable_disk_uuid = "true" + + wait_for_guest_net_timeout = 0 + wait_for_guest_net_routable = false + + network_interface { + network_id = var.network + } + + disk { + label = "disk0" + size = 120 + } + + clone { + template_uuid = var.template + } + + extra_config = { + "guestinfo.ignition.config.data" = base64encode(var.ignition) + "guestinfo.ignition.config.data.encoding" = "base64" + } + tags = var.tags +} + diff --git a/data/data/vsphere/bootstrap/variables.tf b/data/data/vsphere/bootstrap/variables.tf new file mode 100644 index 00000000000..508198dc8a5 --- /dev/null +++ b/data/data/vsphere/bootstrap/variables.tf @@ -0,0 +1,40 @@ +variable "ignition" { + type = string + default = "" +} + +variable "resource_pool" { + type = string +} + +variable "folder" { + type = string +} + +variable "datastore" { + type = string +} + +variable "network" { + type = string +} + +variable "datacenter" { + type = string +} + +variable "template" { + type = string +} + +variable "guest_id" { + type = string +} + +variable "tags" { + type = list +} + +variable "cluster_id" { + type = string +} diff --git a/data/data/vsphere/main.tf b/data/data/vsphere/main.tf new file mode 100644 index 00000000000..a32ba750dbc --- /dev/null +++ b/data/data/vsphere/main.tf @@ -0,0 +1,97 @@ +provider "vsphere" { + user = var.vsphere_username + password = var.vsphere_password + vsphere_server = var.vsphere_url + allow_unverified_ssl = false +} + +data "vsphere_datacenter" "datacenter" { + name = var.vsphere_datacenter +} + +data "vsphere_compute_cluster" "cluster" { + name = var.vsphere_cluster + datacenter_id = data.vsphere_datacenter.datacenter.id +} + +data "vsphere_datastore" "datastore" { + name = var.vsphere_datastore + datacenter_id = data.vsphere_datacenter.datacenter.id +} + +data "vsphere_network" "network" { + name = var.vsphere_network + datacenter_id = data.vsphere_datacenter.datacenter.id +} + +data "vsphere_virtual_machine" "template" { + name = var.vsphere_template + datacenter_id = data.vsphere_datacenter.datacenter.id +} + +resource "vsphere_tag_category" "category" { + name = "openshift-${var.cluster_id}" + description = "Added by openshift-install do not remove" + cardinality = "SINGLE" + + associable_types = [ + "VirtualMachine", + "ResourcePool", + "Folder" + ] +} + +resource "vsphere_tag" "tag" { + name = var.cluster_id + category_id = vsphere_tag_category.category.id + description = "Added by openshift-install do not remove" +} + +resource "vsphere_folder" "folder" { + path = var.vsphere_folder + type = "vm" + datacenter_id = data.vsphere_datacenter.datacenter.id + tags = [vsphere_tag.tag.id] +} + + +module "bootstrap" { + source = "./bootstrap" + + ignition = var.ignition_bootstrap + resource_pool = data.vsphere_compute_cluster.cluster.resource_pool_id + datastore = data.vsphere_datastore.datastore.id + folder = vsphere_folder.folder.path + network = data.vsphere_network.network.id + datacenter = data.vsphere_datacenter.datacenter.id + template = data.vsphere_virtual_machine.template.id + guest_id = data.vsphere_virtual_machine.template.guest_id + + cluster_id = var.cluster_id + tags = [vsphere_tag.tag.id] +} + +module "master" { + source = "./master" + + // limitation of baremetal-runtimecfg. The hostname must be master + name = "master" + instance_count = var.master_count + ignition = var.ignition_master + + resource_pool = data.vsphere_compute_cluster.cluster.resource_pool_id + datastore = data.vsphere_datastore.datastore.id + folder = vsphere_folder.folder.path + network = data.vsphere_network.network.id + datacenter = data.vsphere_datacenter.datacenter.id + template = data.vsphere_virtual_machine.template.id + guest_id = data.vsphere_virtual_machine.template.guest_id + tags = [vsphere_tag.tag.id] + + cluster_domain = var.cluster_domain + cluster_id = var.cluster_id + memory = var.control_plane_memory_mib + num_cpus = var.control_plane_num_cpus + disk_size = var.control_plane_disk_gib +} + diff --git a/data/data/vsphere/master/ignition.tf b/data/data/vsphere/master/ignition.tf new file mode 100644 index 00000000000..9792b803bbb --- /dev/null +++ b/data/data/vsphere/master/ignition.tf @@ -0,0 +1,28 @@ +locals { + ignition_encoded = "data:text/plain;charset=utf-8;base64,${base64encode(var.ignition)}" +} + +data "ignition_file" "hostname" { + count = var.instance_count + + filesystem = "root" + path = "/etc/hostname" + mode = "420" + + content { + content = "${var.name}-${count.index}" + } +} + +data "ignition_config" "ign" { + count = var.instance_count + + append { + source = local.ignition_encoded + } + + files = [ + data.ignition_file.hostname[count.index].rendered + ] +} + diff --git a/data/data/vsphere/master/main.tf b/data/data/vsphere/master/main.tf new file mode 100644 index 00000000000..a120fc686af --- /dev/null +++ b/data/data/vsphere/master/main.tf @@ -0,0 +1,36 @@ +resource "vsphere_virtual_machine" "vm" { + count = var.instance_count + + name = "${var.cluster_id}-${var.name}-${count.index}" + resource_pool_id = var.resource_pool + datastore_id = var.datastore + num_cpus = var.num_cpus + memory = var.memory + guest_id = var.guest_id + folder = var.folder + enable_disk_uuid = "true" + + wait_for_guest_net_timeout = "0" + wait_for_guest_net_routable = "false" + + network_interface { + network_id = var.network + } + + disk { + label = "disk0" + size = var.disk_size + } + + clone { + template_uuid = var.template + } + + extra_config = { + "guestinfo.ignition.config.data" = base64encode(data.ignition_config.ign[count.index].rendered) + "guestinfo.ignition.config.data.encoding" = "base64" + } + + tags = var.tags +} + diff --git a/data/data/vsphere/master/variables.tf b/data/data/vsphere/master/variables.tf new file mode 100644 index 00000000000..5027b80cf28 --- /dev/null +++ b/data/data/vsphere/master/variables.tf @@ -0,0 +1,65 @@ +variable "name" { + type = string +} + +variable "instance_count" { + type = number +} + +variable "ignition" { + type = string + default = "" +} + +variable "resource_pool" { + type = string +} + +variable "folder" { + type = string +} + +variable "datastore" { + type = string +} + +variable "network" { + type = string +} + +variable "cluster_domain" { + type = string +} + +variable "datacenter" { + type = string +} + +variable "template" { + type = string +} + +variable "guest_id" { + type = string +} + +variable "memory" { + type = number +} + +variable "num_cpus" { + type = number +} + +variable "disk_size" { + type = number +} + +variable "tags" { + type = list +} + +variable "cluster_id" { + type = string +} + diff --git a/data/data/vsphere/master/versions.tf b/data/data/vsphere/master/versions.tf new file mode 100644 index 00000000000..ac97c6ac8e7 --- /dev/null +++ b/data/data/vsphere/master/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +} diff --git a/data/data/vsphere/variables-vsphere.tf b/data/data/vsphere/variables-vsphere.tf new file mode 100644 index 00000000000..9a09e02d2d6 --- /dev/null +++ b/data/data/vsphere/variables-vsphere.tf @@ -0,0 +1,63 @@ +////// +// vSphere variables +////// + +variable "vsphere_url" { + type = string + description = "This is the vSphere server for the environment." +} + +variable "vsphere_username" { + type = string + description = "vSphere server user for the environment." +} + +variable "vsphere_password" { + type = string + description = "vSphere server password" +} + +variable "vsphere_cluster" { + type = string + description = "This is the name of the vSphere cluster." +} + +variable "vsphere_datacenter" { + type = string + description = "This is the name of the vSphere data center." +} + +variable "vsphere_datastore" { + type = string + description = "This is the name of the vSphere data store." +} + +variable "vsphere_template" { + type = string + description = "This is the name of the VM template to clone." +} + +variable "vsphere_network" { + type = string + description = "This is the name of the publicly accessible network for cluster ingress and access." +} + +variable "vsphere_folder" { + type = string +} + +/////////// +// Control Plane machine variables +/////////// + +variable "control_plane_memory_mib" { + type = number +} + +variable "control_plane_disk_gib" { + type = number +} + +variable "control_plane_num_cpus" { + type = number +} diff --git a/data/data/vsphere/versions.tf b/data/data/vsphere/versions.tf new file mode 100644 index 00000000000..ac97c6ac8e7 --- /dev/null +++ b/data/data/vsphere/versions.tf @@ -0,0 +1,4 @@ + +terraform { + required_version = ">= 0.12" +} diff --git a/pkg/tfvars/vsphere/vsphere.go b/pkg/tfvars/vsphere/vsphere.go new file mode 100644 index 00000000000..fb0f2f83968 --- /dev/null +++ b/pkg/tfvars/vsphere/vsphere.go @@ -0,0 +1,52 @@ +package vsphere + +import ( + "encoding/json" + + vsphereapis "github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider/v1alpha1" +) + +type config struct { + VSphereURL string `json:"vsphere_url"` + VSphereUsername string `json:"vsphere_username"` + VSpherePassword string `json:"vsphere_password"` + MemoryMiB int64 `json:"control_plane_memory_mib"` + DiskGiB int32 `json:"control_plane_disk_gib"` + NumCPUs int32 `json:"control_plane_num_cpus"` + Cluster string `json:"vsphere_cluster"` + Datacenter string `json:"vsphere_datacenter"` + Datastore string `json:"vsphere_datastore"` + Folder string `json:"vsphere_folder"` + Network string `json:"vsphere_network"` + Template string `json:"vsphere_template"` +} + +// TFVarsSources contains the parameters to be converted into Terraform variables +type TFVarsSources struct { + ControlPlaneConfigs []*vsphereapis.VSphereMachineProviderSpec + Username string + Password string + Cluster string +} + +//TFVars generate vSphere-specific Terraform variables +func TFVars(sources TFVarsSources) ([]byte, error) { + controlPlaneConfig := sources.ControlPlaneConfigs[0] + + cfg := &config{ + VSphereURL: controlPlaneConfig.Workspace.Server, + VSphereUsername: sources.Username, + VSpherePassword: sources.Password, + MemoryMiB: controlPlaneConfig.MemoryMiB, + DiskGiB: controlPlaneConfig.DiskGiB, + NumCPUs: controlPlaneConfig.NumCPUs, + Cluster: sources.Cluster, + Datacenter: controlPlaneConfig.Workspace.Datacenter, + Datastore: controlPlaneConfig.Workspace.Datastore, + Folder: controlPlaneConfig.Workspace.Folder, + Network: controlPlaneConfig.Network.Devices[0].NetworkName, + Template: controlPlaneConfig.Template, + } + + return json.MarshalIndent(cfg, "", " ") +} diff --git a/vendor/github.com/openshift/machine-api-operator/LICENSE b/vendor/github.com/openshift/machine-api-operator/LICENSE new file mode 100644 index 00000000000..261eeb9e9f8 --- /dev/null +++ b/vendor/github.com/openshift/machine-api-operator/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/vendor/github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider/v1alpha1/doc.go b/vendor/github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider/v1alpha1/doc.go new file mode 100644 index 00000000000..2095a0f1ba1 --- /dev/null +++ b/vendor/github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider/v1alpha1/doc.go @@ -0,0 +1,7 @@ +// Package v1alpha1 contains API Schema definitions for the vsphereprovider v1alpha1 API group +// +k8s:openapi-gen=true +// +k8s:deepcopy-gen=package,register +// +k8s:conversion-gen=github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider +// +k8s:defaulter-gen=TypeMeta +// +groupName=vsphereprovider.machine.openshift.io +package v1alpha1 diff --git a/vendor/github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider/v1alpha1/register.go b/vendor/github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider/v1alpha1/register.go new file mode 100644 index 00000000000..40042a4a3b4 --- /dev/null +++ b/vendor/github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider/v1alpha1/register.go @@ -0,0 +1,90 @@ +// Package v1alpha1 contains API Schema definitions for the vsphereprovider v1alpha1 API group +// +k8s:openapi-gen=true +// +k8s:deepcopy-gen=package,register +// +k8s:conversion-gen=github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider +// +k8s:defaulter-gen=TypeMeta +// +groupName=vsphereprovider.machine.openshift.io +package v1alpha1 + +import ( + "encoding/json" + "fmt" + + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/klog" + "sigs.k8s.io/controller-runtime/pkg/scheme" + "sigs.k8s.io/yaml" +) + +var ( + // SchemeGroupVersion is group version used to register these objects + SchemeGroupVersion = schema.GroupVersion{Group: "vsphereprovider.openshift.io", Version: "v1beta1"} + + // SchemeBuilder is used to add go types to the GroupVersionKind scheme + SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} +) + +// RawExtensionFromProviderSpec marshals the machine provider spec. +func RawExtensionFromProviderSpec(spec *VSphereMachineProviderSpec) (*runtime.RawExtension, error) { + if spec == nil { + return &runtime.RawExtension{}, nil + } + + var rawBytes []byte + var err error + if rawBytes, err = json.Marshal(spec); err != nil { + return nil, fmt.Errorf("error marshalling providerSpec: %v", err) + } + + return &runtime.RawExtension{ + Raw: rawBytes, + }, nil +} + +// RawExtensionFromProviderStatus marshals the provider status +func RawExtensionFromProviderStatus(status *VSphereMachineProviderStatus) (*runtime.RawExtension, error) { + if status == nil { + return &runtime.RawExtension{}, nil + } + + var rawBytes []byte + var err error + if rawBytes, err = json.Marshal(status); err != nil { + return nil, fmt.Errorf("error marshalling providerStatus: %v", err) + } + + return &runtime.RawExtension{ + Raw: rawBytes, + }, nil +} + +// ProviderSpecFromRawExtension unmarshals the JSON-encoded spec +func ProviderSpecFromRawExtension(rawExtension *runtime.RawExtension) (*VSphereMachineProviderSpec, error) { + if rawExtension == nil { + return &VSphereMachineProviderSpec{}, nil + } + + spec := new(VSphereMachineProviderSpec) + if err := yaml.Unmarshal(rawExtension.Raw, &spec); err != nil { + return nil, fmt.Errorf("error unmarshalling providerSpec: %v", err) + } + + klog.V(5).Infof("Got provider spec from raw extension: %+v", spec) + return spec, nil +} + +// ProviderStatusFromRawExtension unmarshals a raw extension into a VSphereMachineProviderStatus type +func ProviderStatusFromRawExtension(rawExtension *runtime.RawExtension) (*VSphereMachineProviderStatus, error) { + if rawExtension == nil { + return &VSphereMachineProviderStatus{}, nil + } + + providerStatus := new(VSphereMachineProviderStatus) + if err := yaml.Unmarshal(rawExtension.Raw, providerStatus); err != nil { + return nil, fmt.Errorf("error unmarshalling providerStatus: %v", err) + } + + klog.V(5).Infof("Got provider Status from raw extension: %+v", providerStatus) + return providerStatus, nil +} diff --git a/vendor/github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider/v1alpha1/vsphereproviderconfig_types.go b/vendor/github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider/v1alpha1/vsphereproviderconfig_types.go new file mode 100644 index 00000000000..f8ebc442923 --- /dev/null +++ b/vendor/github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider/v1alpha1/vsphereproviderconfig_types.go @@ -0,0 +1,98 @@ +package v1alpha1 + +import ( + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// VSphereMachineProviderSpec is the type that will be embedded in a Machine.Spec.ProviderSpec field +// for an VSphere virtual machine. It is used by the vSphere machine actuator to create a single Machine. +// +k8s:openapi-gen=true +type VSphereMachineProviderSpec struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + // UserDataSecret contains a local reference to a secret that contains the + // UserData to apply to the instance + UserDataSecret *corev1.LocalObjectReference `json:"userDataSecret,omitempty"` + + // CredentialsSecret is a reference to the secret with vSphere credentials. + CredentialsSecret *corev1.LocalObjectReference `json:"credentialsSecret,omitempty"` + + // Template is the name, inventory path, or instance UUID of the template + // used to clone new machines. + Template string `json:"template"` + + Workspace *Workspace `json:"workspace,omitempty"` + + // Network is the network configuration for this machine's VM. + Network NetworkSpec `json:"network"` + + // NumCPUs is the number of virtual processors in a virtual machine. + // Defaults to the analogue property value in the template from which this + // machine is cloned. + // +optional + NumCPUs int32 `json:"numCPUs,omitempty"` + // NumCPUs is the number of cores among which to distribute CPUs in this + // virtual machine. + // Defaults to the analogue property value in the template from which this + // machine is cloned. + // +optional + NumCoresPerSocket int32 `json:"numCoresPerSocket,omitempty"` + // MemoryMiB is the size of a virtual machine's memory, in MiB. + // Defaults to the analogue property value in the template from which this + // machine is cloned. + // +optional + MemoryMiB int64 `json:"memoryMiB,omitempty"` + // DiskGiB is the size of a virtual machine's disk, in GiB. + // Defaults to the analogue property value in the template from which this + // machine is cloned. + // +optional + DiskGiB int32 `json:"diskGiB,omitempty"` +} + +// NetworkSpec defines the virtual machine's network configuration. +type NetworkSpec struct { + Devices []NetworkDeviceSpec `json:"devices"` +} + +// NetworkDeviceSpec defines the network configuration for a virtual machine's +// network device. +type NetworkDeviceSpec struct { + // NetworkName is the name of the vSphere network to which the device + // will be connected. + NetworkName string `json:"networkName"` +} + +// WorkspaceConfig defines a workspace configuration for the vSphere cloud +// provider. +type Workspace struct { + // Server is the IP address or FQDN of the vSphere endpoint. + // +optional + Server string `gcfg:"server,omitempty" json:"server,omitempty"` + + // Datacenter is the datacenter in which VMs are created/located. + // +optional + Datacenter string `gcfg:"datacenter,omitempty" json:"datacenter,omitempty"` + + // Folder is the folder in which VMs are created/located. + // +optional + Folder string `gcfg:"folder,omitempty" json:"folder,omitempty"` + + // Datastore is the datastore in which VMs are created/located. + // +optional + Datastore string `gcfg:"default-datastore,omitempty" json:"datastore,omitempty"` + + // ResourcePool is the resource pool in which VMs are created/located. + // +optional + ResourcePool string `gcfg:"resourcepool-path,omitempty" json:"resourcePool,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +func init() { + SchemeBuilder.Register(&VSphereMachineProviderSpec{}) +} diff --git a/vendor/github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider/v1alpha1/vsphereproviderstatus_types.go b/vendor/github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider/v1alpha1/vsphereproviderstatus_types.go new file mode 100644 index 00000000000..5cacc2153ce --- /dev/null +++ b/vendor/github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider/v1alpha1/vsphereproviderstatus_types.go @@ -0,0 +1,43 @@ +package v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// VSphereMachineProviderStatus is the type that will be embedded in a Machine.Status.ProviderStatus field. +// It contains VSphere-specific status information. +// +k8s:openapi-gen=true +type VSphereMachineProviderStatus struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + // TODO: populate what we need here: + // InstanceID is the ID of the instance in VSphere + // +optional + //InstanceID *string `json:"instanceId,omitempty"` + + // InstanceState is the provisioning state of the VSphere Instance. + // +optional + //InstanceState *string `json:"instanceState,omitempty"` + // + // TaskRef? + // Ready? + // Conditions is a set of conditions associated with the Machine to indicate + // errors or other status + // Conditions []VSphereMachineProviderCondition `json:"conditions,omitempty"` + + // TaskRef is a managed object reference to a Task related to the machine. + // This value is set automatically at runtime and should not be set or + // modified by users. + // +optional + TaskRef string `json:"taskRef,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +func init() { + SchemeBuilder.Register(&VSphereMachineProviderStatus{}) +} diff --git a/vendor/github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider/v1alpha1/zz_generated.deepcopy.go b/vendor/github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 00000000000..9d24526c8bd --- /dev/null +++ b/vendor/github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,143 @@ +// +build !ignore_autogenerated + +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Copyright 2019 Red Hat, Inc. + * + */ + +// Code generated by controller-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NetworkDeviceSpec) DeepCopyInto(out *NetworkDeviceSpec) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkDeviceSpec. +func (in *NetworkDeviceSpec) DeepCopy() *NetworkDeviceSpec { + if in == nil { + return nil + } + out := new(NetworkDeviceSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NetworkSpec) DeepCopyInto(out *NetworkSpec) { + *out = *in + if in.Devices != nil { + in, out := &in.Devices, &out.Devices + *out = make([]NetworkDeviceSpec, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkSpec. +func (in *NetworkSpec) DeepCopy() *NetworkSpec { + if in == nil { + return nil + } + out := new(NetworkSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *VSphereMachineProviderSpec) DeepCopyInto(out *VSphereMachineProviderSpec) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + if in.UserDataSecret != nil { + in, out := &in.UserDataSecret, &out.UserDataSecret + *out = new(v1.LocalObjectReference) + **out = **in + } + if in.CredentialsSecret != nil { + in, out := &in.CredentialsSecret, &out.CredentialsSecret + *out = new(v1.LocalObjectReference) + **out = **in + } + if in.Workspace != nil { + in, out := &in.Workspace, &out.Workspace + *out = new(Workspace) + **out = **in + } + in.Network.DeepCopyInto(&out.Network) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VSphereMachineProviderSpec. +func (in *VSphereMachineProviderSpec) DeepCopy() *VSphereMachineProviderSpec { + if in == nil { + return nil + } + out := new(VSphereMachineProviderSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *VSphereMachineProviderSpec) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *VSphereMachineProviderStatus) DeepCopyInto(out *VSphereMachineProviderStatus) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new VSphereMachineProviderStatus. +func (in *VSphereMachineProviderStatus) DeepCopy() *VSphereMachineProviderStatus { + if in == nil { + return nil + } + out := new(VSphereMachineProviderStatus) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *VSphereMachineProviderStatus) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Workspace) DeepCopyInto(out *Workspace) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Workspace. +func (in *Workspace) DeepCopy() *Workspace { + if in == nil { + return nil + } + out := new(Workspace) + in.DeepCopyInto(out) + return out +}