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

Openshift machine api #188

Merged
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
64 changes: 39 additions & 25 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ required = [
branch = "release-1.10"

[[override]]
name = "sigs.k8s.io/cluster-api"
branch = "master"
name = "github.com/openshift/cluster-api"
revision = "91fca585a85b163ddfd119fd09c128c9feadddca"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine for now though let's use tags once we finish the mirroring


[[override]]
name = "k8s.io/code-generator"
Expand Down
4 changes: 2 additions & 2 deletions cmd/machine-healthcheck/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import (
"runtime"

"github.com/golang/glog"
mapiv1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
"github.com/openshift/machine-api-operator/pkg/apis"
"github.com/openshift/machine-api-operator/pkg/controller"
sdkVersion "github.com/operator-framework/operator-sdk/version"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
capiv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sigs.k8s.io/controller-runtime/pkg/runtime/signals"
Expand Down Expand Up @@ -43,7 +43,7 @@ func main() {
if err := apis.AddToScheme(mgr.GetScheme()); err != nil {
glog.Fatal(err)
}
if err := capiv1.AddToScheme(mgr.GetScheme()); err != nil {
if err := mapiv1.AddToScheme(mgr.GetScheme()); err != nil {
glog.Fatal(err)
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/nodelink-controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import (
"reflect"
"testing"

mapiv1alpha1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
corev1 "k8s.io/api/core/v1"
capiv1alpha1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
)

func node(taints *[]corev1.Taint) *corev1.Node {
Expand All @@ -32,9 +32,9 @@ func node(taints *[]corev1.Taint) *corev1.Node {
}
}

func machine(taints *[]corev1.Taint) *capiv1alpha1.Machine {
return &capiv1alpha1.Machine{
Spec: capiv1alpha1.MachineSpec{
func machine(taints *[]corev1.Taint) *mapiv1alpha1.Machine {
return &mapiv1alpha1.Machine{
Spec: mapiv1alpha1.MachineSpec{
Taints: *taints,
},
}
Expand Down
40 changes: 20 additions & 20 deletions cmd/nodelink-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ import (

"sigs.k8s.io/controller-runtime/pkg/client/config"

capiv1 "sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
"sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset"
capiclient "sigs.k8s.io/cluster-api/pkg/client/clientset_generated/clientset"
capiinformersfactory "sigs.k8s.io/cluster-api/pkg/client/informers_generated/externalversions"
capiinformers "sigs.k8s.io/cluster-api/pkg/client/informers_generated/externalversions/cluster/v1alpha1"
lister "sigs.k8s.io/cluster-api/pkg/client/listers_generated/cluster/v1alpha1"
mapiv1 "github.com/openshift/cluster-api/pkg/apis/machine/v1beta1"
"github.com/openshift/cluster-api/pkg/client/clientset_generated/clientset"
mapiclient "github.com/openshift/cluster-api/pkg/client/clientset_generated/clientset"
mapiinformersfactory "github.com/openshift/cluster-api/pkg/client/informers_generated/externalversions"
mapiinformers "github.com/openshift/cluster-api/pkg/client/informers_generated/externalversions/machine/v1beta1"
lister "github.com/openshift/cluster-api/pkg/client/listers_generated/machine/v1beta1"

kubeinformers "k8s.io/client-go/informers"
)
Expand All @@ -61,15 +61,15 @@ const (
controllerName = "nodelink"

// machineAnnotationKey is the annotation storing a link between a node and it's machine. Should match upstream cluster-api machine controller. (node.go)
machineAnnotationKey = "cluster.k8s.io/machine"
machineAnnotationKey = "machine.openshift.io/machine"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)

// NewController returns a new *Controller.
func NewController(
nodeInformer coreinformers.NodeInformer,
machineInformer capiinformers.MachineInformer,
machineInformer mapiinformers.MachineInformer,
kubeClient kubeclientset.Interface,
capiClient capiclient.Interface,
capiClient mapiclient.Interface,
) *Controller {

eventBroadcaster := record.NewBroadcaster()
Expand Down Expand Up @@ -104,14 +104,14 @@ func NewController(
c.syncHandler = c.syncNode
c.enqueueNode = c.enqueue

c.machineAddress = make(map[string]*capiv1.Machine)
c.machineAddress = make(map[string]*mapiv1.Machine)

return c
}

// Controller monitors nodes and links them to their machines when possible, as well as applies desired labels and taints.
type Controller struct {
capiClient capiclient.Interface
capiClient mapiclient.Interface
kubeClient kubeclientset.Interface

// To allow injection for testing.
Expand All @@ -130,7 +130,7 @@ type Controller struct {
queue workqueue.RateLimitingInterface

// machines cache map[internalIP]machine
machineAddress map[string]*capiv1.Machine
machineAddress map[string]*mapiv1.Machine
machineAddressMux sync.Mutex
}

Expand Down Expand Up @@ -169,7 +169,7 @@ func (c *Controller) deleteNode(obj interface{}) {
}

func (c *Controller) addMachine(obj interface{}) {
machine := obj.(*capiv1.Machine)
machine := obj.(*mapiv1.Machine)

c.machineAddressMux.Lock()
defer c.machineAddressMux.Unlock()
Expand All @@ -185,7 +185,7 @@ func (c *Controller) addMachine(obj interface{}) {
}

func (c *Controller) updateMachine(old, cur interface{}) {
machine := cur.(*capiv1.Machine)
machine := cur.(*mapiv1.Machine)

c.machineAddressMux.Lock()
defer c.machineAddressMux.Unlock()
Expand All @@ -201,7 +201,7 @@ func (c *Controller) updateMachine(old, cur interface{}) {
}

func (c *Controller) deleteMachine(obj interface{}) {
machine := obj.(*capiv1.Machine)
machine := obj.(*mapiv1.Machine)

c.machineAddressMux.Lock()
defer c.machineAddressMux.Unlock()
Expand Down Expand Up @@ -332,7 +332,7 @@ func (c *Controller) processNode(node *corev1.Node) error {
machineKey, ok := node.Annotations[machineAnnotationKey]
// No machine annotation, this is likely the first time we've seen the node,
// need to load all machines and search for one with matching IP.
var matchingMachine *capiv1.Machine
var matchingMachine *mapiv1.Machine
if ok {
var err error
namespace, machineName, err := cache.SplitMetaNamespaceKey(machineKey)
Expand Down Expand Up @@ -408,7 +408,7 @@ func (c *Controller) processNode(node *corev1.Node) error {
// addTaintsToNode adds taints from machine object to the node object
// Taints are to be an authoritative list on the machine spec per cluster-api comments.
// However, we believe many components can directly taint a node and there is no direct source of truth that should enforce a single writer of taints
func addTaintsToNode(node *corev1.Node, machine *capiv1.Machine) {
func addTaintsToNode(node *corev1.Node, machine *mapiv1.Machine) {
for _, mTaint := range machine.Spec.Taints {
glog.V(3).Infof("machine taint: %v", mTaint)
alreadyPresent := false
Expand Down Expand Up @@ -451,18 +451,18 @@ func main() {

// TODO(jchaloup): set the resync period reasonably
kubeSharedInformers := kubeinformers.NewSharedInformerFactory(kubeClient, 5*time.Second)
capiInformers := capiinformersfactory.NewSharedInformerFactory(client, 5*time.Second)
mapiInformers := mapiinformersfactory.NewSharedInformerFactory(client, 5*time.Second)

ctrl := NewController(
kubeSharedInformers.Core().V1().Nodes(),
capiInformers.Cluster().V1alpha1().Machines(),
mapiInformers.Machine().V1beta1().Machines(),
kubeClient,
client,
)

go ctrl.Run(1, wait.NeverStop)

capiInformers.Start(wait.NeverStop)
mapiInformers.Start(wait.NeverStop)
kubeSharedInformers.Start(wait.NeverStop)

select {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ metadata:
name: machine-api-operator-images
namespace: openshift-cluster-api
data:
images.json: '{"machineAPIOperator": "docker.io/openshift/origin-machine-api-operator:v4.0.0", "clusterAPIControllerAWS": "docker.io/openshift/origin-aws-machine-controllers:v4.0.0", "clusterAPIControllerOpenStack": "docker.io/openshift/origin-openstack-machine-controllers:v4.0.0", "clusterAPIControllerLibvirt": "docker.io/openshift/origin-libvirt-machine-controllers:v4.0.0"}'
images.json: '{"machineAPIOperator": "docker.io/openshift/origin-machine-api-operator:v4.0.0", "clusterAPIControllerAWS": "docker.io/openshift/origin-aws-machine-controllers:v4.0.0", "clusterAPIControllerOpenStack": "docker.io/openshift/origin-openstack-machine-controllers:v4.0.0", "clusterAPIControllerLibvirt": "docker.io/openshift/origin-libvirt-machine-controllers:v4.0.0", "clusterAPIControllerLibvirtDeprecated": "quay.io/coreos/cluster-api-provider-libvirt:origin-v4.0-2019-01-31-041134", "clusterAPIControllerAWSDeprecated": "quay.io/coreos/cluster-api-provider-aws:origin-v4.0-2019-01-31-041134"}'
36 changes: 32 additions & 4 deletions owned-manifests/clusterapi-manager-controllers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ spec:
key: node.alpha.kubernetes.io/unreachable
operator: Exists
containers:
- name: controller-manager
image: {{ .Controllers.Provider }}
- name: controller-manager-deprecated
image: {{ .Controllers.ProviderDeprecated }}
command:
- "./manager"
args:
Expand All @@ -49,8 +49,8 @@ spec:
limits:
cpu: 100m
memory: 30Mi
- name: machine-controller
image: {{ .Controllers.Provider }}
- name: machine-controller-deprecated
image: {{ .Controllers.ProviderDeprecated }}
env:
- name: NODE_NAME
valueFrom:
Expand All @@ -61,6 +61,20 @@ spec:
args:
- --logtostderr=true
- --v=3
- name: nodelink-controller-deprecated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for naming

image: quay.io/coreos/machine-api-operator:origin-v4.0-2019-01-31-041134
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be nice to template these in after having read them from the config like we do for the others. Even if it's temporary, it would be nice for these to come from the release image. I suppose this is not a total blocker though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is never gonna come from the payload/release image. The ones coming from the payload are the ones built from master so adding support for the new types.
The payload CI build will replace every appearance of https://github.com/openshift/machine-api-operator/blob/master/install/image-references#L8 with the corresponding image Stream built by CI.
We could template in the configMap though but it wouldn't make any difference

command:
- /nodelink-controller
args:
- --logtostderr=true
- --v=3
resources:
requests:
cpu: 100m
memory: 20Mi
limits:
cpu: 100m
memory: 30Mi
- name: nodelink-controller
image: {{ .Controllers.NodeLink }}
command:
Expand All @@ -75,6 +89,20 @@ spec:
limits:
cpu: 100m
memory: 30Mi
- name: machine-healthcheck-deprecated
image: quay.io/coreos/machine-api-operator:origin-v4.0-2019-01-31-041134
command:
- /machine-healthcheck
args:
- --logtostderr=true
- --v=3
resources:
requests:
cpu: 100m
memory: 20Mi
limits:
cpu: 100m
memory: 30Mi
- name: machine-healthcheck
image: {{ .Controllers.MachineHealthCheck }}
command:
Expand Down
Loading