Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Use the AzureResource Informer; Refactor for clarity #20

Merged
merged 26 commits into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c47406a
eds: Use the AzureResource Informer
draychev Dec 31, 2019
120253e
kube: Refactor Kubernetes Provider
draychev Dec 31, 2019
bc6a11f
mesh: Adding mesh.provider types enum
draychev Dec 31, 2019
9c6d111
azure: Split Client and Provider
draychev Jan 2, 2020
849601a
k8s: Split Client and Provider
draychev Jan 2, 2020
7eba42b
mesh: No need for ServiceProviderI
draychev Jan 2, 2020
3d649f8
Refactor
draychev Jan 2, 2020
019c72a
azure: Adding tests
draychev Jan 2, 2020
d899eb6
kube: Adding tests
draychev Jan 3, 2020
fab06b1
Moving run-*.sh to ./scripts
draychev Jan 3, 2020
2308aa5
Remove AZURE_RESOURCE_GROUP
draychev Jan 3, 2020
4908690
Remove AZURE_RESOURCE_GROUP
draychev Jan 3, 2020
cf316cf
Better AzureResource
draychev Jan 3, 2020
3eb21cf
Move gRPC tools to pkg/utils/grpc.go
draychev Jan 3, 2020
c2104bd
Port number as a CLI argument
draychev Jan 3, 2020
6fc7e22
Handle SIGINT / SIGTERM
draychev Jan 3, 2020
62f54fc
Refactor
draychev Jan 3, 2020
d06e2ce
Merge branch 'master' into draychev/use-azure-resource-4
draychev Jan 7, 2020
633463e
Delete unused Providers enum
draychev Jan 7, 2020
efb12ea
mesh.GetComputeIDForService should return a slice of ComputeIDs
draychev Jan 7, 2020
7510205
Adding comments
draychev Jan 7, 2020
60ce065
Refactor for clarity; Bring struct declaration close to where it is used
draychev Jan 7, 2020
825ad38
Merge branch 'master' into draychev/use-azure-resource-4
draychev Jan 8, 2020
b55d1ea
Fix a typo
draychev Jan 8, 2020
f4264c9
Leave a TODO to consolidate parseFlags
draychev Jan 8, 2020
ed6645b
Move provider identifiying string to a string const
draychev Jan 8, 2020
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
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

export K8S_NAMESPACE=smc
export AZURE_SUBSCRIPTION=abc
export AZURE_RESOURCE_GROUP=rg
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer need AZURE_RESOURCE_GROUP - the subscription UUID is now available in the AzureResource CRD

export CTR_REGISTRY=your.azurecr.io/smc
export CTR_REGISTRY_CREDS_NAME=acr-creds
1 change: 0 additions & 1 deletion DEMO.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Required steps and components for the successful execution of the demo scripts:
In the root directory of the repo create a `.env` file. It is already listed in `.gitignore` so that anything you put in it would not accidentally leak into a public git repo. The `.env` file should contain the following Bash variables:
- `K8S_NAMESPACE` - Namespace within your Kubernetes cluster, where SMC will be installed.
- `AZURE_SUBSCRIPTION` - the Azure subscription where your Kubernete cluster resides. The demo will use this to configure the Endpoint Discovery Service's cloud observer.
- `AZURE_RESOURCE_GROUP` - Resource group where your Azure Kubernetes cluster resides. The demo uses this to configure the Endpoint Discovery Service so that it watches a particular subset of Azure resources.
- `CTR_REGISTRY` - URL of the container registry. For example: `draychev.azurecr.io/smc`
- `CTR_REGISTRY_CREDS_NAME` - name to be used for the Kubernetes secrets resource to be created from the Docker container registry.

Expand Down
58 changes: 0 additions & 58 deletions cmd/eds/clients.go

This file was deleted.

45 changes: 35 additions & 10 deletions cmd/eds/eds.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@ import (
"flag"
"fmt"
"os"
"os/signal"
"strings"
"syscall"
"time"

"github.com/deislabs/smc/pkg/utils"

"github.com/eapache/channels"
envoyControlPlane "github.com/envoyproxy/go-control-plane/envoy/api/v2"
"github.com/golang/glog"
"github.com/spf13/pflag"
"k8s.io/client-go/tools/clientcmd"

"github.com/deislabs/smc/cmd"
"github.com/deislabs/smc/pkg/catalog"
edsServer "github.com/deislabs/smc/pkg/envoy/eds"
"github.com/deislabs/smc/pkg/providers/azure"
"github.com/deislabs/smc/pkg/providers/kube"
)

