-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* xds: create app interface * Create k8s pkg (#11) * xds: create app interface * create k8s package * Update README.md * create the app in main * to save * merge with main * update readme * connect xds to app
- Loading branch information
1 parent
0eeb090
commit c93d2bf
Showing
36 changed files
with
250 additions
and
456 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
vendor | ||
vendor/* | ||
|
||
deployments | ||
deployments/* | ||
build | ||
build/* | ||
mvatandoost | ||
|
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 @@ | ||
package controlplane |
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,20 @@ | ||
package controlplane | ||
|
||
import ( | ||
"log/slog" | ||
|
||
v1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func (a *App) OnAddSerivce(key string, serviceObj *v1.Service) { | ||
slog.Info("OnAddSerivce", "key", key, "name", serviceObj.Name, "Namespace", serviceObj.Namespace, "Labels", serviceObj.Labels) | ||
} | ||
|
||
func (a *App) OnDeleteService(key string, serviceObj *v1.Service) { | ||
slog.Info("OnDeleteService", "key", key, "name", serviceObj.Name, "Namespace", serviceObj.Namespace, "Labels", serviceObj.Labels) | ||
} | ||
|
||
func (a *App) OnUpdateService(newKey string, newServiceObj *v1.Service, oldKey string, oldServiceObj *v1.Service) { | ||
slog.Info("OnUpdateService", "newKey", newKey, "newServiceName", newServiceObj.Name, "newServiceNamespace", newServiceObj.Namespace, | ||
"oldKey", oldKey, "oleServiceName", oldServiceObj.Name, "oldServiceNamespace", oldServiceObj.Namespace) | ||
} |
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,67 @@ | ||
package controlplane | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/mohammadVatandoost/xds-conrol-plane/internal/node" | ||
) | ||
|
||
func (a *App) GetServices() { | ||
} | ||
|
||
func (a *App) CreateNode(id string) *node.Node { | ||
a.mu.Lock() | ||
defer a.mu.Unlock() | ||
n, ok := a.nodes[id] | ||
if !ok { | ||
n = node.NewNode() | ||
} | ||
a.nodes[id] = n | ||
return n | ||
} | ||
|
||
func (a *App) GetNode(id string) (*node.Node, error) { | ||
a.mu.RLock() | ||
defer a.mu.RUnlock() | ||
node, ok := a.nodes[id] | ||
if !ok { | ||
return nil, fmt.Errorf("node with id: %s is not exist", id) | ||
} | ||
return node, nil | ||
} | ||
|
||
func (a *App) DeleteNode(id string) error { | ||
a.mu.Lock() | ||
defer a.mu.Unlock() | ||
_, ok := a.nodes[id] | ||
if !ok { | ||
return fmt.Errorf("node with id: %s is not exist", id) | ||
} | ||
delete(a.nodes, id) | ||
return nil | ||
} | ||
|
||
func (a *App) AddResourceWatchToNode(id string, resource string) { | ||
a.muResource.Lock() | ||
defer a.muResource.Unlock() | ||
nodes, ok := a.resources[resource] | ||
if !ok { | ||
nodes = make(map[string]struct{}) | ||
a.resources[resource] = nodes | ||
} | ||
nodes[id] = struct{}{} | ||
} | ||
|
||
func (a *App) GetNodesWatchTheResource(resource string) []string { | ||
a.muResource.RLock() | ||
defer a.muResource.RUnlock() | ||
nodesArray := make([]string, 0) | ||
nodes, ok := a.resources[resource] | ||
if !ok { | ||
return nodesArray | ||
} | ||
for n := range nodes { | ||
nodesArray = append(nodesArray, n) | ||
} | ||
return nodesArray | ||
} |
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,19 @@ | ||
package controlplane | ||
|
||
import "log/slog" | ||
|
||
|
||
func (a *App) NewStreamRequest(id string, resourceNames []string) { | ||
node := a.CreateNode(id) | ||
for _, rn := range resourceNames { | ||
node.AddWatcher(rn) | ||
a.AddResourceWatchToNode(id, rn) | ||
} | ||
} | ||
|
||
func (a *App) StreamClosed(id string) { | ||
err := a.DeleteNode(id) | ||
if err != nil { | ||
slog.Error("app stream closed", "error", err, "id", id) | ||
} | ||
} |
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.