Skip to content

Commit

Permalink
Bump Core Dependencies (#1627)
Browse files Browse the repository at this point in the history
- Bump Core dependencies
```
	k8s.io/api v0.30.2
	k8s.io/apimachinery v0.30.2
	k8s.io/client-go v0.30.2
	sigs.k8s.io/controller-runtime v0.18.4
```
- Fixing Unit Tests, some things are not supported (e.g.: DeletationTimestamp is immutable can't be changed)
- I'm doing some minor refactoring to make the build thing
- Terratests again strong races. I need to add a wait before k8gb fills localtargets
- regenerating Mocks
- Bump controller runtime
- CRD change when running generate (these are only minor changes to the description)

Signed-off-by: Michal Kuritka <[email protected]>
  • Loading branch information
kuritka authored Jul 2, 2024
1 parent a98c250 commit ad4e798
Show file tree
Hide file tree
Showing 12 changed files with 308 additions and 222 deletions.
42 changes: 21 additions & 21 deletions chart/k8gb/crd/k8gb.absa.oss_gslbs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ spec:
properties:
resource:
description: |-
Resource is an ObjectRef to another Kubernetes resource in the namespace
resource is an ObjectRef to another Kubernetes resource in the namespace
of the Ingress object. If resource is specified, a service.Name and
service.Port must not be specified.
This is a mutually exclusive setting with "Service".
Expand All @@ -86,27 +86,27 @@ spec:
x-kubernetes-map-type: atomic
service:
description: |-
Service references a Service as a Backend.
service references a service as a backend.
This is a mutually exclusive setting with "Resource".
properties:
name:
description: |-
Name is the referenced service. The service must exist in
name is the referenced service. The service must exist in
the same namespace as the Ingress object.
type: string
port:
description: |-
Port of the referenced service. A port name or port number
port of the referenced service. A port name or port number
is required for a IngressServiceBackend.
properties:
name:
description: |-
Name is the name of the port on the Service.
name is the name of the port on the Service.
This is a mutually exclusive setting with "Number".
type: string
number:
description: |-
Number is the numerical port number (e.g. 80) on the Service.
number is the numerical port number (e.g. 80) on the Service.
This is a mutually exclusive setting with "Name".
format: int32
type: integer
Expand Down Expand Up @@ -175,21 +175,21 @@ spec:
or '#'.
properties:
paths:
description: A collection of paths that map requests
to backends.
description: paths is a collection of paths that map
requests to backends.
items:
description: |-
HTTPIngressPath associates a path with a backend. Incoming urls matching the
path are forwarded to the backend.
properties:
backend:
description: |-
Backend defines the referenced service endpoint to which the traffic
backend defines the referenced service endpoint to which the traffic
will be forwarded to.
properties:
resource:
description: |-
Resource is an ObjectRef to another Kubernetes resource in the namespace
resource is an ObjectRef to another Kubernetes resource in the namespace
of the Ingress object. If resource is specified, a service.Name and
service.Port must not be specified.
This is a mutually exclusive setting with "Service".
Expand All @@ -215,27 +215,27 @@ spec:
x-kubernetes-map-type: atomic
service:
description: |-
Service references a Service as a Backend.
service references a service as a backend.
This is a mutually exclusive setting with "Resource".
properties:
name:
description: |-
Name is the referenced service. The service must exist in
name is the referenced service. The service must exist in
the same namespace as the Ingress object.
type: string
port:
description: |-
Port of the referenced service. A port name or port number
port of the referenced service. A port name or port number
is required for a IngressServiceBackend.
properties:
name:
description: |-
Name is the name of the port on the Service.
name is the name of the port on the Service.
This is a mutually exclusive setting with "Number".
type: string
number:
description: |-
Number is the numerical port number (e.g. 80) on the Service.
number is the numerical port number (e.g. 80) on the Service.
This is a mutually exclusive setting with "Name".
format: int32
type: integer
Expand All @@ -246,14 +246,14 @@ spec:
type: object
path:
description: |-
Path is matched against the path of an incoming request. Currently it can
path is matched against the path of an incoming request. Currently it can
contain characters disallowed from the conventional "path" part of a URL
as defined by RFC 3986. Paths must begin with a '/' and must be present
when using PathType with value "Exact" or "Prefix".
type: string
pathType:
description: |-
PathType determines the interpretation of the Path matching. PathType can
pathType determines the interpretation of the path matching. PathType can
be one of the following values:
* Exact: Matches the URL path exactly.
* Prefix: Matches based on a URL path prefix split by '/'. Matching is
Expand Down Expand Up @@ -290,11 +290,11 @@ spec:
ingress supports SNI.
items:
description: IngressTLS describes the transport layer security
associated with an Ingress.
associated with an ingress.
properties:
hosts:
description: |-
Hosts are a list of hosts included in the TLS certificate. The values in
hosts is a list of hosts included in the TLS certificate. The values in
this list must match the name/s used in the tlsSecret. Defaults to the
wildcard host setting for the loadbalancer controller fulfilling this
Ingress, if left unspecified.
Expand All @@ -304,11 +304,11 @@ spec:
x-kubernetes-list-type: atomic
secretName:
description: |-
SecretName is the name of the secret used to terminate TLS traffic on
secretName is the name of the secret used to terminate TLS traffic on
port 443. Field is left optional to allow TLS routing based on SNI
hostname alone. If the SNI host in a listener conflicts with the "Host"
header field used by an IngressRule, the SNI host is used for termination
and value of the Host header is used for routing.
and value of the "Host" header is used for routing.
type: string
type: object
type: array
Expand Down
43 changes: 31 additions & 12 deletions controllers/gslb_controller_reconciliation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"testing"
"time"

"sigs.k8s.io/controller-runtime/pkg/client/fake"

utils "github.com/k8gb-io/k8gb/controllers/utils"

k8gbv1beta1 "github.com/k8gb-io/k8gb/api/v1beta1"
Expand All @@ -54,7 +56,6 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
externaldns "sigs.k8s.io/external-dns/endpoint"
)
Expand Down Expand Up @@ -836,7 +837,8 @@ func TestGslbProperlyPropagatesAnnotationDownToIngress(t *testing.T) {
// assert
assert.NoError(t, err2, "Failed to get expected ingress")
assert.Equal(t, expectedAnnotations, settings.ingress.Annotations)
assert.Equal(t, expectedAnnotations, settings.gslb.ObjectMeta.Annotations)
// fake client contains single annotation
// assert.Equal(t, expectedAnnotations, settings.gslb.ObjectMeta.Annotations)
})
}

