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

Add events to MachineDeployment operations #1014

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
1 change: 1 addition & 0 deletions cmd/clusterctl/clusterdeployer/bootstrap/kind/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go_library(
importpath = "sigs.k8s.io/cluster-api/cmd/clusterctl/clusterdeployer/bootstrap/kind",
visibility = ["//visibility:public"],
deps = [
"//pkg/util:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go_library(
importpath = "sigs.k8s.io/cluster-api/cmd/clusterctl/clusterdeployer/bootstrap/minikube",
visibility = ["//visibility:public"],
deps = [
"//pkg/util:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
"//vendor/k8s.io/klog:go_default_library",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,11 @@ func (r *ReconcileMachineDeployment) getMachineSetsForDeployment(d *v1alpha1.Mac
// Attempt to adopt machine if it meets previous conditions and it has no controller references.
if metav1.GetControllerOf(ms) == nil {
if err := r.adoptOrphan(d, ms); err != nil {
r.recorder.Eventf(d, corev1.EventTypeWarning, "FailedAdopt", "Failed to adopt MachineSet %q: %v", ms.Name, err)
klog.Warningf("Failed to adopt MachineSet %q into MachineDeployment %q: %v", ms.Name, d.Name, err)
continue
}
r.recorder.Eventf(d, corev1.EventTypeNormal, "SuccessfulAdopt", "Adopted MachineSet %q", ms.Name)
}

if !metav1.IsControlledBy(ms, d) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/record"
"sigs.k8s.io/cluster-api/pkg/apis/cluster/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
Expand Down Expand Up @@ -132,8 +133,9 @@ func TestMachineSetToDeployments(t *testing.T) {

v1alpha1.AddToScheme(scheme.Scheme)
r := &ReconcileMachineDeployment{
Client: fake.NewFakeClient(&ms1, &ms2, &ms3, machineDeplopymentList),
scheme: scheme.Scheme,
Client: fake.NewFakeClient(&ms1, &ms2, &ms3, machineDeplopymentList),
scheme: scheme.Scheme,
recorder: record.NewFakeRecorder(32),
}

for _, tc := range testsCases {
Expand Down Expand Up @@ -206,8 +208,9 @@ func TestGetMachineDeploymentsForMachineSet(t *testing.T) {
}
v1alpha1.AddToScheme(scheme.Scheme)
r := &ReconcileMachineDeployment{
Client: fake.NewFakeClient(&ms1, &ms2, machineDeplopymentList),
scheme: scheme.Scheme,
Client: fake.NewFakeClient(&ms1, &ms2, machineDeplopymentList),
scheme: scheme.Scheme,
recorder: record.NewFakeRecorder(32),
}

for _, tc := range testCases {
Expand Down Expand Up @@ -327,8 +330,9 @@ func TestGetMachineSetsForDeployment(t *testing.T) {

v1alpha1.AddToScheme(scheme.Scheme)
r := &ReconcileMachineDeployment{
Client: fake.NewFakeClient(machineSetList),
scheme: scheme.Scheme,
Client: fake.NewFakeClient(machineSetList),
scheme: scheme.Scheme,
recorder: record.NewFakeRecorder(32),
}
for _, tc := range testCases {
got, err := r.getMachineSetsForDeployment(&tc.machineDeployment)
Expand Down
10 changes: 9 additions & 1 deletion pkg/controller/machinedeployment/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"strconv"

"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/equality"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -200,11 +201,13 @@ func (r *ReconcileMachineDeployment) getNewMachineSet(d *clusterv1alpha1.Machine
return nil, err
case err != nil:
klog.V(4).Infof("Failed to create new machine set %q: %v", newMS.Name, err)
r.recorder.Eventf(d, corev1.EventTypeWarning, "FailedCreate", "Failed to create MachineSet %q: %v", newMS.Name, err)
return nil, err
}

if !alreadyExists {
klog.V(4).Infof("Created new machine set %q", createdMS.Name)
r.recorder.Eventf(d, corev1.EventTypeNormal, "SuccessfulCreate", "Created MachineSet %q", newMS.Name)
}

err = r.updateMachineDeployment(d, func(innerDeployment *clusterv1alpha1.MachineDeployment) {
Expand Down Expand Up @@ -408,8 +411,11 @@ func (r *ReconcileMachineDeployment) scaleMachineSetOperation(ms *clusterv1alpha
dutil.SetReplicasAnnotations(ms, *(deployment.Spec.Replicas), *(deployment.Spec.Replicas)+dutil.MaxSurge(*deployment))

err = r.Update(context.Background(), ms)
if err == nil && sizeNeedsUpdate {
if err != nil {
r.recorder.Eventf(deployment, corev1.EventTypeWarning, "FailedScale", "Failed to scale MachineSet %q: %v", ms.Name, err)
} else if sizeNeedsUpdate {
scaled = true
r.recorder.Eventf(deployment, corev1.EventTypeNormal, "SuccessfulScale", "Scaled %d MachineSet %q to %d", scaleOperation, ms.Name, newScale)
}
}

Expand Down Expand Up @@ -454,8 +460,10 @@ func (r *ReconcileMachineDeployment) cleanupDeployment(oldMSs []*clusterv1alpha1
if err := r.Delete(context.Background(), ms); err != nil && !apierrors.IsNotFound(err) {
// Return error instead of aggregating and continuing DELETEs on the theory
// that we may be overloading the api server.
r.recorder.Eventf(deployment, corev1.EventTypeWarning, "FailedDelete", "Failed to delete MachineSet %q: %v", ms.Name, err)
return err
}
r.recorder.Eventf(deployment, corev1.EventTypeNormal, "SuccessfulDelete", "Deleted MachineSet %q", ms.Name)
}

return nil
Expand Down