Skip to content

Commit 9da81b2

Browse files
Merge pull request #854 from mbaldessari/rebase-k8s
Rebase to newer main dependencies
2 parents 76bc471 + 8fcfe13 commit 9da81b2

2,767 files changed

Lines changed: 152521 additions & 124849 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Dockerfile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG GO_VERSION=1.25.7
1+
ARG GO_VERSION=1.26.5
22
FROM registry.access.redhat.com/ubi9/go-toolset:${GO_VERSION} AS builder
33
ARG GOARCH=amd64
44

‎api/v1alpha1/groupversion_info.go‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,27 @@ limitations under the License.
2020
package v1alpha1
2121

2222
import (
23+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24+
"k8s.io/apimachinery/pkg/runtime"
2325
"k8s.io/apimachinery/pkg/runtime/schema"
24-
"sigs.k8s.io/controller-runtime/pkg/scheme"
2526
)
2627

2728
var (
2829
// GroupVersion is group version used to register these objects
2930
GroupVersion = schema.GroupVersion{Group: "gitops.hybrid-cloud-patterns.io", Version: "v1alpha1"}
3031

3132
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
32-
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
33+
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
3334

3435
// AddToScheme adds the types in this group-version to the given scheme.
3536
AddToScheme = SchemeBuilder.AddToScheme
3637
)
38+
39+
func addKnownTypes(s *runtime.Scheme) error {
40+
s.AddKnownTypes(GroupVersion,
41+
&Pattern{},
42+
&PatternList{},
43+
)
44+
metav1.AddToGroupVersion(s, GroupVersion)
45+
return nil
46+
}

‎api/v1alpha1/pattern_types.go‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,3 @@ const (
280280
DeleteHubChildApps PatternDeletionPhase = "DeleteHubChildApps"
281281
DeleteHub PatternDeletionPhase = "DeleteHub"
282282
)
283-
284-
func init() {
285-
SchemeBuilder.Register(&Pattern{}, &PatternList{})
286-
}

‎api/v1alpha1/pattern_webhook.go‎

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,9 @@ import (
2121
"fmt"
2222
"strings"
2323

24-
"k8s.io/apimachinery/pkg/runtime"
2524
ctrl "sigs.k8s.io/controller-runtime"
2625
"sigs.k8s.io/controller-runtime/pkg/client"
2726
logf "sigs.k8s.io/controller-runtime/pkg/log"
28-
"sigs.k8s.io/controller-runtime/pkg/webhook"
2927
"sigs.k8s.io/controller-runtime/pkg/webhook/admission"
3028
)
3129

