Skip to content
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

Updated Vendored cluster-api and Provider Configurations #4

Merged
merged 7 commits into from
Oct 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
276 changes: 247 additions & 29 deletions Gopkg.lock

Large diffs are not rendered by default.

28 changes: 18 additions & 10 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
required = [
"k8s.io/code-generator/cmd/deepcopy-gen",
]

[prune]
go-tests = true
unused-packages = true

[[prune.project]]
name = "sigs.k8s.io/cluster-api"
unused-packages = false

[[constraint]]
revision = "7db708b5df567c79e2e46f9c37cdbf001bef1302"
name = "sigs.k8s.io/cluster-api"

[[constraint]]
name = "github.com/joho/godotenv"
version = "1.2.0"
Expand All @@ -15,13 +31,5 @@
version = "1.0.0"

[[constraint]]
branch = "release-1.9"
name = "k8s.io/apimachinery"

[prune]
go-tests = true
unused-packages = true

[[constraint]]
branch = "master"
name = "sigs.k8s.io/cluster-api"
name = "k8s.io/code-generator"
branch = "release-1.9"
12 changes: 12 additions & 0 deletions boilerplate.go.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// 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.
88 changes: 37 additions & 51 deletions cloud/azure/actuators/machine/machineactuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,39 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/pkg/sftp"
"golang.org/x/crypto/ssh"
"io/ioutil"
"log"
"os"

"github.com/pkg/sftp"
"golang.org/x/crypto/ssh"

"time"

"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/azure/auth"
"github.com/golang/glog"
"github.com/joho/godotenv"
azureconfigv1 "github.com/platform9/azure-provider/cloud/azure/providerconfig/v1alpha1"
"github.com/platform9/azure-provider/cloud/azure/actuators/machine/machinesetup"
"github.com/platform9/azure-provider/cloud/azure/actuators/machine/wrappers"
azureconfigv1 "github.com/platform9/azure-provider/cloud/azure/providerconfig/v1alpha1"
"gopkg.in/yaml.v2"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/serializer"
clustercommon "sigs.k8s.io/cluster-api/pkg/apis/cluster/common"
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
client "sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset/typed/cluster/v1alpha1"
"time"
)

// The Azure Client, also used as a machine actuator
type AzureClient struct {
v1Alpha1Client client.ClusterV1alpha1Interface
SubscriptionID string
Authorizer autorest.Authorizer
kubeadmToken string
ctx context.Context
scheme *runtime.Scheme
codecFactory *serializer.CodecFactory
machineSetupConfigs machinesetup.MachineSetup
v1Alpha1Client client.ClusterV1alpha1Interface
SubscriptionID string
Authorizer autorest.Authorizer
kubeadmToken string
ctx context.Context
scheme *runtime.Scheme
azureProviderConfigCodec *azureconfigv1.AzureProviderConfigCodec
machineSetupConfigs machinesetup.MachineSetup
}

// Parameter object used to create a machine actuator.
Expand All @@ -62,11 +63,11 @@ type MachineActuatorParams struct {
}

const (
templateFile = "deployment-template.json"
ProviderName = "azure"
SSHUser = "ClusterAPI"
templateFile = "deployment-template.json"
ProviderName = "azure"
SSHUser = "ClusterAPI"
NameAnnotationKey = "azure-name"
RGAnnotationKey = "azure-rg"
RGAnnotationKey = "azure-rg"
)

