Skip to content

Commit 644a678

Browse files
authored
Merge pull request #22 from coderanger/upgrade-deps
✨ Make the webhook not stomp on container restartPolicy
2 parents c63ad0a + ee13d30 commit 644a678

File tree

19 files changed

+866
-467
lines changed

19 files changed

+866
-467
lines changed

.github/workflows/main.yml

+7-7
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ jobs:
1212
name: Lint
1313
runs-on: ubuntu-latest
1414
steps:
15-
- uses: actions/setup-go@v3
15+
- uses: actions/setup-go@v5
1616
with:
17-
go-version: 1.17
17+
go-version: "1.20"
1818
- uses: actions/checkout@v3
1919
- name: golangci-lint
2020
uses: golangci/golangci-lint-action@v3
@@ -30,17 +30,17 @@ jobs:
3030

3131
steps:
3232
- uses: actions/checkout@v2
33-
- uses: actions/setup-go@v3
33+
- uses: actions/setup-go@v5
3434
with:
35-
go-version: 1.17
35+
go-version: "1.20"
3636
- name: Install Kubebuilder
3737
id: install-kubebuilder
3838
run: |
3939
os=$(go env GOOS)
4040
arch=$(go env GOARCH)
41-
version=2.3.1
42-
curl -L https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${version}/kubebuilder_${version}_${os}_${arch}.tar.gz | tar -xz -C /tmp/
43-
sudo mv /tmp/kubebuilder_2.3.1_${os}_${arch} /usr/local/kubebuilder
41+
version=1.29.3
42+
curl -L https://storage.googleapis.com/kubebuilder-tools/kubebuilder-tools-${version}-${os}-${arch}.tar.gz | tar -xz -C /tmp/
43+
sudo mv /tmp/kubebuilder /usr/local/kubebuilder
4444
- run: make test
4545

4646
build:

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.17 as builder
2+
FROM golang:1.20 AS builder
33

44
WORKDIR /workspace
55
# Copy the Go Modules manifests

Makefile

+2-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Image URL to use all building/pushing image targets
33
IMG ?= controller:latest
44
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
5-
CRD_OPTIONS ?= "crd:trivialVersions=true"
5+
CRD_OPTIONS ?= "crd"
66

77
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
88
ifeq (,$(shell go env GOBIN))
@@ -69,11 +69,7 @@ controller-gen:
6969
ifeq (, $(shell which controller-gen))
7070
@{ \
7171
set -e ;\
72-
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
73-
cd $$CONTROLLER_GEN_TMP_DIR ;\
74-
go mod init tmp ;\
75-
go get sigs.k8s.io/controller-tools/cmd/[email protected] ;\
76-
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
72+
go install sigs.k8s.io/controller-tools/cmd/[email protected] ;\
7773
}
7874
CONTROLLER_GEN=$(GOBIN)/controller-gen
7975
else

api/v1beta1/zz_generated.deepcopy.go

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/waiter/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"bytes"
2121
"encoding/json"
2222
"fmt"
23-
"io/ioutil"
23+
"io"
2424
"log"
2525
"net/http"
2626
"os"
@@ -63,7 +63,7 @@ func migratorReady(targetImage, migratorNamespace, migratorName, apiUrl string)
6363
return false, err
6464
}
6565
defer resp.Body.Close()
66-
body, err := ioutil.ReadAll(resp.Body)
66+
body, err := io.ReadAll(resp.Body)
6767
if err != nil {
6868
return false, err
6969
}

components/migrations.go

+26-35
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"time"
2323

2424
cu "github.com/coderanger/controller-utils"
25-
"github.com/go-logr/logr"
2625
"github.com/pkg/errors"
2726
appsv1 "k8s.io/api/apps/v1"
2827
batchv1 "k8s.io/api/batch/v1"
@@ -48,11 +47,6 @@ import (
4847

4948
type migrationsComponent struct{}
5049

51-
type migrationsComponentWatchMap struct {
52-
client client.Client
53-
log logr.Logger
54-
}
55-
5650
func Migrations() *migrationsComponent {
5751
return &migrationsComponent{}
5852
}
@@ -65,33 +59,30 @@ func (comp *migrationsComponent) Setup(ctx *cu.Context, bldr *ctrl.Builder) erro
6559
bldr.Owns(&batchv1.Job{})
6660
bldr.Watches(
6761
&source.Kind{Type: &corev1.Pod{}},
68-
&handler.EnqueueRequestsFromMapFunc{ToRequests: &migrationsComponentWatchMap{client: ctx.Client, log: ctx.Log}},
62+
handler.EnqueueRequestsFromMapFunc(func(obj client.Object) []reconcile.Request {
63+
// Obj is a Pod that just got an event, map it back to any matching Migrators.
64+
requests := []reconcile.Request{}
65+
// Find any Migrator objects that match this pod.
66+
migrators, err := utils.ListMatchingMigrators(context.Background(), ctx.Client, obj)
67+
if err != nil {
68+
ctx.Log.Error(err, "error listing matching migrators")
69+
// TODO Metric to track this for alerting.
70+
return requests
71+
}
72+
for _, migrator := range migrators {
73+
requests = append(requests, reconcile.Request{
74+
NamespacedName: types.NamespacedName{
75+
Name: migrator.Name,
76+
Namespace: migrator.Namespace,
77+
},
78+
})
79+
}
80+
return requests
81+
}),
6982
)
7083
return nil
7184
}
7285

