Skip to content

Commit

Permalink
Update to latest package versions and update tests affected by this
Browse files Browse the repository at this point in the history
Signed-off-by: Jonathan West <jonwest@redhat.com>
  • Loading branch information
jgwest committed Oct 19, 2024
1 parent 18bafa7 commit 734348c
Show file tree
Hide file tree
Showing 75 changed files with 2,415 additions and 7,934 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/handler"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)

// DeploymentTargetReconciler reconciles a DeploymentTarget object
Expand Down Expand Up @@ -378,21 +377,21 @@ func (r *DeploymentTargetReconciler) SetupWithManager(mgr ctrl.Manager) error {
manager := ctrl.NewControllerManagedBy(mgr).
For(&applicationv1alpha1.DeploymentTarget{}).
Watches(
&source.Kind{Type: &codereadytoolchainv1alpha1.SpaceRequest{}},
&codereadytoolchainv1alpha1.SpaceRequest{},
handler.EnqueueRequestsFromMapFunc(r.findDeploymentTargetsForSpaceRequests))

return manager.Complete(r)
}

func (r *DeploymentTargetReconciler) findDeploymentTargetsForSpaceRequests(sr client.Object) []reconcile.Request {
func (r *DeploymentTargetReconciler) findDeploymentTargetsForSpaceRequests(ctx context.Context, sr client.Object) []reconcile.Request {

srObj, isOk := sr.(*codereadytoolchainv1alpha1.SpaceRequest)
if !isOk {
ctrl.Log.Error(nil, "SEVERE: type mismatch in mapping function. Expected an event for SpaceRequest object")
return []reconcile.Request{}
}

dt, err := findMatchingDTForSpaceRequest(context.Background(), r.Client, *srObj)
dt, err := findMatchingDTForSpaceRequest(ctx, r.Client, *srObj)
if err != nil {
ctrl.Log.Error(err, "unable to find matching DT for space request", "spacerequest", srObj.Name, "namespace", srObj.Namespace)
return []reconcile.Request{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var _ = Describe("Test DeploymentTargetReclaimController", func() {
},
}

k8sClient = fake.NewClientBuilder().WithScheme(scheme).WithObjects(&testNS).Build()
k8sClient = fake.NewClientBuilder().WithScheme(scheme).WithObjects(&testNS).WithStatusSubresource(&appstudiosharedv1.DeploymentTarget{}, &appstudiosharedv1.DeploymentTargetClaim{}).Build()

reconciler = DeploymentTargetReconciler{
Client: k8sClient,
Expand Down Expand Up @@ -195,6 +195,8 @@ var _ = Describe("Test DeploymentTargetReclaimController", func() {

It("should unset the finalizer from the DT", func() {

Skip("Deletion-timestamp-based tests are no longer able to be supported by controller-runtime fake client")

By("creating a default DeploymentTargetClass with Delete policy")
dtcls := generateDeploymentTargetClass(appstudiosharedv1.ReclaimPolicy_Delete)
err := k8sClient.Create(ctx, &dtcls)
Expand Down Expand Up @@ -235,6 +237,8 @@ var _ = Describe("Test DeploymentTargetReclaimController", func() {

It("should unset the finalizer from the DT", func() {

Skip("DeletionTimestamp is not supported")

By("creating a default DeploymentTargetClass with Retain policy")
dtcls := generateDeploymentTargetClass(appstudiosharedv1.ReclaimPolicy_Retain)
err := k8sClient.Create(ctx, &dtcls)
Expand Down Expand Up @@ -297,7 +301,7 @@ var _ = Describe("Test DeploymentTargetReclaimController", func() {
}
Expect(k8sClient.Create(context.Background(), spaceRequest)).To(Succeed())

req := reconciler.findDeploymentTargetsForSpaceRequests(spaceRequest)
req := reconciler.findDeploymentTargetsForSpaceRequests(context.Background(), spaceRequest)
Expect(req).To(BeEmpty())
})
})
Expand All @@ -307,7 +311,7 @@ var _ = Describe("Test DeploymentTargetReclaimController", func() {

notASpaceRequest := &appstudiosharedv1.DeploymentTarget{}

req := reconciler.findDeploymentTargetsForSpaceRequests(notASpaceRequest)
req := reconciler.findDeploymentTargetsForSpaceRequests(context.Background(), notASpaceRequest)
Expect(req).To(BeEmpty())
})
})
Expand Down Expand Up @@ -346,7 +350,7 @@ var _ = Describe("Test DeploymentTargetReclaimController", func() {
}
Expect(k8sClient.Create(context.Background(), dt)).To(Succeed())

req := reconciler.findDeploymentTargetsForSpaceRequests(spaceRequest)
req := reconciler.findDeploymentTargetsForSpaceRequests(context.Background(), spaceRequest)
Expect(req).To(HaveLen(1))
Expect(req[0].NamespacedName).To(Equal(types.NamespacedName{Namespace: dt.Namespace, Name: dt.Name}))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)

const (
Expand Down Expand Up @@ -766,15 +765,15 @@ func (r *DeploymentTargetClaimReconciler) SetupWithManager(mgr ctrl.Manager) err
return ctrl.NewControllerManagedBy(mgr).
For(&applicationv1alpha1.DeploymentTargetClaim{}).
Watches(
&source.Kind{Type: &applicationv1alpha1.DeploymentTarget{}},
&applicationv1alpha1.DeploymentTarget{},
handler.EnqueueRequestsFromMapFunc(r.findObjectsForDeploymentTarget),
builder.WithPredicates(predicate.GenerationChangedPredicate{})).
Complete(r)
}

// Map all incoming DT events to corresponding DTC requests to be handled by the Reconciler.
func (r *DeploymentTargetClaimReconciler) findObjectsForDeploymentTarget(dt client.Object) []reconcile.Request {
ctx := context.Background()
func (r *DeploymentTargetClaimReconciler) findObjectsForDeploymentTarget(ctx context.Context, dt client.Object) []reconcile.Request {

handlerLog := log.FromContext(ctx).
WithName(logutil.LogLogger_managed_gitops)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var _ = Describe("Test DeploymentTargetClaimController", func() {
},
}

k8sClient = fake.NewClientBuilder().WithScheme(scheme).WithObjects(&testNS).Build()
k8sClient = fake.NewClientBuilder().WithScheme(scheme).WithObjects(&testNS).WithStatusSubresource(&appstudiosharedv1.DeploymentTarget{}, &appstudiosharedv1.DeploymentTargetClaim{}).Build()

reconciler = DeploymentTargetClaimReconciler{
Client: k8sClient,
Expand Down Expand Up @@ -1107,7 +1107,7 @@ var _ = Describe("Test DeploymentTargetClaimController", func() {

dt := generateDeploymentTarget()

reqs := reconciler.findObjectsForDeploymentTarget(&dt)
reqs := reconciler.findObjectsForDeploymentTarget(ctx, &dt)
Expect(reqs).To(Equal([]reconcile.Request{}))
})

Expand All @@ -1120,7 +1120,7 @@ var _ = Describe("Test DeploymentTargetClaimController", func() {
dt.Spec.ClaimRef = dtc.Name
})

reqs := reconciler.findObjectsForDeploymentTarget(&dt)
reqs := reconciler.findObjectsForDeploymentTarget(ctx, &dt)
Expect(reqs).To(Equal([]reconcile.Request{
newRequest(dtc.Namespace, dtc.Name),
}))
Expand All @@ -1135,7 +1135,7 @@ var _ = Describe("Test DeploymentTargetClaimController", func() {
err := k8sClient.Create(ctx, &dtc)
Expect(err).ToNot(HaveOccurred())

reqs := reconciler.findObjectsForDeploymentTarget(&dt)
reqs := reconciler.findObjectsForDeploymentTarget(ctx, &dt)
Expect(reqs).To(Equal([]reconcile.Request{
newRequest(dtc.Namespace, dtc.Name),
}))
Expand All @@ -1144,14 +1144,14 @@ var _ = Describe("Test DeploymentTargetClaimController", func() {
It("shouldn't return any request if no DTC was found while handling the DT event", func() {
dt := generateDeploymentTarget()

reqs := reconciler.findObjectsForDeploymentTarget(&dt)
reqs := reconciler.findObjectsForDeploymentTarget(ctx, &dt)
Expect(reqs).To(Equal([]reconcile.Request{}))
})

It("shouldn't return any request if an object of different type is passed", func() {
dtc := generateDeploymentTargetClaim()

reqs := reconciler.findObjectsForDeploymentTarget(&dtc)
reqs := reconciler.findObjectsForDeploymentTarget(ctx, &dtc)
Expect(reqs).To(Equal([]reconcile.Request{}))
})
})
Expand Down Expand Up @@ -1187,7 +1187,7 @@ var _ = Describe("Test DeploymentTargetClaimController", func() {
},
}

k8sClient = fake.NewClientBuilder().WithScheme(scheme).WithObjects(&testNS).Build()
k8sClient = fake.NewClientBuilder().WithScheme(scheme).WithObjects(&testNS).WithStatusSubresource(&appstudiosharedv1.DeploymentTarget{}, &appstudiosharedv1.DeploymentTargetClaim{}).Build()

reconciler = DeploymentTargetClaimReconciler{
Client: k8sClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
managedgitopsv1alpha1 "github.com/redhat-appstudio/managed-gitops/backend-shared/apis/managed-gitops/v1alpha1"
apierr "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/pointer"
"k8s.io/utils/ptr"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -41,7 +41,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"
)

// EnvironmentReconciler reconciles a Environment object
Expand Down Expand Up @@ -517,8 +516,8 @@ func generateDesiredResource(ctx context.Context, env appstudioshared.Environmen
Kind: env.Kind,
Name: env.Name,
UID: env.UID,
BlockOwnerDeletion: pointer.Bool(true),
Controller: pointer.Bool(true),
BlockOwnerDeletion: ptr.To(true),
Controller: ptr.To(true),
},
},
},
Expand Down Expand Up @@ -629,22 +628,22 @@ func (r *EnvironmentReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&appstudioshared.Environment{}).
Watches(
&source.Kind{Type: &corev1.Secret{}},
&corev1.Secret{},
handler.EnqueueRequestsFromMapFunc(r.findObjectsForSecret),
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}), // secret doesn't have a generation, so we use RV
).
Watches(
&source.Kind{Type: &appstudioshared.DeploymentTargetClaim{}},
&appstudioshared.DeploymentTargetClaim{},
handler.EnqueueRequestsFromMapFunc(r.findObjectsForDeploymentTargetClaim),
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}),
).
Watches(
&source.Kind{Type: &appstudioshared.DeploymentTarget{}},
&appstudioshared.DeploymentTarget{},
handler.EnqueueRequestsFromMapFunc(r.findObjectsForDeploymentTarget),
builder.WithPredicates(predicate.GenerationChangedPredicate{}),
).
Watches(
&source.Kind{Type: &managedgitopsv1alpha1.GitOpsDeploymentManagedEnvironment{}},
&managedgitopsv1alpha1.GitOpsDeploymentManagedEnvironment{},
handler.EnqueueRequestsFromMapFunc(r.findObjectsForGitOpsDeploymentManagedEnvironment),
builder.WithPredicates(predicate.GenerationChangedPredicate{}),
).
Expand All @@ -653,8 +652,8 @@ func (r *EnvironmentReconciler) SetupWithManager(mgr ctrl.Manager) error {

// findObjectsForGitOpsDeploymentManagedEnvironment maps an incoming GitOpsDeploymentManagedEnvironment event to the
// corresponding Environment request.
func (r *EnvironmentReconciler) findObjectsForGitOpsDeploymentManagedEnvironment(managedEnv client.Object) []reconcile.Request {
ctx := context.Background()
func (r *EnvironmentReconciler) findObjectsForGitOpsDeploymentManagedEnvironment(ctx context.Context, managedEnv client.Object) []reconcile.Request {

handlerLog := log.FromContext(ctx).
WithName(logutil.LogLogger_managed_gitops)

Expand Down Expand Up @@ -682,8 +681,8 @@ func (r *EnvironmentReconciler) findObjectsForGitOpsDeploymentManagedEnvironment
}

// findObjectsForDeploymentTargetClaim maps an incoming DTC event to the corresponding Environment request.
func (r *EnvironmentReconciler) findObjectsForDeploymentTargetClaim(dtc client.Object) []reconcile.Request {
ctx := context.Background()
func (r *EnvironmentReconciler) findObjectsForDeploymentTargetClaim(ctx context.Context, dtc client.Object) []reconcile.Request {

handlerLog := log.FromContext(ctx).
WithName(logutil.LogLogger_managed_gitops)

Expand Down Expand Up @@ -713,8 +712,8 @@ func (r *EnvironmentReconciler) findObjectsForDeploymentTargetClaim(dtc client.O

// findObjectsForDeploymentTarget maps an incoming DT event to the corresponding Environment request.
// We should reconcile Environments if the DT credentials get updated.
func (r *EnvironmentReconciler) findObjectsForDeploymentTarget(dt client.Object) []reconcile.Request {
ctx := context.Background()
func (r *EnvironmentReconciler) findObjectsForDeploymentTarget(ctx context.Context, dt client.Object) []reconcile.Request {

handlerLog := log.FromContext(ctx).
WithName(logutil.LogLogger_managed_gitops)

Expand Down Expand Up @@ -768,8 +767,8 @@ func (r *EnvironmentReconciler) findObjectsForDeploymentTarget(dt client.Object)
// There are two types of secrets that we want to reconcile:
// 1. Secret created by the SpaceRequest controller
// 2. Secret created for the managed Environment
func (r *EnvironmentReconciler) findObjectsForSecret(secret client.Object) []reconcile.Request {
ctx := context.Background()
func (r *EnvironmentReconciler) findObjectsForSecret(ctx context.Context, secret client.Object) []reconcile.Request {

handlerLog := log.FromContext(ctx).
WithName(logutil.LogLogger_managed_gitops)

Expand Down
Loading

0 comments on commit 734348c

Please sign in to comment.