This repository has been archived by the owner on Jul 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 90
[WIP] Make KPNG more like a library and decouple from the GRPC API #389
Closed
astoycos
wants to merge
3
commits into
kubernetes-retired:master
from
astoycos:refactor-sink-interface
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Interface Print State Example | ||
|
||
This Example showcases the use of KPNG as a library, which simply prints the | ||
ENLS(expected node local state) for services and endpoints from a running | ||
K8s cluster. | ||
|
||
To run this manually simply point it to a kubeconfig and specify the node name | ||
you're interested in i.e | ||
|
||
```bash | ||
go run main.go --kubeconfig=/home/USER/.kube/config --nodename=kpng-e2e-ipv4-nft-control-plane | ||
``` | ||
|
||
And you can watch as the state is delivered. | ||
|
||
For example when a simple hello world service is created with | ||
|
||
`kubectl expose deployment nginx-deployment --type=ClusterIP` | ||
|
||
The example shows the expected changes for a given node: | ||
|
||
```bash | ||
go run main.go --kubeconfig=/home/astoycos/.kube/config --nodename=kpng-e2e-ipv4-nft-worker | ||
... | ||
I1021 15:06:50.966214 1033987 main.go:37] Got Service Update: Name -> nginx-deployment, Namespace -> default | ||
I1021 15:06:50.970474 1033987 main.go:53] Got Endpoint Update: [EPSName: nginx-deployment-qzxrf, Ips: V4:"10.1.1.7", isLocal: true] for Service: nginx-deployment | ||
I1021 15:06:50.970576 1033987 main.go:53] Got Endpoint Update: [EPSName: nginx-deployment-qzxrf, Ips: V4:"10.1.2.8", isLocal: false] for Service: nginx-deployment | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module sigs.k8s.io/kpng/examples/interface-print-state | ||
|
||
go 1.19 | ||
|
||
require k8s.io/klog/v2 v2.80.1 | ||
|
||
require github.com/go-logr/logr v1.2.3 // indirect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/go-logr/logr v1.2.3 h1:2DntVwHkVopvECVRSlL5PSo9eG+cAkDCuckLubN+rq0= | ||
k8s.io/klog/v2 v2.80.1 h1:atnLQ121W371wYYFawwYx1aEY2eUfs4l3J72wtgAwV4= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
/* | ||
Copyright 2021 The Kubernetes Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
|
||
"k8s.io/klog/v2" | ||
"sigs.k8s.io/kpng/api/localnetv1" | ||
"sigs.k8s.io/kpng/server/jobs/kube2store" | ||
"sigs.k8s.io/kpng/server/jobs/store2localinterface" | ||
) | ||
|
||
type myBackend struct{} | ||
|
||
var _ store2localinterface.NodeLocalStateConsumer = myBackend{} | ||
|
||
func (m myBackend) UpdateServices(services <-chan *localnetv1.Service) { | ||
klog.V(2).Info("In Backend Update Service") | ||
for service := range services { | ||
klog.Infof("Got Service Update: Name -> %s, Namespace -> %s\n", service.Name, service.Namespace) | ||
} | ||
} | ||
|
||
func (m myBackend) DeleteServices(services <-chan *localnetv1.Service) { | ||
klog.V(2).Info("In Backend Delete Service") | ||
|
||
for service := range services { | ||
klog.Infof("Got Service Delete: %v\n", service) | ||
} | ||
} | ||
|
||
func (m myBackend) UpdateEndpoints(endpoints <-chan *localnetv1.EndpointInfo) { | ||
klog.V(2).Info("In Backend Update Endpoint") | ||
|
||
for endpoint := range endpoints { | ||
klog.Infof("Got Endpoint Update: [EPSName: %s, Ips: %+v, isLocal: %v] for Service: %s \n", | ||
endpoint.SourceName, endpoint.Endpoint.IPs, endpoint.Endpoint.Local, endpoint.ServiceName) | ||
} | ||
} | ||
|
||
func (m myBackend) DeleteEndpoints(endpoints <-chan *localnetv1.EndpointInfo) { | ||
klog.V(2).Info("In Backend Delete Endpoint") | ||
|
||
for endpoint := range endpoints { | ||
klog.Infof("Got Endpoint Delete: %v\n", endpoint) | ||
} | ||
} | ||
|
||
var ( | ||
nodeName = flag.String("nodename", "", "Node Name to get services data") | ||
kubeconfig = flag.String("kubeconfig", "", "Path to Kube Config") | ||
) | ||
|
||
func main() { | ||
klog.InitFlags(nil) | ||
defer klog.Flush() | ||
|
||
flag.Parse() | ||
printBackend := myBackend{} | ||
k2sCfg := &kube2store.Config{} | ||
// kubeconfig := "~/.kube/config" | ||
// kubeserver := "" | ||
|
||
ctx, store, err := store2localinterface.StartKube2store(k2sCfg, *kubeconfig, "") | ||
if err != nil { | ||
fmt.Printf("Unable to start kube2store exiting %v", err) | ||
os.Exit(1) | ||
} | ||
// If this returns something broke :-) | ||
store2localinterface.WatchStore(ctx, store, *nodeName, printBackend) | ||
|
||
ctx.Done() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why prefix an internal type with the project's name, or any part of the package path btw?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed :)