Skip to content

Commit

Permalink
UPSTREAM: <carry>: openshift: build fixes due to new cluster-api vend…
Browse files Browse the repository at this point in the history
…or and addition of managed identity
  • Loading branch information
awesomenix authored and openshift-merge-robot committed May 2, 2019
1 parent fa79861 commit 7e23f23
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 51 deletions.
1 change: 0 additions & 1 deletion pkg/cloud/azure/actuators/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ go_library(
"//vendor/github.com/openshift/cluster-api/pkg/client/clientset_generated/clientset/typed/machine/v1beta1:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
Expand Down
11 changes: 6 additions & 5 deletions pkg/cloud/azure/actuators/machine/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import (
"context"
"time"

clusterv1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
clusterv1 "github.com/openshift/cluster-api/pkg/apis/cluster/v1alpha1"
machinev1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
client "github.com/openshift/cluster-api/pkg/client/clientset_generated/clientset/typed/machine/v1beta1"
controllerError "github.com/openshift/cluster-api/pkg/controller/error"
"github.com/pkg/errors"
Expand Down Expand Up @@ -59,7 +60,7 @@ func NewActuator(params ActuatorParams) *Actuator {
}

// Create creates a machine and is invoked by the machine controller.
func (a *Actuator) Create(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine) error {
func (a *Actuator) Create(ctx context.Context, cluster *clusterv1.Cluster, machine *machinev1.Machine) error {
klog.Infof("Creating machine %v", machine.Name)

scope, err := actuators.NewMachineScope(actuators.MachineScopeParams{
Expand All @@ -85,7 +86,7 @@ func (a *Actuator) Create(ctx context.Context, cluster *clusterv1.Cluster, machi
}

// Delete deletes a machine and is invoked by the Machine Controller.
func (a *Actuator) Delete(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine) error {
func (a *Actuator) Delete(ctx context.Context, cluster *clusterv1.Cluster, machine *machinev1.Machine) error {
klog.Infof("Deleting machine %v", machine.Name)

scope, err := actuators.NewMachineScope(actuators.MachineScopeParams{
Expand Down Expand Up @@ -114,7 +115,7 @@ func (a *Actuator) Delete(ctx context.Context, cluster *clusterv1.Cluster, machi
// Update updates a machine and is invoked by the Machine Controller.
// If the Update attempts to mutate any immutable state, the method will error
// and no updates will be performed.
func (a *Actuator) Update(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine) error {
func (a *Actuator) Update(ctx context.Context, cluster *clusterv1.Cluster, machine *machinev1.Machine) error {
klog.Infof("Updating machine %v", machine.Name)

scope, err := actuators.NewMachineScope(actuators.MachineScopeParams{
Expand All @@ -141,7 +142,7 @@ func (a *Actuator) Update(ctx context.Context, cluster *clusterv1.Cluster, machi
}

// Exists test for the existence of a machine and is invoked by the Machine Controller
func (a *Actuator) Exists(ctx context.Context, cluster *clusterv1.Cluster, machine *clusterv1.Machine) (bool, error) {
func (a *Actuator) Exists(ctx context.Context, cluster *clusterv1.Cluster, machine *machinev1.Machine) (bool, error) {
klog.Infof("Checking if machine %v exists", machine.Name)

scope, err := actuators.NewMachineScope(actuators.MachineScopeParams{
Expand Down
6 changes: 2 additions & 4 deletions pkg/cloud/azure/actuators/machine/actuator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ func newMachine(t *testing.T, machineConfig providerv1.AzureMachineProviderSpec,
},
Spec: machinev1.MachineSpec{
ProviderSpec: *providerSpec,
Versions: machinev1.MachineVersionInfo{
Kubelet: "1.9.4",
ControlPlane: "1.9.4",
},
},
}
}
Expand Down Expand Up @@ -370,6 +366,8 @@ func TestNodeJoinSecondControlPlane(t *testing.T) {
t.Errorf("failed to create machine: %+v", err)
}

t.Logf("%+v", fakeScope.Machine)

if isNodeJoin, err := fakeReconciler.isNodeJoin(); err != nil {
t.Errorf("isNodeJoin failed to create machine: %+v", err)
} else if !isNodeJoin {
Expand Down
21 changes: 12 additions & 9 deletions pkg/cloud/azure/actuators/machine/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func (s *Reconciler) isNodeJoin() (bool, error) {
return true, nil
case v1alpha1.ControlPlane:
for _, cm := range clusterMachines.Items {
if cm.Spec.Versions.ControlPlane == "" {
if cm.ObjectMeta.Labels[v1alpha1.MachineRoleLabel] == v1alpha1.ControlPlane {
continue
}
vmInterface, err := s.virtualMachinesSvc.Get(context.Background(), &virtualmachines.Spec{Name: cm.Name})
Expand Down Expand Up @@ -271,7 +271,7 @@ func (s *Reconciler) isNodeJoin() (bool, error) {
return true, nil
}

return false, nil
return len(clusterMachines.Items) > 0, nil
default:
return false, errors.Errorf("Unknown value %s for label `set` on machine %s, skipping machine creation", set, s.scope.Name())
}
Expand Down Expand Up @@ -475,14 +475,17 @@ func (s *Reconciler) createVirtualMachine(ctx context.Context, nicName string) e
return errors.Wrap(zoneErr, "failed to get availability zone")
}

managedIdentity := azure.GenerateManagedIdentityName(s.scope.SubscriptionID, s.scope.ClusterConfig.ResourceGroup, s.scope.Cluster.Name)

vmSpec = &virtualmachines.Spec{
Name: s.scope.Machine.Name,
NICName: nicName,
SSHKeyData: string(decoded),
Size: s.scope.MachineConfig.VMSize,
OSDisk: s.scope.MachineConfig.OSDisk,
Image: s.scope.MachineConfig.Image,
Zone: vmZone,
Name: s.scope.Machine.Name,
NICName: nicName,
SSHKeyData: string(decoded),
Size: s.scope.MachineConfig.VMSize,
OSDisk: s.scope.MachineConfig.OSDisk,
Image: s.scope.MachineConfig.Image,
Zone: vmZone,
ManagedIdentity: managedIdentity,
}

userData, userDataErr := s.getCustomUserData()
Expand Down
21 changes: 0 additions & 21 deletions pkg/cloud/azure/actuators/machine_scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
machineclient "github.com/openshift/cluster-api/pkg/client/clientset_generated/clientset/typed/machine/v1beta1"
"github.com/pkg/errors"
apicorev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog"
Expand Down Expand Up @@ -176,26 +175,6 @@ func MachineConfigFromProviderSpec(clusterClient machineclient.MachineClassesGet
return unmarshalProviderSpec(providerConfig.Value)
}

if providerConfig.ValueFrom != nil && providerConfig.ValueFrom.MachineClass != nil {
ref := providerConfig.ValueFrom.MachineClass
klog.V(4).Info("Decoding ProviderConfig from MachineClass")
klog.V(6).Infof("ref: %v", ref)
if ref.Provider != "" && ref.Provider != "azure" {
return nil, errors.Errorf("Unsupported provider: %q", ref.Provider)
}

if len(ref.Namespace) > 0 && len(ref.Name) > 0 {
klog.V(4).Infof("Getting MachineClass: %s/%s", ref.Namespace, ref.Name)
mc, err := clusterClient.MachineClasses(ref.Namespace).Get(ref.Name, metav1.GetOptions{})
klog.V(6).Infof("Retrieved MachineClass: %+v", mc)
if err != nil {
return nil, err
}
providerConfig.Value = &mc.ProviderSpec
return unmarshalProviderSpec(&mc.ProviderSpec)
}
}

return &config, nil
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/cloud/azure/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,12 @@ func GeneratePublicIPName(clusterName, hash string) string {
func GenerateFQDN(publicIPName, location string) string {
return fmt.Sprintf("%s.%s.%s", publicIPName, location, DefaultAzureDNSZone)
}

// GenerateManagedIdentityName generates managed identity name.
func GenerateManagedIdentityName(subscriptionID, resourceGroupName, clusterName string) string {
return fmt.Sprintf(
"/subscriptions/%s/resourcegroups/%s/providers/Microsoft.ManagedIdentity/userAssignedIdentities/%s-identity",
subscriptionID,
resourceGroupName,
clusterName)
}
6 changes: 3 additions & 3 deletions pkg/cloud/azure/services/config/startupscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func GetVMStartupScript(machine *actuators.MachineScope, bootstrapToken string)
SaKey: string(machine.Scope.ClusterConfig.SAKeyPair.Key),
BootstrapToken: bootstrapToken,
LBAddress: dnsName,
KubernetesVersion: machine.Machine.Spec.Versions.ControlPlane,
KubernetesVersion: "1.13.4",
CloudProviderConfig: getAzureCloudProviderConfig(machine),
})
if err != nil {
Expand All @@ -100,7 +100,7 @@ func GetVMStartupScript(machine *actuators.MachineScope, bootstrapToken string)
PodSubnet: machine.Scope.Cluster.Spec.ClusterNetwork.Pods.CIDRBlocks[0],
ServiceSubnet: machine.Scope.Cluster.Spec.ClusterNetwork.Services.CIDRBlocks[0],
ServiceDomain: machine.Scope.Cluster.Spec.ClusterNetwork.ServiceDomain,
KubernetesVersion: machine.Machine.Spec.Versions.ControlPlane,
KubernetesVersion: "1.13.4",
CloudProviderConfig: getAzureCloudProviderConfig(machine),
})

Expand All @@ -116,7 +116,7 @@ func GetVMStartupScript(machine *actuators.MachineScope, bootstrapToken string)
CACertHash: caCertHash,
BootstrapToken: bootstrapToken,
InternalLBAddress: azure.DefaultInternalLBIPAddress,
KubernetesVersion: machine.Machine.Spec.Versions.Kubelet,
KubernetesVersion: "1.13.4",
CloudProviderConfig: getAzureCloudProviderConfig(machine),
})

Expand Down
26 changes: 18 additions & 8 deletions pkg/cloud/azure/services/virtualmachines/virtualmachines.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ import (

// Spec input specification for Get/CreateOrUpdate/Delete calls
type Spec struct {
Name string
NICName string
SSHKeyData string
Size string
Zone string
Image v1alpha1.Image
OSDisk v1alpha1.OSDisk
CustomData string
Name string
NICName string
SSHKeyData string
Size string
Zone string
Image v1alpha1.Image
OSDisk v1alpha1.OSDisk
CustomData string
ManagedIdentity string
}

// Get provides information about a virtual network.
Expand Down Expand Up @@ -167,6 +168,15 @@ func (s *Service) CreateOrUpdate(ctx context.Context, spec azure.Spec) error {
},
}

if vmSpec.ManagedIdentity != "" {
virtualMachine.Identity = &compute.VirtualMachineIdentity{
Type: compute.ResourceIdentityTypeUserAssigned,
UserAssignedIdentities: map[string]*compute.VirtualMachineIdentityUserAssignedIdentitiesValue{
vmSpec.ManagedIdentity: &compute.VirtualMachineIdentityUserAssignedIdentitiesValue{},
},
}
}

if vmSpec.Zone != "" {
zones := []string{vmSpec.Zone}
virtualMachine.Zones = &zones
Expand Down

0 comments on commit 7e23f23

Please sign in to comment.