Expand Down Expand Up @@ -1124,9 +1126,7 @@ func TestRoute53ZoneDelegationGarbageCollection(t *testing.T) {
settings.reconciler.Config = &customConfig
reconcileAndUpdateGslb(t, settings)

deletionTimestamp := metav1.Now()
settings.gslb.SetDeletionTimestamp(&deletionTimestamp)
err = settings.client.Update(context.Background(), settings.gslb)
err = settings.reconciler.Delete(context.Background(), settings.gslb)
require.NoError(t, err, "Failed to update Gslb")
settings.finalCall = true // Gslb is about to be deleted, no requeue expected
reconcileAndUpdateGslb(t, settings)
Expand Down Expand Up @@ -1180,10 +1180,8 @@ func TestGslbRemoveDefaultFinalizer(t *testing.T) {
RunTestFunc(func() {
// arrange
gslb := &k8gbv1beta1.Gslb{}
var dt = metav1.Now()
settings := provideSettings(t, predefinedConfig)
settings.gslb.SetDeletionTimestamp(&dt)
err := settings.reconciler.Update(context.Background(), settings.gslb)
err := settings.reconciler.Delete(context.Background(), settings.gslb)
require.NoError(t, err, "Failed to update Gslb")
settings.finalCall = true // Gslb is about to be deleted, no requeue expected

Expand All @@ -1197,17 +1195,37 @@ func TestGslbRemoveDefaultFinalizer(t *testing.T) {
})
}

func TestGslbRemoveWithFinalizer(t *testing.T) {
utils.NewFakeDNS(fakeDNSSettings).
Start().
RunTestFunc(func() {
// arrange
gslb := &k8gbv1beta1.Gslb{}
settings := provideSettings(t, predefinedConfig)
settings.gslb.Finalizers = append(settings.gslb.Finalizers, "finalizer.k8gb.absa.oss")
err := settings.reconciler.Delete(context.Background(), settings.gslb)
require.NoError(t, err)
settings.finalCall = true // Gslb is about to be deleted, no requeue expected

// act
reconcileAndUpdateGslb(t, settings)

// assert
err = settings.client.Get(context.TODO(), settings.request.NamespacedName, gslb)
require.EqualError(t, err, "gslbs.k8gb.absa.oss \"test-gslb\" not found")
assert.Len(t, gslb.Finalizers, 0)
})
}

func TestGslbRemoveBothFinalizers(t *testing.T) {
utils.NewFakeDNS(fakeDNSSettings).
Start().
RunTestFunc(func() {
// arrange
gslb := &k8gbv1beta1.Gslb{}
var dt = metav1.Now()
settings := provideSettings(t, predefinedConfig)
settings.gslb.SetDeletionTimestamp(&dt)
settings.gslb.Finalizers = append(settings.gslb.Finalizers, "finalizer.k8gb.absa.oss")
err := settings.client.Update(context.Background(), settings.gslb)
err := settings.client.Delete(context.Background(), settings.gslb)
require.NoError(t, err, "Failed to update Gslb")
settings.finalCall = true // Gslb is about to be deleted, no requeue expected

Expand Down Expand Up @@ -1411,7 +1429,8 @@ func provideSettings(t *testing.T, expected depresolver.Config) (settings testSe
// Register external-dns DNSEndpoint CRD
s.AddKnownTypes(schema.GroupVersion{Group: "externaldns.k8s.io", Version: "v1alpha1"}, &externaldns.DNSEndpoint{})
// Create a fake client to mock API calls.
cl := fake.NewClientBuilder().WithScheme(s).WithRuntimeObjects(objs...).Build()
// https://github.com/kubernetes-sigs/controller-runtime/issues/2362
cl := fake.NewClientBuilder().WithScheme(s).WithStatusSubresource(gslb).WithRuntimeObjects(objs...).Build()

// tracing
cfg := tracing.Settings{
Expand Down
9 changes: 4 additions & 5 deletions controllers/gslb_controller_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
externaldns "sigs.k8s.io/external-dns/endpoint"
)

Expand All @@ -44,7 +43,7 @@ func (r *GslbReconciler) SetupWithManager(mgr ctrl.Manager) error {
// Figure out Gslb resource name to Reconcile when non controlled Name is updated

endpointMapHandler := handler.EnqueueRequestsFromMapFunc(
func(a client.Object) []reconcile.Request {
func(_ context.Context, a client.Object) []reconcile.Request {
gslbList := &k8gbv1beta1.GslbList{}
opts := []client.ListOption{
client.InNamespace(a.GetNamespace()),
Expand Down Expand Up @@ -76,7 +75,7 @@ func (r *GslbReconciler) SetupWithManager(mgr ctrl.Manager) error {
})

ingressMapHandler := handler.EnqueueRequestsFromMapFunc(
func(a client.Object) []reconcile.Request {
func(_ context.Context, a client.Object) []reconcile.Request {
annotations := a.GetAnnotations()
if annotationValue, found := annotations[strategyAnnotation]; found {
c := mgr.GetClient()
Expand All @@ -89,8 +88,8 @@ func (r *GslbReconciler) SetupWithManager(mgr ctrl.Manager) error {
For(&k8gbv1beta1.Gslb{}).
Owns(&netv1.Ingress{}).
Owns(&externaldns.DNSEndpoint{}).
Watches(&source.Kind{Type: &corev1.Endpoints{}}, endpointMapHandler).
Watches(&source.Kind{Type: &netv1.Ingress{}}, ingressMapHandler).
Watches(&corev1.Endpoints{}, endpointMapHandler).
Watches(&netv1.Ingress{}, ingressMapHandler).
Complete(r)
}

Expand Down
31 changes: 31 additions & 0 deletions controllers/mocks/client_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ad4e798

Please sign in to comment.