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

feat(platform): support networking ingress event for v1 version #1996

Merged
merged 1 commit into from
Jun 22, 2022
Merged
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
26 changes: 23 additions & 3 deletions pkg/platform/proxy/networking/ingress/storage/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ package storage
import (
"context"

"tkestack.io/tke/pkg/platform/proxy"
"tkestack.io/tke/pkg/util/apiclient"

corev1 "k8s.io/api/core/v1"
extensionsv1beta1 "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
networkingv1beta1 "k8s.io/api/networking/v1beta1"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -36,6 +34,8 @@ import (
"k8s.io/apiserver/pkg/registry/rest"
"k8s.io/client-go/kubernetes"
platforminternalclient "tkestack.io/tke/api/client/clientset/internalversion/typed/platform/internalversion"
"tkestack.io/tke/pkg/platform/proxy"
"tkestack.io/tke/pkg/util/apiclient"
)

// EventREST implements the REST endpoint for find events by a daemonset.
Expand Down Expand Up @@ -74,6 +74,9 @@ func (r *EventREST) Get(ctx context.Context, name string, options *metav1.GetOpt
if apiclient.ClusterVersionIsBefore116(client) {
return listEventsByExtensions(ctx, client, namespaceName, name, options)
}
if apiclient.ClusterVersionIsAfter122(client) {
return listEventsByNetworkingsV1(ctx, client, namespaceName, name, options)
}
return listEventsByNetworkings(ctx, client, namespaceName, name, options)
}

Expand Down Expand Up @@ -110,3 +113,20 @@ func listEventsByNetworkings(ctx context.Context, client *kubernetes.Clientset,
}
return client.CoreV1().Events(namespaceName).List(ctx, listOptions)
}

func listEventsByNetworkingsV1(ctx context.Context, client *kubernetes.Clientset, namespaceName, name string, options *metav1.GetOptions) (runtime.Object, error) {
ingress, err := client.NetworkingV1().Ingresses(namespaceName).Get(ctx, name, *options)
if err != nil {
return nil, errors.NewNotFound(networkingv1.Resource("ingresses/events"), name)
}

selector := fields.AndSelectors(
fields.OneTermEqualSelector("involvedObject.uid", string(ingress.UID)),
fields.OneTermEqualSelector("involvedObject.name", ingress.Name),
fields.OneTermEqualSelector("involvedObject.namespace", ingress.Namespace),
fields.OneTermEqualSelector("involvedObject.kind", "Ingress"))
listOptions := metav1.ListOptions{
FieldSelector: selector.String(),
}
return client.CoreV1().Events(namespaceName).List(ctx, listOptions)
}