• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

heathcliff26 / kube-upgrade / 19393334557

15 Nov 2025 05:41PM UTC coverage: 72.307% (+0.2%) from 72.155%
19393334557

Pull #192

github

web-flow
Merge bcbbff0ce into 9625339c7
Pull Request #192: upgrade-controller: Use validating webhook to ensure only a single plan exists

18 of 28 new or added lines in 3 files covered. (64.29%)

1094 of 1513 relevant lines covered (72.31%)

11.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

93.33
/pkg/upgrade-controller/controller/validatingwebhook.go
1
package controller
2

3
import (
4
        "context"
5
        "fmt"
6
        "log/slog"
7

8
        api "github.com/heathcliff26/kube-upgrade/pkg/apis/kubeupgrade/v1alpha3"
9
        "k8s.io/apimachinery/pkg/runtime"
10
        "sigs.k8s.io/controller-runtime/pkg/client"
11
        "sigs.k8s.io/controller-runtime/pkg/webhook/admission"
12
)
13

14
// +kubebuilder:webhook:path=/validate-kubeupgrade-heathcliff-eu-v1alpha3-kubeupgradeplan,mutating=false,failurePolicy=fail,groups=kubeupgrade.heathcliff.eu,resources=kubeupgradeplans,verbs=create;update,versions=v1alpha3,name=kubeupgrade.heathcliff.eu,admissionReviewVersions=v1,sideEffects=None
15

16
// planValidatingHook validates the plan
17
type planValidatingHook struct {
18
        client.Client
19
}
20

21
// Validate all values of the plan and check if they are sensible
22
func (*planValidatingHook) validate(obj runtime.Object) (admission.Warnings, error) {
22✔
23
        plan, ok := obj.(*api.KubeUpgradePlan)
22✔
24
        if !ok {
23✔
25
                return nil, fmt.Errorf("expected a KubeUpgradePlan but got a %T", obj)
1✔
26
        }
1✔
27

28
        err := api.ValidateObject_KubeUpgradePlan(plan)
21✔
29
        if err != nil {
36✔
30
                return nil, err
15✔
31
        }
15✔
32

33
        return nil, nil
6✔
34
}
35

36
// ValidateCreate validates the object on creation.
37
// The optional warnings will be added to the response as warning messages.
38
// Return an error if the object is invalid.
39
func (p *planValidatingHook) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
4✔
40
        if p.Client == nil {
5✔
41
                return nil, fmt.Errorf("no client provided for validating webhook, please report a bug")
1✔
42
        }
1✔
43

44
        planList := &api.KubeUpgradePlanList{}
3✔
45
        err := p.List(ctx, planList)
3✔
46
        if err != nil {
3✔
NEW
47
                return nil, fmt.Errorf("failed to list KubeUpgradePlans: %v", err)
×
NEW
48
        }
×
49
        if len(planList.Items) > 0 {
4✔
50
                slog.With("existing-plan", planList.Items[0].Name).Warn("Attempted to create a KubeUpgradePlan, but one already exists")
1✔
51
                return nil, fmt.Errorf("KubeUpgradePlan already exists")
1✔
52
        }
1✔
53

54
        return p.validate(obj)
2✔
55
}
56

57
// ValidateUpdate validates the object on update.
58
// The optional warnings will be added to the response as warning messages.
59
// Return an error if the object is invalid.
60
func (p *planValidatingHook) ValidateUpdate(_ context.Context, _ runtime.Object, newObj runtime.Object) (admission.Warnings, error) {
2✔
61
        return p.validate(newObj)
2✔
62
}
2✔
63

64
// ValidateDelete validates the object on deletion.
65
// The optional warnings will be added to the response as warning messages.
66
// Return an error if the object is invalid.
67
func (*planValidatingHook) ValidateDelete(_ context.Context, _ runtime.Object) (admission.Warnings, error) {
1✔
68
        return nil, nil
1✔
69
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc