Skip to content

Commit

Permalink
change key
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammadVatandoost committed Nov 7, 2023
1 parent 3de7915 commit b783980
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ configMap:
LOGGER_LEVEL: "info"
GRPC_GO_LOG_VERBOSITY_LEVEL: 99
GRPC_GO_LOG_SEVERITY_LEVEL: "info"
Server1Address: "xds:///xds-grpc-server-example-headless.control-plane-example:8888"
Server1Address: "xds:///xds-grpc-server-example-headless.control-plane-example.svc.cluster.local:8888"
GRPC_XDS_BOOTSTRAP: "./xds_bootstrap.json"
# GRPC_XDS_BOOTSTRAP_CONFIG: "{\n \"xds_servers\": [\n {\n \"server_uri\": \"xds-control-plane-headless.xds-control-plane.svc.cluster.local:8888\",\n \"channel_creds\": [\n {\n \"type\": \"insecure\"\n }\n ],\n \"server_features\": [\"xds_v3\"] \n }\n ],\n \"node\": {\n \"id\": \"b7f9c818-fb46-43ca-8662-d3bdbcf7ec18~10.0.0.1\",\n \"metadata\": {\n \"R_GCP_PROJECT_NUMBER\": \"123456789012\"\n },\n \"locality\": {\n \"zone\": \"us-central1-a\"\n }\n }\n}\n"

2 changes: 1 addition & 1 deletion example/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ var (
func main() {

// viper.SetDefault("Server1Address", "xds:///xds-grpc-server-example-headless:8888")
viper.SetDefault("Server1Address", "xds:///xds-grpc-server-example-headless.control-plane-example")
viper.SetDefault("Server1Address", "xds:///xds-grpc-server-example-headless.control-plane-example.svc.cluster.local:8888")
// viper.SetDefault("Server1Address", "xds-grpc-server-example-headless:8888")
// Read Config from ENV
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
Expand Down
4 changes: 2 additions & 2 deletions internal/app/control-plane/informer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func (a *App) DeleteService(key string) {
}

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)
// slog.Info("OnUpdateService", "newKey", newKey, "newServiceName", newServiceObj.Name, "newServiceNamespace", newServiceObj.Namespace,
// "oldKey", oldKey, "oleServiceName", oldServiceObj.Name, "oldServiceNamespace", oldServiceObj.Namespace)
a.muResource.Lock()
defer a.muResource.Unlock()
resourceInstance, ok := a.resources[oldKey]
Expand Down
4 changes: 3 additions & 1 deletion internal/app/control-plane/xds.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (a *App) UpdateNodeCache(nodeID string) {
node, ok := a.nodes[nodeID]
if !ok {
slog.Error("UpdateNodeCache, node doesn't exist", "nodeID", nodeID)
return
}
resources := node.GetWatchings()
node.ClearResources()
Expand All @@ -49,8 +50,9 @@ func (a *App) UpdateNodeCache(nodeID string) {
slog.Error("UpdateCache, resource doesn't exist", "resource", rn, "nodeID", nodeID)
continue
}
// resource.ServiceObj.Spec.Ports[0].Name
//ToDo: later fix loop through each port name
endPoint, cluster, route, listner, err := xds.MakeXDSResource(resource, a.conf.Region, a.conf.Zone, resource.ServiceObj.Spec.Ports[0].Name)
endPoint, cluster, route, listner, err := xds.MakeXDSResource(resource, a.conf.Region, a.conf.Zone, "")
if err != nil {
slog.Error("UpdateCache, failed to Make XDS Resource", "error", err, "resource", rn, "nodeID", nodeID)
continue
Expand Down
3 changes: 2 additions & 1 deletion internal/informer/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ func isXDSService(service *v1.Service) (string, bool) {
func getServiceKey(service *v1.Service, portName string) (string, error) {
for _, port := range service.Spec.Ports {
if port.Name == portName {
return service.Name + "." + service.Namespace + ":" + portName, nil
return fmt.Sprintf("%s.%s.svc.cluster.local:%d",
service.Name, service.Namespace, port.Port), nil
}
}
return "", fmt.Errorf("couldn't find the port name, portName: %s, serviceName: %s, namespace: %s",
Expand Down
5 changes: 3 additions & 2 deletions internal/xds/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ func getAddresses(key string, portName string) []string {
// grpcServiceName := svcc.GRPCServiceName //"echo.EchoServer"
// name := fmt.Sprintf("%s.%s.svc.cluster.local", serviceName, namespace)
// name := fmt.Sprintf("%s.%s.svc.cluster.local", serviceName, namespace)
name := fmt.Sprintf("%s.svc.cluster.local", key)
// name := fmt.Sprintf("%s.svc.cluster.local", key)
name := key
cname, rec, err := net.LookupSRV(portName, string(protocol), name)
if err != nil {
slog.Error("Could not find the address", "key", key, "portName", portName, "err", err.Error())
return upstreamPorts
} else {
slog.Info("address found", "cname", cname, "rec", rec)
slog.Info("addresses found", "cname", cname, "rec", rec, "key", key, "name", name)
}

for i := range rec {
Expand Down

0 comments on commit b783980

Please sign in to comment.