const (
serverType = "EDS"
port = 15124

verbosityFlag = "verbosity"
defaultNamespace = "default"

maxAuthRetryCount = 10
Expand All @@ -32,10 +37,10 @@ var (
flags = pflag.NewFlagSet(`diplomat-edsServer`, pflag.ExitOnError)
kubeConfigFile = flags.String("kubeconfig", "", "Path to Kubernetes config file.")
azureAuthFile = flags.String("azureAuthFile", "", "Path to Azure Auth File")
resourceGroup = flags.String("resource-group", "", "Azure Resource Group")
subscriptionID = flags.String("subscriptionID", "", "Azure Subscription")
verbosity = flags.Int(verbosityFlag, 1, "Set logging verbosity level")
verbosity = flags.Int("verbosity", 1, "Set logging verbosity level")
namespace = flags.String("namespace", "default", "Kubernetes namespace to watch.")
port = flags.Int("port", 15124, "Endpoint Discovery Service port number. (Default: 15124)")
)

func main() {
Expand All @@ -50,11 +55,30 @@ func main() {
// which would trigger Envoy updates.
announceChan := channels.NewRingChannel(1024)

computeProviders, meshSpec, serviceCatalog := setupClients(announceChan)
grpcServer, lis := cmd.NewGrpc(serverType, port)
eds := edsServer.NewEDSServer(ctx, computeProviders, serviceCatalog, meshSpec, announceChan)
kubeConfig, err := clientcmd.BuildConfigFromFlags("", *kubeConfigFile)
if err != nil {
glog.Fatalf("Error gathering Kubernetes config. Ensure correctness of CLI argument 'kubeconfig=%s': %s", *kubeConfigFile, err)
}

stopChan := make(chan struct{})
meshSpec := kube.NewMeshSpecClient(kubeConfig, getNamespaces(), 1*time.Second, announceChan, stopChan)
kubernetesProvider := kube.NewProvider(kubeConfig, getNamespaces(), 1*time.Second, announceChan, "Kubernetes")
azureProvider := azure.NewProvider(*subscriptionID, *namespace, *azureAuthFile, maxAuthRetryCount, retryPause, announceChan, meshSpec, "Azure")
draychev marked this conversation as resolved.
Show resolved Hide resolved

// ServiceName Catalog is the facility, which we query to get the list of services, weights for traffic split etc.
serviceCatalog := catalog.NewServiceCatalog(meshSpec, stopChan, kubernetesProvider, azureProvider)

grpcServer, lis := utils.NewGrpc(serverType, *port)
eds := edsServer.NewEDSServer(ctx, serviceCatalog, meshSpec, announceChan)
envoyControlPlane.RegisterEndpointDiscoveryServiceServer(grpcServer, eds)
cmd.GrpcServe(ctx, grpcServer, lis, cancel, serverType)
go utils.GrpcServe(ctx, grpcServer, lis, cancel, serverType)

sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
<-sigChan

close(stopChan)
glog.Info("Goodbye!")
}

func parseFlags() {
draychev marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -71,8 +95,9 @@ func getNamespaces() []string {
if namespace == nil {
defaultNS := defaultNamespace
namespaces = []string{defaultNS}
} else {
namespaces = []string{*namespace}
}
namespaces = []string{*namespace}
glog.Infof("Observing namespaces: %s", strings.Join(namespaces, ","))
return namespaces
}
21 changes: 14 additions & 7 deletions cmd/sds/sds.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,27 @@ import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"

"github.com/deislabs/smc/pkg/utils"

envoyControlPlane "github.com/envoyproxy/go-control-plane/envoy/service/discovery/v2"
"github.com/golang/glog"
"github.com/spf13/pflag"

"github.com/deislabs/smc/cmd"
sdsServer "github.com/deislabs/smc/pkg/envoy/sds"
)

const (
serverType = "SDS"
port = 15123

verbosityFlag = "verbosity"
)

var (
flags = pflag.NewFlagSet(`diplomat-sds`, pflag.ExitOnError)
keysDirectory = flags.String("keys-directory", "", "Directory where the keys are stored")
verbosity = flags.Int(verbosityFlag, 1, "Set logging verbosity level")
verbosity = flags.Int("verbosity", 1, "Set logging verbosity level")
port = flags.Int("port", 15123, "Service Discovery Service port number. (Default: 15123)")
)

func main() {
Expand All @@ -34,10 +35,16 @@ func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

grpcServer, lis := cmd.NewGrpc(serverType, port)
grpcServer, lis := utils.NewGrpc(serverType, *port)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as @vramakrishnan requested - we moved the gRPC tools in pkg/utils

sds := sdsServer.NewSDSServer(keysDirectory)
envoyControlPlane.RegisterSecretDiscoveryServiceServer(grpcServer, sds)
cmd.GrpcServe(ctx, grpcServer, lis, cancel, serverType)
go utils.GrpcServe(ctx, grpcServer, lis, cancel, serverType)

sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
<-sigChan

glog.Info("Goodbye!")
Comment on lines +43 to +47
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The syscall handling block here is a bit of a noop at the moment. Reasons for putting it:
a) symmetry with eds.go
b) we are going to need this once proper integrations w/ a certificate management system(s) is implemented

}