@@ -42,23 +40,18 @@ type PatternValidator struct {
4240
//nolint:lll
4341
// +kubebuilder:webhook:verbs=create;update;delete,path=/validate-gitops-hybrid-cloud-patterns-io-v1alpha1-pattern,mutating=false,failurePolicy=fail,groups=gitops.hybrid-cloud-patterns.io,resources=patterns,versions=v1alpha1,name=vpattern.gitops.hybrid-cloud-patterns.io,admissionReviewVersions=v1,sideEffects=none
4442

45-
var _ webhook.CustomValidator = &PatternValidator{}
43+
var _ admission.Validator[*Pattern] = &PatternValidator{}
4644

4745
// SetupWebhookWithManager will setup the manager to manage the webhooks
4846
func (r *PatternValidator) SetupWebhookWithManager(mgr ctrl.Manager) error {
4947
r.Client = mgr.GetClient()
50-
return ctrl.NewWebhookManagedBy(mgr).
51-
For(&Pattern{}).
48+
return ctrl.NewWebhookManagedBy(mgr, &Pattern{}).
5249
WithValidator(r).
5350
Complete()
5451
}
5552

5653
// ValidateCreate implements webhook.CustomValidator so a webhook will be registered for the type
57-
func (r *PatternValidator) ValidateCreate(ctx context.Context, obj runtime.Object) (admission.Warnings, error) {
58-
p, err := convertToPattern(obj)
59-
if err != nil {
60-
return nil, err
61-
}
54+
func (r *PatternValidator) ValidateCreate(ctx context.Context, p *Pattern) (admission.Warnings, error) {
6255
patternlog.Info("validate create", "name", p.Name)
6356

6457
if err := validateVariantAlias(p); err != nil {
@@ -67,7 +60,7 @@ func (r *PatternValidator) ValidateCreate(ctx context.Context, obj runtime.Objec
6760
}
6861

6962
var patterns PatternList
70-
if err = r.Client.List(ctx, &patterns); err != nil {
63+
if err := r.Client.List(ctx, &patterns); err != nil {
7164
return nil, fmt.Errorf("failed to list Pattern resources: %v", err)
7265
}
7366
if len(patterns.Items) > 0 {
@@ -78,11 +71,7 @@ func (r *PatternValidator) ValidateCreate(ctx context.Context, obj runtime.Objec
7871
}
7972

8073
// ValidateUpdate implements webhook.CustomValidator so a webhook will be registered for the type
81-
func (r *PatternValidator) ValidateUpdate(_ context.Context, _, newObj runtime.Object) (admission.Warnings, error) {
82-
p, err := convertToPattern(newObj)
83-
if err != nil {
84-
return nil, err
85-
}
74+
func (r *PatternValidator) ValidateUpdate(_ context.Context, _, p *Pattern) (admission.Warnings, error) {
8675
patternlog.Info("validate update", "name", p.Name)
8776

8877
if err := validateVariantAlias(p); err != nil {
@@ -94,11 +83,7 @@ func (r *PatternValidator) ValidateUpdate(_ context.Context, _, newObj runtime.O
9483
}
9584

9685
// ValidateDelete implements webhook.CustomValidator so a webhook will be registered for the type
97-
func (r *PatternValidator) ValidateDelete(_ context.Context, obj runtime.Object) (admission.Warnings, error) {
98-
p, err := convertToPattern(obj)
99-
if err != nil {
100-
return nil, err
101-
}
86+
func (r *PatternValidator) ValidateDelete(_ context.Context, p *Pattern) (admission.Warnings, error) {
10287
patternlog.Info("validate delete", "name", p.Name)
10388

10489
if !strings.EqualFold(p.Annotations[PruneAnnotation], "true") {
@@ -109,14 +94,6 @@ func (r *PatternValidator) ValidateDelete(_ context.Context, obj runtime.Object)
10994
return nil, nil
11095
}
11196

112-
func convertToPattern(obj runtime.Object) (*Pattern, error) {
113-
p, ok := obj.(*Pattern)
114-
if !ok {
115-
return nil, fmt.Errorf("expected a Pattern object but got %T", obj)
116-
}
117-
return p, nil
118-
}
119-
12097
func validateVariantAlias(p *Pattern) error {
12198
if p.Spec.ClusterGroupName == "" && p.Spec.Variant == "" {
12299
return fmt.Errorf("one of spec.variant or spec.clusterGroupName must be set")

‎api/v1alpha1/pattern_webhook_test.go‎

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -222,23 +222,6 @@ func TestValidateUpdate_AllowsBothSet(t *testing.T) {
222222
}
223223
}
224224

225-
func TestValidateCreate_RejectsNonPatternObject(t *testing.T) {
226-
scheme := runtime.NewScheme()
227-
if err := AddToScheme(scheme); err != nil {
228-
t.Fatalf("failed to add scheme: %v", err)
229-
}
230-
231-
fakeClient := fake.NewClientBuilder().WithScheme(scheme).Build()
232-
validator := &PatternValidator{Client: fakeClient}
233-
234-
notAPattern := &PatternList{}
235-
236-
_, err := validator.ValidateCreate(context.Background(), notAPattern)
237-
if err == nil {
238-
t.Error("expected error for non-Pattern object, got nil")
239-
}
240-
}
241-
242225
func TestValidateUpdate_Allows(t *testing.T) {
243226
scheme := runtime.NewScheme()
244227
if err := AddToScheme(scheme); err != nil {

‎config/crd/bases/gitops.hybrid-cloud-patterns.io_patterns.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.16.4
6+
controller-gen.kubebuilder.io/version: v0.21.0
77
name: patterns.gitops.hybrid-cloud-patterns.io
88
spec:
99
group: gitops.hybrid-cloud-patterns.io

0 commit comments

Comments
 (0)