From 7a396d9137140e9824becbe217392197b8c9529c Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 7 Feb 2019 22:21:13 -0800 Subject: [PATCH 1/2] pkg/asset/machines: Convert Master to a WriteableAsset Since 3326b6b3 (pkg/tfvars: Pull from []Machine instead of InstallConfig, 2018-11-28, #792), we've been consuming structured master configurations to generate Terraform variables. But before this commit, the Openshift asset was the WriteableAsset responsible for the master configs, giving you the following issue: 1. openshift-install create manifests i. Master asset populated with structured data ii. Openshift asset pulls in Master, flattens to YAML, and writes to disk. 2. openshift-install create cluster i. Openshift asset reads master YAML from disk. ii. TerraformVariables asset pulls in Master, but it's empty. iii. Panic [1]. With this commit, responsibility for reading and writing master manifests to disk gets shifted to the Master asset itself. I've dropped the structured Master properties (Machines and MachineDeprecated) in favor of new methods on the asset. There are three possible paths towards recovering the asset that we feed in to TerraformVariables: a. After rendering it with Generate. This information had been structured before this commit, so no problems here. b. After reading from the disk. This information could be unmarshalled in Master.Load(), but... c. After loading it from the state file. There are no hooks for custom unmarshalling in this pathway, so while the generic YAML unmarshal would give us a structured machine object, it would not unmarshal the RawExtension that holds the provider spec. The lack of custom-unmarshal hooks for (c) means there's no reliable way to use Master properties to feed TerraformVariables structured provider information. With this commit, we use Master methods instead. That's just as efficient for the (b) and (c) cases, and while it's an uneccessary (de)serialize cycle for (a), that's not too expensive. Unpacking the YAML data into the appropriate structures is a bit hairy. I'm not familiar with this code though, maybe there's a better way. It will help once we complete the shift to the OpenShift machine-API types started in cf60daa1 (Pivot aws from cluster.k8s.io into machine.openshift.io, 2019-02-01, #1175). I've also taken the opportunity to drop the list. It saves us a few lines of code for (de)serializing, and there's no upside to collecting the Machine configs together in a single file. The "glob, but not the master files" logic in the Openshift loader is also a bit ugly. Moving forward, I expect us to push the remaining Openshift assets out into their own assets as well, which would allow us to tighten down on the wildcard there. There's also a bit of dancing to ensure our Machine filenames are ordered by increasing index. I'm padding the filenames with %02d (for example) to get ...-01.yaml, etc. so they come back in the right order on load (filepath.Glob sorts its output [2]). To avoid hard-coding a pad size, I format the largest index, measure its length, and use that length to construct padFormat. [1]: https://github.com/openshift/installer/issues/1205 [2]: https://github.com/golang/go/blob/go1.11.5/src/path/filepath/match.go#L325 --- pkg/asset/cluster/tfvars.go | 26 ++- pkg/asset/ignition/bootstrap/bootstrap.go | 3 + pkg/asset/machines/aws/machines.go | 2 +- pkg/asset/machines/master.go | 196 +++++++++++++++++++--- pkg/asset/manifests/openshift.go | 65 ++----- pkg/asset/store/assetcreate_test.go | 9 +- pkg/asset/targets/targets.go | 2 + pkg/tfvars/aws/aws.go | 4 +- 8 files changed, 225 insertions(+), 82 deletions(-) diff --git a/pkg/asset/cluster/tfvars.go b/pkg/asset/cluster/tfvars.go index 4b76ea7b6ff..3a1f365c19d 100644 --- a/pkg/asset/cluster/tfvars.go +++ b/pkg/asset/cluster/tfvars.go @@ -21,7 +21,7 @@ import ( "github.com/openshift/installer/pkg/types/openstack" "github.com/pkg/errors" "github.com/sirupsen/logrus" - awsprovider "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1" + awsprovider "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1" openstackprovider "sigs.k8s.io/cluster-api-provider-openstack/pkg/apis/openstackproviderconfig/v1alpha1" ) @@ -76,10 +76,8 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error { bootstrapIgn := string(bootstrapIgnAsset.Files()[0].Data) masterIgn := string(masterIgnAsset.Files()[0].Data) - masterCount := len(mastersAsset.Machines) - if mastersAsset.Machines == nil { - masterCount = len(mastersAsset.MachinesDeprecated) - } + masters := mastersAsset.Machines() + masterCount := len(masters) data, err := tfvars.TFVars( clusterID.ClusterID, installConfig.Config.ObjectMeta.Name, @@ -105,8 +103,12 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error { switch platform := installConfig.Config.Platform.Name(); platform { case aws.Name: + masters, err := mastersAsset.StructuredMachines() + if err != nil { + return err + } data, err = awstfvars.TFVars( - mastersAsset.Machines[0].Spec.ProviderSpec.Value.Object.(*awsprovider.AWSMachineProviderConfig), + masters[0].Spec.ProviderSpec.Value.Object.(*awsprovider.AWSMachineProviderConfig), ) if err != nil { return errors.Wrapf(err, "failed to get %s Terraform variables", platform) @@ -116,8 +118,12 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error { Data: data, }) case libvirt.Name: + masters, err := mastersAsset.StructuredMachines() + if err != nil { + return err + } data, err = libvirttfvars.TFVars( - mastersAsset.Machines[0].Spec.ProviderSpec.Value.Object.(*libvirtprovider.LibvirtMachineProviderConfig), + masters[0].Spec.ProviderSpec.Value.Object.(*libvirtprovider.LibvirtMachineProviderConfig), string(*rhcosImage), &installConfig.Config.Networking.MachineCIDR.IPNet, installConfig.Config.Platform.Libvirt.Network.IfName, @@ -132,8 +138,12 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error { }) case none.Name: case openstack.Name: + masters, err := mastersAsset.StructuredMachinesDeprecated() + if err != nil { + return err + } data, err = openstacktfvars.TFVars( - mastersAsset.MachinesDeprecated[0].Spec.ProviderSpec.Value.Object.(*openstackprovider.OpenstackProviderSpec), + masters[0].Spec.ProviderSpec.Value.Object.(*openstackprovider.OpenstackProviderSpec), installConfig.Config.Platform.OpenStack.Region, installConfig.Config.Platform.OpenStack.ExternalNetwork, installConfig.Config.Platform.OpenStack.TrunkSupport, diff --git a/pkg/asset/ignition/bootstrap/bootstrap.go b/pkg/asset/ignition/bootstrap/bootstrap.go index a6850b12302..8266d171e60 100644 --- a/pkg/asset/ignition/bootstrap/bootstrap.go +++ b/pkg/asset/ignition/bootstrap/bootstrap.go @@ -22,6 +22,7 @@ import ( "github.com/openshift/installer/pkg/asset/ignition" "github.com/openshift/installer/pkg/asset/installconfig" "github.com/openshift/installer/pkg/asset/kubeconfig" + "github.com/openshift/installer/pkg/asset/machines" "github.com/openshift/installer/pkg/asset/manifests" "github.com/openshift/installer/pkg/asset/tls" "github.com/openshift/installer/pkg/types" @@ -75,6 +76,7 @@ func (a *Bootstrap) Dependencies() []asset.Asset { &tls.JournalCertKey{}, &kubeconfig.Admin{}, &kubeconfig.Kubelet{}, + &machines.Master{}, &manifests.Manifests{}, &manifests.Openshift{}, } @@ -347,6 +349,7 @@ func (a *Bootstrap) addParentFiles(dependencies asset.Parents) { for _, asset := range []asset.WritableAsset{ &kubeconfig.Admin{}, &kubeconfig.Kubelet{}, + &machines.Master{}, &tls.KubeCA{}, &tls.AggregatorCA{}, &tls.EtcdCA{}, diff --git a/pkg/asset/machines/aws/machines.go b/pkg/asset/machines/aws/machines.go index 634484d8d7e..a4a52e88580 100644 --- a/pkg/asset/machines/aws/machines.go +++ b/pkg/asset/machines/aws/machines.go @@ -11,7 +11,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/sets" "k8s.io/utils/pointer" - awsprovider "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1" + awsprovider "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1" "github.com/openshift/installer/pkg/types" "github.com/openshift/installer/pkg/types/aws" diff --git a/pkg/asset/machines/master.go b/pkg/asset/machines/master.go index 11d88e03676..de87d07a796 100644 --- a/pkg/asset/machines/master.go +++ b/pkg/asset/machines/master.go @@ -2,11 +2,13 @@ package machines import ( "fmt" + "os" + "path/filepath" + "github.com/ghodss/yaml" + libvirtapi "github.com/openshift/cluster-api-provider-libvirt/pkg/apis" + libvirtprovider "github.com/openshift/cluster-api-provider-libvirt/pkg/apis/libvirtproviderconfig/v1alpha1" machineapi "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1" - "github.com/pkg/errors" - clusterapi "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1" - "github.com/openshift/installer/pkg/asset" "github.com/openshift/installer/pkg/asset/ignition/machine" "github.com/openshift/installer/pkg/asset/installconfig" @@ -19,16 +21,32 @@ import ( libvirttypes "github.com/openshift/installer/pkg/types/libvirt" nonetypes "github.com/openshift/installer/pkg/types/none" openstacktypes "github.com/openshift/installer/pkg/types/openstack" + "github.com/pkg/errors" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/serializer" + awsapi "sigs.k8s.io/cluster-api-provider-aws/pkg/apis" + awsprovider "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1" + openstackapi "sigs.k8s.io/cluster-api-provider-openstack/pkg/apis" + openstackprovider "sigs.k8s.io/cluster-api-provider-openstack/pkg/apis/openstackproviderconfig/v1alpha1" + clusterapi "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1" ) // Master generates the machines for the `master` machine pool. type Master struct { - Machines []machineapi.Machine - MachinesDeprecated []clusterapi.Machine - UserDataSecretRaw []byte + FileList []*asset.File } -var _ asset.Asset = (*Master)(nil) +var ( + directory = "openshift" + + // MasterMachineFileName is the format string for constucting the master Machine filenames. + MasterMachineFileName = "99_openshift-cluster-api_master-machines-%s.yaml" + + // MasterUserDataFileName is the filename used for the master user-data secret. + MasterUserDataFileName = "99_openshift-cluster-api_master-user-data-secret.yaml" + + _ asset.WritableAsset = (*Master)(nil) +) // Name returns a human friendly name for the Master Asset. func (m *Master) Name() string { @@ -59,12 +77,8 @@ func (m *Master) Generate(dependencies asset.Parents) error { dependencies.Get(clusterID, installconfig, rhcosImage, mign) var err error - userDataMap := map[string][]byte{"master-user-data": mign.File.Data} - m.UserDataSecretRaw, err = userDataList(userDataMap) - if err != nil { - return errors.Wrap(err, "failed to create user-data secret for master machines") - } - + machines := []machineapi.Machine{} + machinesDeprecated := []clusterapi.Machine{} ic := installconfig.Config pool := masterPool(ic.Machines) switch ic.Platform.Name() { @@ -81,42 +95,180 @@ func (m *Master) Generate(dependencies asset.Parents) error { mpool.Zones = azs } pool.Platform.AWS = &mpool - m.Machines, err = aws.Machines(clusterID.ClusterID, ic, &pool, string(*rhcosImage), "master", "master-user-data") + machines, err = aws.Machines(clusterID.ClusterID, ic, &pool, string(*rhcosImage), "master", "master-user-data") if err != nil { return errors.Wrap(err, "failed to create master machine objects") } - aws.ConfigMasters(m.Machines, ic.ObjectMeta.Name) + aws.ConfigMasters(machines, ic.ObjectMeta.Name) case libvirttypes.Name: mpool := defaultLibvirtMachinePoolPlatform() mpool.Set(ic.Platform.Libvirt.DefaultMachinePlatform) mpool.Set(pool.Platform.Libvirt) pool.Platform.Libvirt = &mpool - m.Machines, err = libvirt.Machines(clusterID.ClusterID, ic, &pool, "master", "master-user-data") + machines, err = libvirt.Machines(clusterID.ClusterID, ic, &pool, "master", "master-user-data") if err != nil { return errors.Wrap(err, "failed to create master machine objects") } case nonetypes.Name: - // This is needed to ensure that roundtrip generate-load tests pass when - // comparing this value. Otherwise, generate will use a nil value while - // load will use an empty slice. - m.Machines = []machineapi.Machine{} + return nil case openstacktypes.Name: mpool := defaultOpenStackMachinePoolPlatform(ic.Platform.OpenStack.FlavorName) mpool.Set(ic.Platform.OpenStack.DefaultMachinePlatform) mpool.Set(pool.Platform.OpenStack) pool.Platform.OpenStack = &mpool - m.MachinesDeprecated, err = openstack.Machines(clusterID.ClusterID, ic, &pool, string(*rhcosImage), "master", "master-user-data") + machinesDeprecated, err = openstack.Machines(clusterID.ClusterID, ic, &pool, string(*rhcosImage), "master", "master-user-data") if err != nil { return errors.Wrap(err, "failed to create master machine objects") } - openstack.ConfigMasters(m.MachinesDeprecated, ic.ObjectMeta.Name) + openstack.ConfigMasters(machinesDeprecated, ic.ObjectMeta.Name) default: return fmt.Errorf("invalid Platform") } + + userDataMap := map[string][]byte{"master-user-data": mign.File.Data} + data, err := userDataList(userDataMap) + if err != nil { + return errors.Wrap(err, "failed to create user-data secret for master machines") + } + + m.FileList = []*asset.File{{ + Filename: filepath.Join(directory, MasterUserDataFileName), + Data: data, + }} + + machinesAll := []runtime.Object{} + for _, machine := range machines { + machinesAll = append(machinesAll, &machine) + } + for _, machine := range machinesDeprecated { + machinesAll = append(machinesAll, &machine) + } + + count := len(machinesAll) + if count == 0 { + return errors.New("at least one master machine must be configured") + } + + padFormat := fmt.Sprintf("%%0%dd", len(fmt.Sprintf("%d", count))) + for i, machine := range machinesAll { + data, err := yaml.Marshal(machine) + if err != nil { + return errors.Wrapf(err, "marshal master %d", i) + } + + padded := fmt.Sprintf(padFormat, i) + m.FileList = append(m.FileList, &asset.File{ + Filename: filepath.Join(directory, fmt.Sprintf(MasterMachineFileName, padded)), + Data: data, + }) + } + return nil } +// Files returns the files generated by the asset. +func (m *Master) Files() []*asset.File { + return m.FileList +} + +// Load reads the asset files from disk. +func (m *Master) Load(f asset.FileFetcher) (found bool, err error) { + file, err := f.FetchByName(filepath.Join(directory, MasterUserDataFileName)) + if err != nil { + if os.IsNotExist(err) { + return false, nil + } + return false, err + } + m.FileList = []*asset.File{file} + + fileList, err := f.FetchByPattern(filepath.Join(directory, fmt.Sprintf(MasterMachineFileName, "*"))) + if err != nil { + return true, err + } + + if len(fileList) == 0 { + return true, errors.Errorf("master machine manifests are required if you also provide %s", file.Filename) + } + + m.FileList = append(m.FileList, fileList...) + return true, nil +} + +// Machines returns master Machine manifest YAML. +func (m *Master) Machines() [][]byte { + machines := [][]byte{} + userData := filepath.Join(directory, MasterUserDataFileName) + for _, file := range m.FileList { + if file.Filename == userData { + continue + } + machines = append(machines, file.Data) + } + return machines +} + +// StructuredMachines returns master Machine manifest structures. +func (m *Master) StructuredMachines() ([]machineapi.Machine, error) { + scheme := runtime.NewScheme() + awsapi.AddToScheme(scheme) + libvirtapi.AddToScheme(scheme) + openstackapi.AddToScheme(scheme) + decoder := serializer.NewCodecFactory(scheme).UniversalDecoder( + awsprovider.SchemeGroupVersion, + libvirtprovider.SchemeGroupVersion, + openstackprovider.SchemeGroupVersion, + ) + + machines := []machineapi.Machine{} + for i, data := range m.Machines() { + machine := &machineapi.Machine{} + err := yaml.Unmarshal(data, &machine) + if err != nil { + return machines, errors.Wrapf(err, "unmarshal master %d", i) + } + + obj, _, err := decoder.Decode(machine.Spec.ProviderSpec.Value.Raw, nil, nil) + if err != nil { + return machines, errors.Wrapf(err, "unmarshal master %d", i) + } + + machine.Spec.ProviderSpec.Value = &runtime.RawExtension{Object: obj} + machines = append(machines, *machine) + } + + return machines, nil +} + +// StructuredMachinesDeprecated returns master Machine manifest structures. +func (m *Master) StructuredMachinesDeprecated() ([]clusterapi.Machine, error) { + scheme := runtime.NewScheme() + openstackapi.AddToScheme(scheme) + decoder := serializer.NewCodecFactory(scheme).UniversalDecoder( + openstackprovider.SchemeGroupVersion, + ) + + machines := []clusterapi.Machine{} + for i, data := range m.Machines() { + machine := &clusterapi.Machine{} + err := yaml.Unmarshal(data, &machine) + if err != nil { + return machines, errors.Wrapf(err, "unmarshal master %d", i) + } + + obj, _, err := decoder.Decode(machine.Spec.ProviderSpec.Value.Raw, nil, nil) + if err != nil { + return machines, errors.Wrapf(err, "unmarshal master %d", i) + } + + machine.Spec.ProviderSpec.Value = &runtime.RawExtension{Object: obj} + machines = append(machines, *machine) + } + + return machines, nil +} + func masterPool(pools []types.MachinePool) types.MachinePool { for idx, pool := range pools { if pool.Name == "master" { diff --git a/pkg/asset/manifests/openshift.go b/pkg/asset/manifests/openshift.go index c01bf5c2cf6..c63a9d70b15 100644 --- a/pkg/asset/manifests/openshift.go +++ b/pkg/asset/manifests/openshift.go @@ -2,6 +2,7 @@ package manifests import ( "encoding/base64" + "fmt" "path/filepath" "github.com/aws/aws-sdk-go/aws/session" @@ -14,18 +15,13 @@ import ( // https://github.com/openshift/installer/pull/854 goyaml "gopkg.in/yaml.v2" - "github.com/ghodss/yaml" "github.com/gophercloud/utils/openstack/clientconfig" - machineapi "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1" "github.com/openshift/installer/pkg/asset" "github.com/openshift/installer/pkg/asset/installconfig" "github.com/openshift/installer/pkg/asset/machines" osmachine "github.com/openshift/installer/pkg/asset/machines/openstack" "github.com/openshift/installer/pkg/asset/password" "github.com/openshift/installer/pkg/asset/templates/content/openshift" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - clusterapi "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1" ) const ( @@ -53,7 +49,6 @@ func (o *Openshift) Dependencies() []asset.Asset { &installconfig.InstallConfig{}, &ClusterK8sIO{}, &machines.Worker{}, - &machines.Master{}, &password.KubeadminPassword{}, &openshift.BindingDiscovery{}, @@ -69,8 +64,7 @@ func (o *Openshift) Generate(dependencies asset.Parents) error { kubeadminPassword := &password.KubeadminPassword{} clusterk8sio := &ClusterK8sIO{} worker := &machines.Worker{} - master := &machines.Master{} - dependencies.Get(installConfig, clusterk8sio, worker, master, kubeadminPassword) + dependencies.Get(installConfig, clusterk8sio, worker, kubeadminPassword) var cloudCreds cloudCredsSecretData platform := installConfig.Config.Platform.Name() switch platform { @@ -128,23 +122,10 @@ func (o *Openshift) Generate(dependencies asset.Parents) error { kubeadminPasswordSecret, roleCloudCredsSecretReader) - var masterMachines []byte - var err error - if master.Machines != nil { - masterMachines, err = listFromMachines(master.Machines) - } else { - masterMachines, err = listFromMachinesDeprecated(master.MachinesDeprecated) - } - if err != nil { - return err - } - assetData := map[string][]byte{ "99_binding-discovery.yaml": []byte(bindingDiscovery.Files()[0].Data), "99_kubeadmin-password-secret.yaml": applyTemplateData(kubeadminPasswordSecret.Files()[0].Data, templateData), "99_openshift-cluster-api_cluster.yaml": clusterk8sio.Raw, - "99_openshift-cluster-api_master-machines.yaml": masterMachines, - "99_openshift-cluster-api_master-user-data-secret.yaml": master.UserDataSecretRaw, "99_openshift-cluster-api_worker-machineset.yaml": worker.MachineSetRaw, "99_openshift-cluster-api_worker-user-data-secret.yaml": worker.UserDataSecretRaw, } @@ -179,35 +160,25 @@ func (o *Openshift) Load(f asset.FileFetcher) (bool, error) { if err != nil { return false, err } - o.FileList = fileList - asset.SortFiles(o.FileList) - return len(fileList) > 0, nil -} -func listFromMachines(objs []machineapi.Machine) ([]byte, error) { - list := &metav1.List{ - TypeMeta: metav1.TypeMeta{ - APIVersion: "v1", - Kind: "List", - }, - } - for idx := range objs { - list.Items = append(list.Items, runtime.RawExtension{Object: &objs[idx]}) - } + masterMachinePattern := fmt.Sprintf(machines.MasterMachineFileName, "*") + for _, file := range fileList { + filename := filepath.Base(file.Filename) + if filename == machines.MasterUserDataFileName { + continue + } - return yaml.Marshal(list) -} + matched, err := filepath.Match(masterMachinePattern, filename) + if err != nil { + return true, err + } + if matched { + continue + } -func listFromMachinesDeprecated(objs []clusterapi.Machine) ([]byte, error) { - list := &metav1.List{ - TypeMeta: metav1.TypeMeta{ - APIVersion: "v1", - Kind: "List", - }, - } - for idx := range objs { - list.Items = append(list.Items, runtime.RawExtension{Object: &objs[idx]}) + o.FileList = append(o.FileList, file) } - return yaml.Marshal(list) + asset.SortFiles(o.FileList) + return len(o.FileList) > 0, nil } diff --git a/pkg/asset/store/assetcreate_test.go b/pkg/asset/store/assetcreate_test.go index 795cc7e6f15..acdbf6c0f0c 100644 --- a/pkg/asset/store/assetcreate_test.go +++ b/pkg/asset/store/assetcreate_test.go @@ -86,14 +86,19 @@ func TestCreatedAssetsAreNotDirty(t *testing.T) { t.Fatalf("failed to create new asset store: %v", err) } + exists := struct{}{} + emptyAssets := map[string]struct{}{ + "Master Machines": exists, // no files for the 'none' platform + "Metadata": exists, // read-only + } for _, a := range tc.targets { + name := a.Name() newAsset := reflect.New(reflect.TypeOf(a).Elem()).Interface().(asset.WritableAsset) if err := newAssetStore.Fetch(newAsset); err != nil { t.Fatalf("failed to fetch %q in new store: %v", a.Name(), err) } assetState := newAssetStore.assets[reflect.TypeOf(a)] - // Make an exception for metadata. It's files are read-only. - if a.Name() != "Metadata" { + if _, ok := emptyAssets[name]; !ok { assert.Truef(t, assetState.presentOnDisk, "asset %q was not found on disk", a.Name()) } } diff --git a/pkg/asset/targets/targets.go b/pkg/asset/targets/targets.go index db253ccee39..bb153c322b4 100644 --- a/pkg/asset/targets/targets.go +++ b/pkg/asset/targets/targets.go @@ -7,6 +7,7 @@ import ( "github.com/openshift/installer/pkg/asset/ignition/machine" "github.com/openshift/installer/pkg/asset/installconfig" "github.com/openshift/installer/pkg/asset/kubeconfig" + "github.com/openshift/installer/pkg/asset/machines" "github.com/openshift/installer/pkg/asset/manifests" "github.com/openshift/installer/pkg/asset/templates/content/bootkube" "github.com/openshift/installer/pkg/asset/templates/content/openshift" @@ -21,6 +22,7 @@ var ( // Manifests are the manifests targeted assets. Manifests = []asset.WritableAsset{ + &machines.Master{}, &manifests.Manifests{}, &manifests.Openshift{}, } diff --git a/pkg/tfvars/aws/aws.go b/pkg/tfvars/aws/aws.go index 411e99a0644..286b9cad286 100644 --- a/pkg/tfvars/aws/aws.go +++ b/pkg/tfvars/aws/aws.go @@ -5,7 +5,7 @@ import ( "encoding/json" "github.com/pkg/errors" - "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1" + "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1" ) type config struct { @@ -19,7 +19,7 @@ type config struct { } // TFVars generates AWS-specific Terraform variables launching the cluster. -func TFVars(masterConfig *v1alpha1.AWSMachineProviderConfig) ([]byte, error) { +func TFVars(masterConfig *v1beta1.AWSMachineProviderConfig) ([]byte, error) { tags := make(map[string]string, len(masterConfig.Tags)) for _, tag := range masterConfig.Tags { tags[tag.Name] = tag.Value From d983eaee20f1669738c34a6e7d9cfd9525c80a72 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 8 Feb 2019 17:47:21 -0800 Subject: [PATCH 2/2] vendor: Bump cluster-API providers And shift the AWS provider's commit to land after they fixed registration [1] and also after their pivot to v1beta1 [2] (because 3a125a69, Change awsproviderconfig.k8s.io/v1alpha1 API version to awsproviderconfig.openshift.io/v1beta1, 2019-02-11, #1223 already started us along that pivot). Generated (after the Gopkg.toml bump) with: $ dep ensure using: $ dep version dep: version : v0.5.0-31-g73b3afe build date : 2019-02-08 git hash : 73b3afe go version : go1.10.3 go compiler : gc platform : linux/amd64 features : ImportDuringSolve=false [1]: https://github.com/openshift/cluster-api-provider-aws/pull/149 [2]: https://github.com/openshift/cluster-api-provider-aws/pull/152 --- Gopkg.lock | 29 ++++++++++---- Gopkg.toml | 2 +- ...toscheme_libvirtproviderconfig_v1alpha1.go | 10 +++++ .../pkg/apis/apis.go | 17 ++++++++ ...ddtoscheme_openshiftawsprovider_v1beta1.go | 26 +++++++++++++ .../cluster-api-provider-aws/pkg/apis/apis.go | 33 ++++++++++++++++ .../awsmachineproviderconfig_types.go | 2 +- .../{v1alpha1 => v1beta1}/doc.go | 6 +-- .../{v1alpha1 => v1beta1}/register.go | 22 +++++++---- .../zz_generated.deepcopy.go | 5 ++- .../pkg/apis/apis.go | 39 +++++++++++++++++++ 11 files changed, 169 insertions(+), 22 deletions(-) create mode 100644 vendor/github.com/openshift/cluster-api-provider-libvirt/pkg/apis/addtoscheme_libvirtproviderconfig_v1alpha1.go create mode 100644 vendor/github.com/openshift/cluster-api-provider-libvirt/pkg/apis/apis.go create mode 100644 vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/addtoscheme_openshiftawsprovider_v1beta1.go create mode 100644 vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/apis.go rename vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/{v1alpha1 => v1beta1}/awsmachineproviderconfig_types.go (99%) rename vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/{v1alpha1 => v1beta1}/doc.go (82%) rename vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/{v1alpha1 => v1beta1}/register.go (83%) rename vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/{v1alpha1 => v1beta1}/zz_generated.deepcopy.go (99%) create mode 100644 vendor/sigs.k8s.io/cluster-api-provider-openstack/pkg/apis/apis.go diff --git a/Gopkg.lock b/Gopkg.lock index bdbdb991ff3..96cd3e974c5 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -406,9 +406,12 @@ revision = "91fca585a85b163ddfd119fd09c128c9feadddca" [[projects]] - digest = "1:46e54b01e18842945bd92e687a237d891fbc5ee3224f460eb47b55454837862f" + digest = "1:64f129e3a0f9d8419e57ab6b65cceedc136d6dc5bcd9398545890bd4217bf6f2" name = "github.com/openshift/cluster-api-provider-libvirt" - packages = ["pkg/apis/libvirtproviderconfig/v1alpha1"] + packages = [ + "pkg/apis", + "pkg/apis/libvirtproviderconfig/v1alpha1", + ] pruneopts = "NUT" revision = "c23986b36a2521cd69ac22d7adb74a22bca9f7aa" @@ -847,18 +850,24 @@ revision = "ef6f8fc12d32fc1646f231f6e39dbef59ad2e4dd" [[projects]] - digest = "1:b03dcb1c1d57b36333b0fa402ea776f65ba3b25afce00049fe6497f047aa56f6" + digest = "1:3981a97e1e569cbbaaab702d2b44adfac402e923a2bb0984ef5fad93bcbf8c79" name = "sigs.k8s.io/cluster-api-provider-aws" - packages = ["pkg/apis/awsproviderconfig/v1alpha1"] + packages = [ + "pkg/apis", + "pkg/apis/awsproviderconfig/v1beta1", + ] pruneopts = "NUT" - revision = "9a983a5c6c12b27169c57e4c8948cb554e4d6b6c" + revision = "15fe4b4ea5636f8516c238490fc6a85d44161181" source = "https://github.com/openshift/cluster-api-provider-aws.git" [[projects]] branch = "master" - digest = "1:fcc276bfa3e1e3f8bda1249073912cebf9373996d24a9ffe988ad284c1cf65e3" + digest = "1:53e688169eb9b22a6a6d1d69f8987e85331bb185e3f3691ef4182e18f6bdd3a0" name = "sigs.k8s.io/cluster-api-provider-openstack" - packages = ["pkg/apis/openstackproviderconfig/v1alpha1"] + packages = [ + "pkg/apis", + "pkg/apis/openstackproviderconfig/v1alpha1", + ] pruneopts = "NUT" revision = "581696acc2e79f9cc1755a9cb1d8b6d512298883" source = "https://github.com/openshift/cluster-api-provider-openstack.git" @@ -925,6 +934,7 @@ "github.com/openshift/api/config/v1", "github.com/openshift/client-go/config/clientset/versioned", "github.com/openshift/client-go/route/clientset/versioned", + "github.com/openshift/cluster-api-provider-libvirt/pkg/apis", "github.com/openshift/cluster-api-provider-libvirt/pkg/apis/libvirtproviderconfig/v1alpha1", "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1", "github.com/openshift/library-go/pkg/config/clusteroperator/v1helpers", @@ -948,6 +958,7 @@ "k8s.io/apimachinery/pkg/apis/meta/v1", "k8s.io/apimachinery/pkg/fields", "k8s.io/apimachinery/pkg/runtime", + "k8s.io/apimachinery/pkg/runtime/serializer", "k8s.io/apimachinery/pkg/util/errors", "k8s.io/apimachinery/pkg/util/sets", "k8s.io/apimachinery/pkg/util/validation", @@ -961,7 +972,9 @@ "k8s.io/client-go/tools/clientcmd/api/v1", "k8s.io/client-go/tools/watch", "k8s.io/utils/pointer", - "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1", + "sigs.k8s.io/cluster-api-provider-aws/pkg/apis", + "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1", + "sigs.k8s.io/cluster-api-provider-openstack/pkg/apis", "sigs.k8s.io/cluster-api-provider-openstack/pkg/apis/openstackproviderconfig/v1alpha1", "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1", ] diff --git a/Gopkg.toml b/Gopkg.toml index a1e38a906d1..ec8c9133726 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -59,7 +59,7 @@ ignored = [ [[constraint]] name = "sigs.k8s.io/cluster-api-provider-aws" source = "https://github.com/openshift/cluster-api-provider-aws.git" - revision = "9a983a5c6c12b27169c57e4c8948cb554e4d6b6c" + revision = "15fe4b4ea5636f8516c238490fc6a85d44161181" [[constraint]] name = "github.com/openshift/cluster-api-provider-libvirt" diff --git a/vendor/github.com/openshift/cluster-api-provider-libvirt/pkg/apis/addtoscheme_libvirtproviderconfig_v1alpha1.go b/vendor/github.com/openshift/cluster-api-provider-libvirt/pkg/apis/addtoscheme_libvirtproviderconfig_v1alpha1.go new file mode 100644 index 00000000000..d6e363c0c8a --- /dev/null +++ b/vendor/github.com/openshift/cluster-api-provider-libvirt/pkg/apis/addtoscheme_libvirtproviderconfig_v1alpha1.go @@ -0,0 +1,10 @@ +package apis + +import ( + "github.com/openshift/cluster-api-provider-libvirt/pkg/apis/libvirtproviderconfig/v1alpha1" +) + +func init() { + // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back + AddToSchemes = append(AddToSchemes, v1alpha1.SchemeBuilder.AddToScheme) +} diff --git a/vendor/github.com/openshift/cluster-api-provider-libvirt/pkg/apis/apis.go b/vendor/github.com/openshift/cluster-api-provider-libvirt/pkg/apis/apis.go new file mode 100644 index 00000000000..d2d5b47ccc9 --- /dev/null +++ b/vendor/github.com/openshift/cluster-api-provider-libvirt/pkg/apis/apis.go @@ -0,0 +1,17 @@ +// Generate deepcopy for apis +//go:generate go run ../../vendor/k8s.io/code-generator/cmd/deepcopy-gen/main.go -O zz_generated.deepcopy -i ./... -h ../../hack/boilerplate.go.txt + +// Package apis contains Kubernetes API groups. +package apis + +import ( + "k8s.io/apimachinery/pkg/runtime" +) + +// AddToSchemes may be used to add all resources defined in the project to a Scheme +var AddToSchemes runtime.SchemeBuilder + +// AddToScheme adds all Resources to the Scheme +func AddToScheme(s *runtime.Scheme) error { + return AddToSchemes.AddToScheme(s) +} diff --git a/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/addtoscheme_openshiftawsprovider_v1beta1.go b/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/addtoscheme_openshiftawsprovider_v1beta1.go new file mode 100644 index 00000000000..cf53260c4e8 --- /dev/null +++ b/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/addtoscheme_openshiftawsprovider_v1beta1.go @@ -0,0 +1,26 @@ +/* +Copyright 2018 The Kubernetes Authors. + +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. +*/ + +package apis + +import ( + "sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1" +) + +func init() { + // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back + AddToSchemes = append(AddToSchemes, v1beta1.SchemeBuilder.AddToScheme) +} diff --git a/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/apis.go b/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/apis.go new file mode 100644 index 00000000000..e951fcc6f1c --- /dev/null +++ b/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/apis.go @@ -0,0 +1,33 @@ +/* +Copyright 2018 The Kubernetes Authors. + +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. +*/ + +// Generate deepcopy for apis +//go:generate go run ../../vendor/k8s.io/code-generator/cmd/deepcopy-gen/main.go -O zz_generated.deepcopy -i ./... -h ../../hack/boilerplate/boilerplate.go.txt + +// Package apis contains Kubernetes API groups. +package apis + +import ( + "k8s.io/apimachinery/pkg/runtime" +) + +// AddToSchemes may be used to add all resources defined in the project to a Scheme +var AddToSchemes runtime.SchemeBuilder + +// AddToScheme adds all Resources to the Scheme +func AddToScheme(s *runtime.Scheme) error { + return AddToSchemes.AddToScheme(s) +} diff --git a/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1/awsmachineproviderconfig_types.go b/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1/awsmachineproviderconfig_types.go similarity index 99% rename from vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1/awsmachineproviderconfig_types.go rename to vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1/awsmachineproviderconfig_types.go index a826bb26a44..8e8b551ca24 100644 --- a/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1/awsmachineproviderconfig_types.go +++ b/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1/awsmachineproviderconfig_types.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package v1alpha1 +package v1beta1 import ( corev1 "k8s.io/api/core/v1" diff --git a/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1/doc.go b/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1/doc.go similarity index 82% rename from vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1/doc.go rename to vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1/doc.go index c391550798a..b23498c7386 100644 --- a/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1/doc.go +++ b/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1/doc.go @@ -14,10 +14,10 @@ See the License for the specific language governing permissions and limitations under the License. */ -// Package v1alpha1 contains API Schema definitions for the awsproviderconfig v1alpha1 API group +// Package v1beta1 contains API Schema definitions for the awsproviderconfig v1beta1 API group // +k8s:openapi-gen=true // +k8s:deepcopy-gen=package,register // +k8s:conversion-gen=sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig // +k8s:defaulter-gen=TypeMeta -// +groupName=awsproviderconfig.k8s.io -package v1alpha1 +// +groupName=awsproviderconfig.openshift.io +package v1beta1 diff --git a/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1/register.go b/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1/register.go similarity index 83% rename from vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1/register.go rename to vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1/register.go index 1217f5baa8b..97854315417 100644 --- a/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1/register.go +++ b/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1/register.go @@ -16,18 +16,20 @@ limitations under the License. // NOTE: Boilerplate only. Ignore this file. -// Package v1alpha1 contains API Schema definitions for the awsproviderconfig v1alpha1 API group +// Package v1beta1 contains API Schema definitions for the awsproviderconfig v1beta1 API group // +k8s:openapi-gen=true // +k8s:deepcopy-gen=package,register // +k8s:conversion-gen=sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig // +k8s:defaulter-gen=TypeMeta // +groupName=awsproviderconfig.k8s.io -package v1alpha1 +package v1beta1 import ( "bytes" "fmt" + "github.com/ghodss/yaml" + machinev1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime/schema" @@ -37,7 +39,7 @@ import ( var ( // SchemeGroupVersion is group version used to register these objects - SchemeGroupVersion = schema.GroupVersion{Group: "awsproviderconfig.k8s.io", Version: "v1alpha1"} + SchemeGroupVersion = schema.GroupVersion{Group: "awsproviderconfig.openshift.io", Version: "v1beta1"} // SchemeBuilder is used to add go types to the GroupVersionKind scheme SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion} @@ -76,8 +78,11 @@ func NewCodec() (*AWSProviderConfigCodec, error) { // DecodeProviderSpec deserialises an object from the provider config func (codec *AWSProviderConfigCodec) DecodeProviderSpec(providerSpec *machinev1.ProviderSpec, out runtime.Object) error { if providerSpec.Value != nil { - _, _, err := codec.decoder.Decode(providerSpec.Value.Raw, nil, out) - if err != nil { + // TODO(vikasc): revert back to using `Decode` once installer and mao have started using + // awsprovider apis pivoted under openshift.io api group + // _, _, err := codec.decoder.Decode(providerSpec.Value.Raw, nil, out) + // if err != nil { + if err := yaml.Unmarshal(providerSpec.Value.Raw, out); err != nil { return fmt.Errorf("decoding failure: %v", err) } } @@ -107,8 +112,11 @@ func (codec *AWSProviderConfigCodec) EncodeProviderStatus(in runtime.Object) (*r // DecodeProviderStatus deserialises the provider status func (codec *AWSProviderConfigCodec) DecodeProviderStatus(providerStatus *runtime.RawExtension, out runtime.Object) error { if providerStatus != nil { - _, _, err := codec.decoder.Decode(providerStatus.Raw, nil, out) - if err != nil { + // TODO(vikasc): revert back to using `Decode` once installer and mao have started using + // awsprovider apis pivoted under openshift.io api group + //_, _, err := codec.decoder.Decode(providerStatus.Raw, nil, out) + if err := yaml.Unmarshal(providerStatus.Raw, out); err != nil { + return fmt.Errorf("decoding failure: %v", err) } } diff --git a/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1/zz_generated.deepcopy.go b/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1/zz_generated.deepcopy.go similarity index 99% rename from vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1/zz_generated.deepcopy.go rename to vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1/zz_generated.deepcopy.go index 5af190171bc..eae74a6ea98 100644 --- a/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1alpha1/zz_generated.deepcopy.go +++ b/vendor/sigs.k8s.io/cluster-api-provider-aws/pkg/apis/awsproviderconfig/v1beta1/zz_generated.deepcopy.go @@ -1,7 +1,7 @@ // +build !ignore_autogenerated /* -Copyright 2018 The Kubernetes Authors. +Copyright 2019 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -15,9 +15,10 @@ 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. */ + // Code generated by main. DO NOT EDIT. -package v1alpha1 +package v1beta1 import ( v1 "k8s.io/api/core/v1" diff --git a/vendor/sigs.k8s.io/cluster-api-provider-openstack/pkg/apis/apis.go b/vendor/sigs.k8s.io/cluster-api-provider-openstack/pkg/apis/apis.go new file mode 100644 index 00000000000..99c9b2b6a73 --- /dev/null +++ b/vendor/sigs.k8s.io/cluster-api-provider-openstack/pkg/apis/apis.go @@ -0,0 +1,39 @@ +/* +Copyright 2018 The Kubernetes Authors. + +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. +*/ + +// Generate deepcopy for apis +//go:generate go run ../../vendor/k8s.io/code-generator/cmd/deepcopy-gen/main.go -O zz_generated.deepcopy -i ./... -h ../../hack/boilerplate.go.txt + +// Package apis contains Kubernetes API groups. +package apis + +import ( + "k8s.io/apimachinery/pkg/runtime" + "sigs.k8s.io/cluster-api-provider-openstack/pkg/apis/openstackproviderconfig/v1alpha1" +) + +// AddToSchemes may be used to add all resources defined in the project to a Scheme +var AddToSchemes runtime.SchemeBuilder + +func init() { + // Register the types with the Scheme so the components can map objects to GroupVersionKinds and back + AddToSchemes = append(AddToSchemes, v1alpha1.SchemeBuilder.AddToScheme) +} + +// AddToScheme adds all Resources to the Scheme +func AddToScheme(s *runtime.Scheme) error { + return AddToSchemes.AddToScheme(s) +}