func parseFlags() {
Expand Down
9 changes: 9 additions & 0 deletions demo/AzureResource.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: smc.osm.k8s.io/v1
kind: AzureResource
metadata:
name: bookstore
namespace: smc
labels:
app: bookstore-1
spec:
resourceid: /subscriptions/abc/resourcegroups/xyz/providers/Microsoft.Compute/virtualMachines/myVM
3 changes: 0 additions & 3 deletions demo/deploy-eds.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ spec:
args:
- "--kubeconfig"
- "/kube/config"
- "--resource-group"
- "$AZURE_RESOURCE_GROUP"
- "--azureAuthFile"
- "/azure/azureAuth.json"
- "--subscriptionID"
Expand All @@ -82,4 +80,3 @@ spec:
imagePullSecrets:
- name: "$CTR_REGISTRY_CREDS_NAME"
EOF

2 changes: 1 addition & 1 deletion dockerfiles/Dockerfile.eds
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM alpine:3.10.1
ADD bin/eds /eds
ADD ./run-eds.sh /run-eds.sh
ADD ./scripts/run-eds.sh /run-eds.sh
RUN chmod +x /eds
RUN chmod +x /run-eds.sh
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ require (
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
github.com/golang/protobuf v1.3.2
github.com/json-iterator/go v1.1.8 // indirect
github.com/onsi/ginkgo v1.8.0
github.com/onsi/gomega v1.5.0
github.com/pkg/errors v0.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.4.0 // indirect
Expand Down
7 changes: 7 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ github.com/envoyproxy/protoc-gen-validate v0.0.0-20190405222122-d6164de49109 h1:
github.com/envoyproxy/protoc-gen-validate v0.0.0-20190405222122-d6164de49109/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/evanphx/json-patch v0.0.0-20190203023257-5858425f7550/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5IcNrDCXZ6OoTAWu7M=
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
Expand Down Expand Up @@ -146,6 +147,7 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.1/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.1 h1:0hERBMJE1eitiLkihrMvRVBYAkpHzc/J3QdDN+dAcgU=
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.7 h1:Y+UAYTZ7gDEuOfhxKWy+dvb5dRQ6rJjFSdX2HZY1/gI=
Expand Down Expand Up @@ -187,10 +189,12 @@ github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+
github.com/onsi/ginkgo v0.0.0-20170829012221-11459a886d9c/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.8.0 h1:VkHVNpR4iVnU8XQR6DBm8BqYjN7CRzw+xKUbVVbbW9w=
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
github.com/onsi/gomega v0.0.0-20190113212917-5533ce8a0da3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo=
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
Expand Down Expand Up @@ -360,11 +364,13 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/inf.v0 v0.9.0/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
Expand Down Expand Up @@ -400,6 +406,7 @@ k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
k8s.io/kube-openapi v0.0.0-20190228160746-b3a7cee44a30/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc=
k8s.io/kube-openapi v0.0.0-20190502190224-411b2483e503/go.mod h1:iU+ZGYsNlvU9XKUSso6SQfKTCCw7lFduMZy26Mgr2Fw=
k8s.io/kube-openapi v0.0.0-20190603182131-db7b694dc208 h1:5sW+fEHvlJI3Ngolx30CmubFulwH28DhKjGf70Xmtco=
k8s.io/kube-openapi v0.0.0-20190603182131-db7b694dc208/go.mod h1:nfDlWeOsu3pUf4yWGL+ERqohP4YsZcBJXWMK+gkzOA4=
k8s.io/utils v0.0.0-20190221042446-c2654d5206da/go.mod h1:8k8uAuAQ0rXslZKaEWd0c3oVhZz7sSzSiPnVZayjIX0=
k8s.io/utils v0.0.0-20190607212802-c55fbcfc754a h1:2jUDc9gJja832Ftp+QbDV0tVhQHMISFn01els+2ZAcw=
Expand Down
Loading