Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to controller-runtime metadata client #330

Merged
merged 3 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion controllers/receiver_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,20 @@ func TestReceiverHandler(t *testing.T) {
g.Expect(k8sClient.Update(context.Background(), &rcvrObj)).To(Succeed())
g.Consistently(func() bool {
var obj notifyv1.Receiver
g.Expect(k8sClient.Get(context.Background(), client.ObjectKeyFromObject(receiver), &obj))
g.Expect(k8sClient.Get(context.Background(), client.ObjectKeyFromObject(receiver), &obj)).To(Succeed())
return obj.Status.URL == address
}, 30*time.Second, time.Second).Should(BeTrue())

res, err := http.Post("http://localhost:56788/"+address, "application/json", nil)
g.Expect(err).ToNot(HaveOccurred())
g.Expect(res.StatusCode).To(Equal(http.StatusOK))
g.Eventually(func() bool {
obj := &unstructured.Unstructured{}
obj.SetGroupVersionKind(object.GroupVersionKind())
g.Expect(k8sClient.Get(context.Background(), client.ObjectKeyFromObject(object), obj)).To(Succeed())
v, ok := obj.GetAnnotations()[meta.ReconcileRequestAnnotation]
return ok && v != ""
}, 30*time.Second, time.Second).Should(BeTrue())
}

func readManifest(manifest, namespace string) (*unstructured.Unstructured, error) {
Expand Down
6 changes: 2 additions & 4 deletions internal/server/event_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/fluxcd/pkg/runtime/conditions"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/yaml"
Expand Down Expand Up @@ -269,9 +268,8 @@ func (s *EventServer) eventMatchesAlert(ctx context.Context, event *events.Event

labelMatch := true
if source.Name == "*" && source.MatchLabels != nil {
var obj unstructured.Unstructured
obj.SetKind(event.InvolvedObject.Kind)
obj.SetAPIVersion(event.InvolvedObject.APIVersion)
var obj metav1.PartialObjectMetadata
obj.SetGroupVersionKind(event.InvolvedObject.GroupVersionKind())
obj.SetName(event.InvolvedObject.Name)
obj.SetNamespace(event.InvolvedObject.Namespace)

Expand Down
3 changes: 1 addition & 2 deletions internal/server/receiver_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/google/go-github/v41/github"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -373,7 +372,7 @@ func (s *ReceiverServer) annotate(ctx context.Context, resource v1beta1.CrossNam

group, version := getGroupVersion(apiVersion)

u := &unstructured.Unstructured{}
u := &metav1.PartialObjectMetadata{}
u.SetGroupVersionKind(schema.GroupVersionKind{
Group: group,
Kind: resource.Kind,
Expand Down