Skip to content

Commit

Permalink
Merge pull request #471 from bison/vsphere-labels
Browse files Browse the repository at this point in the history
vsphere: Reconcile region and zone labels on Machine
  • Loading branch information
openshift-merge-robot committed Jan 27, 2020
2 parents cea2bcc + 797fa4d commit 33a640c
Show file tree
Hide file tree
Showing 34 changed files with 3,600 additions and 51 deletions.
6 changes: 6 additions & 0 deletions cmd/vsphere/main.go
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"

configv1 "github.com/openshift/api/config/v1"
"github.com/openshift/machine-api-operator/pkg/apis/machine/v1beta1"
vsphereapis "github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider"
capimachine "github.com/openshift/machine-api-operator/pkg/controller/machine"
Expand Down Expand Up @@ -50,9 +51,14 @@ func main() {
// Initialize machine actuator.
machineActuator := machine.NewActuator(machine.ActuatorParams{
Client: mgr.GetClient(),
APIReader: mgr.GetAPIReader(),
EventRecorder: mgr.GetEventRecorderFor("vspherecontroller"),
})

if err := configv1.AddToScheme(mgr.GetScheme()); err != nil {
klog.Fatal(err)
}

if err := vsphereapis.AddToScheme(mgr.GetScheme()); err != nil {
klog.Fatal(err)
}
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Expand Up @@ -14,7 +14,7 @@ require (
github.com/imdario/mergo v0.3.8 // indirect
github.com/onsi/ginkgo v1.10.1 // indirect
github.com/onsi/gomega v1.7.0 // indirect
github.com/openshift/api v3.9.1-0.20191021111209-b216bf51f261+incompatible // indirect
github.com/openshift/api v3.9.1-0.20191021111209-b216bf51f261+incompatible
github.com/openshift/client-go v0.0.0-20190617165122-8892c0adc000
github.com/openshift/cluster-version-operator v3.11.1-0.20190629164025-08cac1c02538+incompatible
github.com/operator-framework/operator-sdk v0.5.1-0.20190301204940-c2efe6f74e7b
Expand All @@ -35,6 +35,8 @@ require (
gonum.org/v1/gonum v0.0.0-20190915125329-975d99cd20a9 // indirect
google.golang.org/appengine v1.6.1 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/gcfg.v1 v1.2.3
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.2.4 // indirect
k8s.io/api v0.0.0-20190918195907-bd6ac527cfd2
k8s.io/apiextensions-apiserver v0.0.0-20190918201827-3de75813f604 // indirect
Expand Down
7 changes: 5 additions & 2 deletions go.sum
Expand Up @@ -223,8 +223,7 @@ github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo=
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.7.0 h1:XPnZz8VVBHjVsy1vzJmRwIcSwiUO+JFfrv/xGiigmME=
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/openshift/api v3.9.1-0.20190517100836-d5b34b957e91+incompatible h1:YGaag04O7ouO33cS+u3wgdrLffvxC+OlMb0N+AidrZI=
github.com/openshift/api v3.9.1-0.20190517100836-d5b34b957e91+incompatible/go.mod h1:dh9o4Fs58gpFXGSYfnVxGR9PnV53I8TW84pQaJDdGiY=
github.com/openshift/api v3.9.1-0.20191021111209-b216bf51f261+incompatible h1:utBU7gFaezvoEDmbcQLPfSG/jrimJVqIqkAXRehqv/4=
github.com/openshift/api v3.9.1-0.20191021111209-b216bf51f261+incompatible/go.mod h1:dh9o4Fs58gpFXGSYfnVxGR9PnV53I8TW84pQaJDdGiY=
github.com/openshift/client-go v0.0.0-20190923180330-3b6373338c9b h1:E++qQ7W1/EdvuMo+YGVbMPn4HihEp7YT5Rghh0VmA9A=
github.com/openshift/client-go v0.0.0-20190923180330-3b6373338c9b/go.mod h1:6rzn+JTr7+WYS2E1TExP4gByoABxMznR6y2SnUIkmxk=
Expand Down Expand Up @@ -434,13 +433,17 @@ gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogR
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/gcfg.v1 v1.2.3 h1:m8OOJ4ccYHnx2f4gQwpno8nAX5OGOh7RLaaz0pj3Ogs=
gopkg.in/gcfg.v1 v1.2.3/go.mod h1:yesOnuUOFQAhST5vPY4nbZsb/huCgGGXlipJsBn0b3o=
gopkg.in/inf.v0 v0.9.0/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
gopkg.in/square/go-jose.v2 v2.2.2/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME=
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down
64 changes: 31 additions & 33 deletions install/0000_30_machine-api-operator_09_rbac.yaml
Expand Up @@ -11,6 +11,22 @@ metadata:
name: machine-api-controllers
namespace: openshift-machine-api

---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: machine-api-controllers
namespace: openshift-config
rules:
- apiGroups:
- ""
resources:
- configmaps
verbs:
- get
- list
- watch

---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
Expand Down Expand Up @@ -288,6 +304,21 @@ subjects:
name: machine-api-controllers
namespace: openshift-machine-api

---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: machine-api-controllers
namespace: openshift-config
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: machine-api-controllers
subjects:
- kind: ServiceAccount
name: machine-api-controllers
namespace: openshift-machine-api

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand Down Expand Up @@ -332,21 +363,6 @@ subjects:
name: prometheus-k8s
namespace: openshift-monitoring

---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: machine-api-cloud-provider-config-reader
namespace: openshift-config
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: cloud-provider-config-reader
subjects:
- kind: ServiceAccount
name: machine-api-controllers
namespace: openshift-machine-api

---
# Roles needed by prometheus to scrape machine api Operator metrics endpoint
apiVersion: rbac.authorization.k8s.io/v1
Expand All @@ -371,21 +387,3 @@ rules:
- get
- list
- watch

---
# Roles needed by machine-api in order to read openshift-config:cloud-provider-config configmap
# https://github.com/openshift/installer/blob/a76a6b34092d99835d0e947ae9343d231f38f7e1/pkg/asset/manifests/cloudproviderconfig.go#L80
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: cloud-provider-config-reader
namespace: openshift-config
rules:
- apiGroups:
- ""
resources:
- configmap
resourceNames:
- cloud-provider-config
verbs:
- get
31 changes: 19 additions & 12 deletions pkg/controller/vsphere/actuator.go
Expand Up @@ -24,19 +24,22 @@ const (
// Actuator is responsible for performing machine reconciliation.
type Actuator struct {
client runtimeclient.Client
apiReader runtimeclient.Reader
eventRecorder record.EventRecorder
}

// ActuatorParams holds parameter information for Actuator.
type ActuatorParams struct {
Client runtimeclient.Client
APIReader runtimeclient.Reader
EventRecorder record.EventRecorder
}

// NewActuator returns an actuator.
func NewActuator(params ActuatorParams) *Actuator {
return &Actuator{
client: params.Client,
apiReader: params.APIReader,
eventRecorder: params.EventRecorder,
}
}
Expand All @@ -55,9 +58,10 @@ func (a *Actuator) handleMachineError(machine *machinev1.Machine, err error, eve
func (a *Actuator) Create(ctx context.Context, machine *machinev1.Machine) error {
klog.Infof("%s: actuator creating machine", machine.GetName())
scope, err := newMachineScope(machineScopeParams{
Context: ctx,
client: a.client,
machine: machine,
Context: ctx,
client: a.client,
machine: machine,
apiReader: a.apiReader,
})
if err != nil {
return a.handleMachineError(machine, err, createEventAction)
Expand All @@ -75,9 +79,10 @@ func (a *Actuator) Create(ctx context.Context, machine *machinev1.Machine) error
func (a *Actuator) Exists(ctx context.Context, machine *machinev1.Machine) (bool, error) {
klog.Infof("%s: actuator checking if machine exists", machine.GetName())
scope, err := newMachineScope(machineScopeParams{
Context: ctx,
client: a.client,
machine: machine,
Context: ctx,
client: a.client,
machine: machine,
apiReader: a.apiReader,
})
if err != nil {
return false, fmt.Errorf(scopeFailFmt, machine.GetName(), err)
Expand All @@ -88,9 +93,10 @@ func (a *Actuator) Exists(ctx context.Context, machine *machinev1.Machine) (bool
func (a *Actuator) Update(ctx context.Context, machine *machinev1.Machine) error {
klog.Infof("%s: actuator updating machine", machine.GetName())
scope, err := newMachineScope(machineScopeParams{
Context: ctx,
client: a.client,
machine: machine,
Context: ctx,
client: a.client,
machine: machine,
apiReader: a.apiReader,
})
if err != nil {
fmtErr := fmt.Sprintf(scopeFailFmt, machine.GetName(), err)
Expand All @@ -110,9 +116,10 @@ func (a *Actuator) Update(ctx context.Context, machine *machinev1.Machine) error
func (a *Actuator) Delete(ctx context.Context, machine *machinev1.Machine) error {
klog.Infof("%s: actuator deleting machine", machine.GetName())
scope, err := newMachineScope(machineScopeParams{
Context: ctx,
client: a.client,
machine: machine,
Context: ctx,
client: a.client,
machine: machine,
apiReader: a.apiReader,
})
if err != nil {
fmtErr := fmt.Sprintf(scopeFailFmt, machine.GetName(), err)
Expand Down
17 changes: 15 additions & 2 deletions pkg/controller/vsphere/machine_scope.go
Expand Up @@ -24,8 +24,10 @@ const (
// machineScopeParams defines the input parameters used to create a new MachineScope.
type machineScopeParams struct {
context.Context
client runtimeclient.Client
machine *machinev1.Machine
client runtimeclient.Client
apiReader runtimeclient.Reader
machine *machinev1.Machine
vSphereConfig *vSphereConfig
}

// machineScope defines a scope defined around a machine and its cluster.
Expand All @@ -35,6 +37,10 @@ type machineScope struct {
session *session.Session
// api server controller runtime client
client runtimeclient.Client
// client reader that bypasses the manager's cache
apiReader runtimeclient.Reader
// vSphere cloud-provider config
vSphereConfig *vSphereConfig
// machine resource
machine *machinev1.Machine
providerSpec *apivshpere.VSphereMachineProviderSpec
Expand All @@ -49,6 +55,11 @@ func newMachineScope(params machineScopeParams) (*machineScope, error) {
return nil, fmt.Errorf("%v: machine scope require a context", params.machine.GetName())
}

vSphereConfig, err := getVSphereConfig(params.apiReader)
if err != nil {
klog.Errorf("Failed to fetch vSphere config: %v", err)
}

providerSpec, err := apivshpere.ProviderSpecFromRawExtension(params.machine.Spec.ProviderSpec.Value)
if err != nil {
return nil, machineapierros.InvalidMachineConfiguration("failed to get machine config: %v", err)
Expand Down Expand Up @@ -76,10 +87,12 @@ func newMachineScope(params machineScopeParams) (*machineScope, error) {
return &machineScope{
Context: params.Context,
client: params.client,
apiReader: params.apiReader,
session: authSession,
machine: params.machine,
providerSpec: providerSpec,
providerStatus: providerStatus,
vSphereConfig: vSphereConfig,
machineToBePatched: runtimeclient.MergeFrom(params.machine.DeepCopy()),
}, nil
}
Expand Down

0 comments on commit 33a640c

Please sign in to comment.