73-
// Watch map function used above.
74-
// Obj is a Pod that just got an event, map it back to any matching Migrators.
75-
func (m *migrationsComponentWatchMap) Map(obj handler.MapObject) []reconcile.Request {
76-
requests := []reconcile.Request{}
77-
// Find any Migrator objects that match this pod.
78-
migrators, err := utils.ListMatchingMigrators(context.Background(), m.client, obj.Meta)
79-
if err != nil {
80-
m.log.Error(err, "error listing matching migrators")
81-
// TODO Metric to track this for alerting.
82-
return requests
83-
}
84-
for _, migrator := range migrators {
85-
requests = append(requests, reconcile.Request{
86-
NamespacedName: types.NamespacedName{
87-
Name: migrator.Name,
88-
Namespace: migrator.Namespace,
89-
},
90-
})
91-
}
92-
return requests
93-
}
94-
9586
func (comp *migrationsComponent) Reconcile(ctx *cu.Context) (cu.Result, error) {
9687
obj := ctx.Object.(*migrationsv1beta1.Migrator)
9788

@@ -310,9 +301,9 @@ func (comp *migrationsComponent) Reconcile(ctx *cu.Context) (cu.Result, error) {
310301
return cu.Result{}, nil
311302
}
312303

313-
func (_ *migrationsComponent) findOwners(ctx *cu.Context, obj cu.Object) ([]cu.Object, error) {
304+
func (_ *migrationsComponent) findOwners(ctx *cu.Context, obj client.Object) ([]client.Object, error) {
314305
namespace := obj.GetNamespace()
315-
owners := []cu.Object{}
306+
owners := []client.Object{}
316307
for {
317308
owners = append(owners, obj)
318309
ref := metav1.GetControllerOfNoCopy(obj)
@@ -329,15 +320,15 @@ func (_ *migrationsComponent) findOwners(ctx *cu.Context, obj cu.Object) ([]cu.O
329320
}
330321
return nil, errors.Wrapf(err, "error finding object type for owner reference %v", ref)
331322
}
332-
err = ctx.Client.Get(ctx, types.NamespacedName{Name: ref.Name, Namespace: namespace}, ownerObj)
323+
obj = ownerObj.(client.Object)
324+
err = ctx.Client.Get(ctx, types.NamespacedName{Name: ref.Name, Namespace: namespace}, obj)
333325
if err != nil {
334326
// Gracefully handle objects we don't have access to
335327
if kerrors.IsForbidden(err) {
336328
break
337329
}
338330
return nil, errors.Wrapf(err, "error finding object type for owner reference %v", ref)
339331
}
340-
obj = ownerObj.(cu.Object)
341332
}
342333
// Reverse the slice so it goes top -> bottom.
343334
for i, j := 0, len(owners)-1; i < j; i, j = i+1, j-1 {
@@ -346,7 +337,7 @@ func (_ *migrationsComponent) findOwners(ctx *cu.Context, obj cu.Object) ([]cu.O
346337
return owners, nil
347338
}
348339

349-
func (_ *migrationsComponent) findSpecFor(ctx *cu.Context, obj cu.Object) *corev1.PodSpec {
340+
func (_ *migrationsComponent) findSpecFor(ctx *cu.Context, obj client.Object) *corev1.PodSpec {
350341
switch v := obj.(type) {
351342
case *corev1.Pod:
352343
return &v.Spec
@@ -373,7 +364,7 @@ func (_ *migrationsComponent) findSpecFor(ctx *cu.Context, obj cu.Object) *corev
373364
}
374365
}
375366

376-
func (comp *migrationsComponent) findOwnerSpec(ctx *cu.Context, obj cu.Object) (*corev1.PodSpec, error) {
367+
func (comp *migrationsComponent) findOwnerSpec(ctx *cu.Context, obj client.Object) (*corev1.PodSpec, error) {
377368
owners, err := comp.findOwners(ctx, obj)
378369
if err != nil {
379370
return nil, err

0 commit comments

Comments
 (0)