func init() {
Expand All @@ -79,7 +80,7 @@ func init() {

// Creates a new azure client to be used as a machine actuator
func NewMachineActuator(params MachineActuatorParams) (*AzureClient, error) {
scheme, codecFactory, err := azureconfigv1.NewSchemeAndCodecs()
scheme, azureProviderConfigCodec, err := azureconfigv1.NewSchemeAndCodecs()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -110,14 +111,13 @@ func NewMachineActuator(params MachineActuatorParams) (*AzureClient, error) {
kubeadmToken: params.KubeadmToken,
ctx: context.Background(),
scheme: scheme,
codecFactory: codecFactory,
azureProviderConfigCodec: azureProviderConfigCodec,
}, nil
}

// Create a machine based on the cluster and machine spec passed
func (azure *AzureClient) Create(cluster *clusterv1.Cluster, machine *clusterv1.Machine) error {
var clusterConfig azureconfigv1.AzureClusterProviderConfig
err := azure.decodeClusterProviderConfig(cluster.Spec.ProviderConfig, &clusterConfig)
clusterConfig, err := azure.azureProviderConfigCodec.ClusterProviderFromProviderConfig(cluster.Spec.ProviderConfig)
if err != nil {
return err
}
Expand Down Expand Up @@ -146,13 +146,11 @@ func (azure *AzureClient) Create(cluster *clusterv1.Cluster, machine *clusterv1.
// Currently only checks machine existence and does not update anything.
func (azure *AzureClient) Update(cluster *clusterv1.Cluster, goalMachine *clusterv1.Machine) error {
//Parse in configurations
var goalMachineConfig azureconfigv1.AzureMachineProviderConfig
err := azure.decodeMachineProviderConfig(goalMachine.Spec.ProviderConfig, &goalMachineConfig)
_, err := azure.decodeMachineProviderConfig(goalMachine.Spec.ProviderConfig)
if err != nil {
return err
}
var clusterConfig azureconfigv1.AzureClusterProviderConfig
err = azure.decodeClusterProviderConfig(cluster.Spec.ProviderConfig, &clusterConfig)
_, err = azure.azureProviderConfigCodec.ClusterProviderFromProviderConfig(cluster.Spec.ProviderConfig)
if err != nil {
return err
}
Expand All @@ -168,13 +166,11 @@ func (azure *AzureClient) Update(cluster *clusterv1.Cluster, goalMachine *cluste
// Will block until the machine has been successfully deleted, or an error is returned.
func (azure *AzureClient) Delete(cluster *clusterv1.Cluster, machine *clusterv1.Machine) error {
//Parse in configurations
var machineConfig azureconfigv1.AzureMachineProviderConfig
err := azure.decodeMachineProviderConfig(machine.Spec.ProviderConfig, &machineConfig)
_, err := azure.decodeMachineProviderConfig(machine.Spec.ProviderConfig)
if err != nil {
return err
}
var clusterConfig azureconfigv1.AzureClusterProviderConfig
err = azure.decodeClusterProviderConfig(cluster.Spec.ProviderConfig, &clusterConfig)
clusterConfig, err := azure.azureProviderConfigCodec.ClusterProviderFromProviderConfig(cluster.Spec.ProviderConfig)
if err != nil {
return err
}
Expand Down Expand Up @@ -206,13 +202,11 @@ func (azure *AzureClient) Delete(cluster *clusterv1.Cluster, machine *clusterv1.
// Get the kubeconfig of a machine based on the cluster and machine spec passed.
// Has not been fully tested as k8s is not yet bootstrapped on created machines.
func (azure *AzureClient) GetKubeConfig(cluster *clusterv1.Cluster, machine *clusterv1.Machine) (string, error) {
var clusterConfig azureconfigv1.AzureClusterProviderConfig
err := azure.decodeClusterProviderConfig(cluster.Spec.ProviderConfig, &clusterConfig)
_, err := azure.azureProviderConfigCodec.ClusterProviderFromProviderConfig(cluster.Spec.ProviderConfig)
if err != nil {
return "", err
}
var machineConfig azureconfigv1.AzureMachineProviderConfig
err = azure.decodeMachineProviderConfig(machine.Spec.ProviderConfig, &machineConfig)
machineConfig, err := azure.decodeMachineProviderConfig(machine.Spec.ProviderConfig)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -293,20 +287,13 @@ func (azure *AzureClient) Exists(cluster *clusterv1.Cluster, machine *clusterv1.
return vm != nil, nil
}

func (azure *AzureClient) decodeMachineProviderConfig(providerConfig clusterv1.ProviderConfig, out runtime.Object) error {
_, _, err := azure.codecFactory.UniversalDecoder().Decode(providerConfig.Value.Raw, nil, out)
if err != nil {
return fmt.Errorf("machine providerconfig decoding failure: %v", err)
}
return nil
}

func (azure *AzureClient) decodeClusterProviderConfig(providerConfig clusterv1.ProviderConfig, out runtime.Object) error {
_, _, err := azure.codecFactory.UniversalDecoder().Decode(providerConfig.Value.Raw, nil, out)
func (azure *AzureClient) decodeMachineProviderConfig(providerConfig clusterv1.ProviderConfig) (*azureconfigv1.AzureMachineProviderConfig, error) {
var config azureconfigv1.AzureMachineProviderConfig
err := azure.azureProviderConfigCodec.DecodeFromProviderConfig(providerConfig, &config)
if err != nil {
return fmt.Errorf("cluster providerconfig decoding failure: %v", err)
return nil, err
}
return nil
return &config, err
}

func readJSON(path string) (*map[string]interface{}, error) {
Expand All @@ -330,12 +317,11 @@ func base64EncodeCommand(command string) *string {
}

func (azure *AzureClient) convertMachineToDeploymentParams(cluster *clusterv1.Cluster, machine *clusterv1.Machine) (*map[string]interface{}, error) {
var machineConfig azureconfigv1.AzureMachineProviderConfig
err := azure.decodeMachineProviderConfig(machine.Spec.ProviderConfig, &machineConfig)
machineConfig, err := azure.decodeMachineProviderConfig(machine.Spec.ProviderConfig)
if err != nil {
return nil, err
}
startupScript, err := azure.getStartupScript(cluster, machine)
startupScript, err := azure.getStartupScript(*machineConfig)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -424,8 +410,8 @@ func parseMachineSetupConfig(path string) (*machinesetup.MachineSetup, error) {
}

// Get the startup script from the machine_set_configs, taking into account the role of the given machine
func (azure *AzureClient) getStartupScript(cluster *clusterv1.Cluster, machine *clusterv1.Machine) (string, error) {
if machine.Spec.Roles[0] == "Master" {
func (azure *AzureClient) getStartupScript(machineConfig azureconfigv1.AzureMachineProviderConfig) (string, error) {
if machineConfig.Roles[0] == azureconfigv1.Master {
const startupScript = `(
apt-get update
apt-get install -y docker.io
Expand Down Expand Up @@ -482,7 +468,7 @@ chown $(id -u ClusterAPI):$(id -g ClusterAPI) /home/ClusterAPI/.kube/config
KUBECONFIG=/etc/kubernetes/admin.conf kubectl apply -f https://raw.githubusercontent.com/cloudnativelabs/kube-router/master/daemonset/kubeadm-kuberouter.yaml
) 2>&1 | tee /var/log/startup.log`
return startupScript, nil
} else if machine.Spec.Roles[0] == "Node" {
} else if machineConfig.Roles[0] == azureconfigv1.Node {
const startupScript = `(
apt-get update
apt-get install -y docker.io
Expand Down
41 changes: 13 additions & 28 deletions cloud/azure/actuators/machine/machineactuator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ import (
"github.com/Azure/go-autorest/autorest/azure/auth"
"github.com/ghodss/yaml"
"github.com/joho/godotenv"
"github.com/platform9/azure-provider/cloud/azure/providerconfig/v1alpha1"
"github.com/platform9/azure-provider/cloud/azure/actuators/machine/machinesetup"
"github.com/platform9/azure-provider/cloud/azure/actuators/machine/wrappers"
"sigs.k8s.io/cluster-api/pkg/apis/cluster/common"
"github.com/platform9/azure-provider/cloud/azure/providerconfig/v1alpha1"
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
)

Expand Down Expand Up @@ -55,8 +54,7 @@ func TestCreate(t *testing.T) {
if err != nil {
t.Fatalf("unable to create machine actuator: %v", err)
}
var clusterConfig v1alpha1.AzureClusterProviderConfig
err = azure.decodeClusterProviderConfig(cluster.Spec.ProviderConfig, &clusterConfig)
clusterConfig, err := azure.azureProviderConfigCodec.ClusterProviderFromProviderConfig(cluster.Spec.ProviderConfig)
if err != nil {
t.Fatalf("unable to parse cluster provider config: %v", err)
}
Expand Down Expand Up @@ -116,13 +114,11 @@ func TestDelete(t *testing.T) {
if err != nil {
t.Fatalf("unable to create machine actuator: %v", err)
}
var clusterConfig v1alpha1.AzureClusterProviderConfig
err = azure.decodeClusterProviderConfig(cluster.Spec.ProviderConfig, &clusterConfig)
clusterConfig, err := azure.azureProviderConfigCodec.ClusterProviderFromProviderConfig(cluster.Spec.ProviderConfig)
if err != nil {
t.Fatalf("unable to parse cluster provider config: %v", err)
}
var machineConfig v1alpha1.AzureMachineProviderConfig
err = azure.decodeMachineProviderConfig(machines[0].Spec.ProviderConfig, &machineConfig)
_, err = azure.decodeMachineProviderConfig(machines[0].Spec.ProviderConfig)
if err != nil {
t.Fatalf("unable to parse machine provider config: %v", err)
}
Expand Down Expand Up @@ -193,14 +189,12 @@ func TestParseProviderConfigs(t *testing.T) {
if err != nil {
t.Fatalf("unable to create machine actuator: %v", err)
}
var clusterConfig v1alpha1.AzureClusterProviderConfig
err = azure.decodeClusterProviderConfig(cluster.Spec.ProviderConfig, &clusterConfig)
_, err = azure.azureProviderConfigCodec.ClusterProviderFromProviderConfig(cluster.Spec.ProviderConfig)
if err != nil {
t.Fatalf("unable to parse cluster provider config: %v", err)
}
for _, machine := range machines {
var machineConfig v1alpha1.AzureMachineProviderConfig
err = azure.decodeMachineProviderConfig(machine.Spec.ProviderConfig, &machineConfig)
_, err := azure.decodeMachineProviderConfig(machine.Spec.ProviderConfig)
if err != nil {
t.Fatalf("unable to parse machine provider config: %v", err)
}
Expand Down Expand Up @@ -278,26 +272,17 @@ KUBECONFIG=/etc/kubernetes/admin.conf kubectl apply -f https://raw.githubusercon
machineSetupConfigs: machinesetup.MachineSetup{
Items: []machinesetup.Params{
{
MachineParams: machinesetup.MachineParams{
Roles: []v1alpha1.MachineRole{
"Master",
},
},
MachineParams: machinesetup.MachineParams{},
Metadata: machinesetup.Metadata{
StartupScript: expectedStartupScript,
},
},
},
},
}
machine := &clusterv1.Machine{
Spec: clusterv1.MachineSpec{
Roles: []common.MachineRole{
"Master",
},
},
}
actualStartupScript, err := azure.getStartupScript(nil, machine)
machineConfig := mockAzureMachineProviderConfig(t)
machineConfig.Roles = []v1alpha1.MachineRole{"Master"}
actualStartupScript, err := azure.getStartupScript(*machineConfig)
if err != nil {
t.Fatalf("unable to get startup script: %v", err)
}
Expand Down Expand Up @@ -387,7 +372,7 @@ func mockAzureClusterProviderConfig(t *testing.T, rg string) *v1alpha1.AzureClus

func mockAzureClient(t *testing.T) (*AzureClient, error) {
t.Helper()
scheme, codecFactory, err := v1alpha1.NewSchemeAndCodecs()
scheme, codec, err := v1alpha1.NewSchemeAndCodecs()
if err != nil {
return nil, err
}
Expand All @@ -410,7 +395,7 @@ func mockAzureClient(t *testing.T) (*AzureClient, error) {
return &AzureClient{
SubscriptionID: wrappers.MockSubscriptionID,
scheme: scheme,
codecFactory: codecFactory,
Authorizer: authorizer,
azureProviderConfigCodec: codec,
Authorizer: authorizer,
}, nil
}
2 changes: 0 additions & 2 deletions cloud/azure/actuators/machine/machinesetup/types.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package machinesetup

import (
azureconfigv1 "github.com/platform9/azure-provider/cloud/azure/providerconfig/v1alpha1"
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
)

Expand All @@ -18,7 +17,6 @@ type Params struct {

type MachineParams struct {
OS string `json:"os"`
Roles []azureconfigv1.MachineRole `json:"roles"`
Versions clusterv1.MachineVersionInfo `json:"versions"`
}

Expand Down
5 changes: 2 additions & 3 deletions cloud/azure/actuators/machine/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package machine

import (
"fmt"
azureconfigv1 "github.com/platform9/azure-provider/cloud/azure/providerconfig/v1alpha1"

"github.com/platform9/azure-provider/cloud/azure/actuators/machine/wrappers"
clusterv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
)

// Return the ip address of an existing machine based on the cluster and machine spec passed.
func (azure *AzureClient) GetIP(cluster *clusterv1.Cluster, machine *clusterv1.Machine) (string, error) {
var clusterConfig azureconfigv1.AzureClusterProviderConfig
err := azure.decodeClusterProviderConfig(cluster.Spec.ProviderConfig, &clusterConfig)
clusterConfig, err := azure.azureProviderConfigCodec.ClusterProviderFromProviderConfig(cluster.Spec.ProviderConfig)
if err != nil {
return "", err
}
Expand Down
Loading