Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
51 changes: 51 additions & 0 deletions 0001-Delete-annotated-machines-first-when-scaling-down.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
From f6a8010437fb132130a29369650f944df973058f Mon Sep 17 00:00:00 2001
From: Jan Chaloupka <jchaloup@redhat.com>
Date: Sat, 20 Oct 2018 12:35:41 +0200
Subject: [PATCH 1/2] Delete annotated machines first when scaling down

---
.../pkg/controller/machineset/controller.go | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/vendor/sigs.k8s.io/cluster-api/pkg/controller/machineset/controller.go b/vendor/sigs.k8s.io/cluster-api/pkg/controller/machineset/controller.go
index 2bf2e16..63a8051 100644
--- a/vendor/sigs.k8s.io/cluster-api/pkg/controller/machineset/controller.go
+++ b/vendor/sigs.k8s.io/cluster-api/pkg/controller/machineset/controller.go
@@ -46,6 +46,9 @@ var stateConfirmationTimeout = 10 * time.Second
// The polling is against a local memory cache.
var stateConfirmationInterval = 100 * time.Millisecond

+// machineDeleteAnnotationKey annotates machines to be delete among first ones
+var machineDeleteAnnotationKey = "sigs.k8s.io/cluster-api-delete-machine"
+
// Add creates a new MachineSet Controller and adds it to the Manager with default RBAC. The Manager will set fields on the Controller
// and Start it when the Manager is Started.
func Add(mgr manager.Manager) error {
@@ -327,7 +330,24 @@ func (c *ReconcileMachineSet) adoptOrphan(machineSet *clusterv1alpha1.MachineSet
func getMachinesToDelete(filteredMachines []*clusterv1alpha1.Machine, diff int) []*clusterv1alpha1.Machine {
// TODO: Define machines deletion policies.
// see: https://github.com/kubernetes/kube-deploy/issues/625
- return filteredMachines[:diff]
+
+ // First delete all machines with sigs.k8s.io/cluster-api-delete-machine annotation
+ var machinesToDelete []*clusterv1alpha1.Machine
+ var remainingMachines []*clusterv1alpha1.Machine
+ for _, machine := range filteredMachines {
+ if _, delete := machine.Annotations[machineDeleteAnnotationKey]; delete {
+ machinesToDelete = append(machinesToDelete, machine)
+ } else {
+ remainingMachines = append(remainingMachines, machine)
+ }
+ }
+
+ machinesToDeleteLen := len(machinesToDelete)
+ if machinesToDeleteLen >= diff {
+ return machinesToDelete[:diff]
+ }
+
+ return append(machinesToDelete, remainingMachines[:(diff-machinesToDeleteLen)]...)
}

func (c *ReconcileMachineSet) waitForMachineCreation(machineList []*clusterv1alpha1.Machine) error {
--
2.7.5
35 changes: 35 additions & 0 deletions 0001-use-Update-instead-of-Status.Update-as-CustomResourc.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
From 16531c16bfa5030bb5f85d75f20353eeff46ba25 Mon Sep 17 00:00:00 2001
From: Enxebre <alberto.garcial@hotmail.com>
Date: Fri, 19 Oct 2018 09:51:27 +0200
Subject: [PATCH] use Update() instead of Status.Update() as
CustomResourceSubresources might not be enable

---
vendor/sigs.k8s.io/cluster-api/pkg/controller/node/node.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/vendor/sigs.k8s.io/cluster-api/pkg/controller/node/node.go b/vendor/sigs.k8s.io/cluster-api/pkg/controller/node/node.go
index cb16730b..f1a4bff3 100644
--- a/vendor/sigs.k8s.io/cluster-api/pkg/controller/node/node.go
+++ b/vendor/sigs.k8s.io/cluster-api/pkg/controller/node/node.go
@@ -75,7 +75,7 @@ func (c *ReconcileNode) link(node *corev1.Node) error {
t := metav1.Now()
machine.Status.LastUpdated = &t
machine.Status.NodeRef = objectRef(node)
- if err = c.Client.Status().Update(context.Background(), machine); err != nil {
+ if err = c.Client.Update(context.Background(), machine); err != nil {
glog.Errorf("Error updating machine to link to node: %v\n", err)
} else {
glog.Infof("Successfully linked machine %s to node %s\n",
@@ -121,7 +121,7 @@ func (c *ReconcileNode) unlink(node *corev1.Node) error {
t := metav1.Now()
machine.Status.LastUpdated = &t
machine.Status.NodeRef = nil
- if err = c.Client.Status().Update(context.Background(), machine); err != nil {
+ if err = c.Client.Update(context.Background(), machine); err != nil {
glog.Errorf("Error updating machine %s to unlink node %s: %v\n",
machine.ObjectMeta.Name, node.ObjectMeta.Name, err)
} else {
--
2.15.2 (Apple Git-101.1)

51 changes: 51 additions & 0 deletions 0002-Sort-machines-before-syncing.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
From ab07b60b23d26cc712a65d89abecf3ad495e2929 Mon Sep 17 00:00:00 2001
From: Jan Chaloupka <jchaloup@redhat.com>
Date: Sat, 20 Oct 2018 12:37:52 +0200
Subject: [PATCH 2/2] Sort machines before syncing

---
.../cluster-api/pkg/controller/machineset/controller.go | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/vendor/sigs.k8s.io/cluster-api/pkg/controller/machineset/controller.go b/vendor/sigs.k8s.io/cluster-api/pkg/controller/machineset/controller.go
index 63a8051..ce303ca 100644
--- a/vendor/sigs.k8s.io/cluster-api/pkg/controller/machineset/controller.go
+++ b/vendor/sigs.k8s.io/cluster-api/pkg/controller/machineset/controller.go
@@ -19,6 +19,7 @@ package machineset
import (
"context"
"fmt"
+ "sort"
"strings"
"sync"
"time"
@@ -161,7 +162,8 @@ func (r *ReconcileMachineSet) Reconcile(request reconcile.Request) (reconcile.Re
}

// Filter out irrelevant machines (deleting/mismatch labels) and claim orphaned machines.
- var filteredMachines []*clusterv1alpha1.Machine
+ var machineNames []string
+ machineSetMachines := make(map[string]*clusterv1alpha1.Machine)
for idx := range allMachines.Items {
machine := &allMachines.Items[idx]
if shouldExcludeMachine(machineSet, machine) {
@@ -174,7 +176,16 @@ func (r *ReconcileMachineSet) Reconcile(request reconcile.Request) (reconcile.Re
continue
}
}
- filteredMachines = append(filteredMachines, machine)
+ machineNames = append(machineNames, machine.Name)
+ machineSetMachines[machine.Name] = machine
+ }
+
+ // sort the filteredMachines from the oldest to the youngest
+ sort.Strings(machineNames)
+
+ var filteredMachines []*clusterv1alpha1.Machine
+ for _, machineName := range machineNames {
+ filteredMachines = append(filteredMachines, machineSetMachines[machineName])
}

syncErr := r.syncReplicas(machineSet, filteredMachines)
--
2.7.5
12 changes: 8 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ WORKDIR /go/src/github.com/openshift/cluster-api-provider-libvirt
# This expects that the context passed to the docker build command is
# the cluster-api-provider-libvirt directory.
# e.g. docker build -t <tag> -f <this_Dockerfile> <path_to_cluster-api-libvirt>
COPY . .
RUN GOPATH=/go CGO_ENABLED=1 go install ./cmd/machine-controller
RUN GOPATH=/go CGO_ENABLED=0 GOOS=linux go install -a -ldflags '-extldflags "-static"' github.com/openshift/cluster-api-provider-libvirt/vendor/sigs.k8s.io/cluster-api/cmd/controller-manager
COPY pkg/ pkg/
COPY cmd/ cmd/
COPY vendor/ vendor/
COPY lib/ lib/

RUN GOPATH="/go" CGO_ENABLED=1 GOOS=linux go build -o /go/bin/machine-controller-manager github.com/openshift/cluster-api-provider-libvirt/cmd/manager
RUN GOPATH="/go" CGO_ENABLED=0 GOOS=linux go build -o /go/bin/manager -ldflags '-extldflags "-static"' github.com/openshift/cluster-api-provider-libvirt/vendor/sigs.k8s.io/cluster-api/cmd/manager

# Final container
FROM openshift/origin-base
RUN yum install -y ca-certificates libvirt-libs openssh-clients

COPY --from=builder /go/bin/machine-controller /go/bin/controller-manager /
COPY --from=builder /go/bin/manager /go/bin/machine-controller-manager /
Loading