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

Add workloadapi options for cmd-registry-memory #56

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions .github/workflows/docker-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
- uses: actions/setup-go@v1
with:
go-version: 1.13.4
- name: Build memory-registry image
run: docker build . -t "${ORG}/memory-registry:${TAG}" --target runtime
- name: Push memory-registry image
- name: Build registry-memory image
run: docker build . -t "${ORG}/registry-memory:${TAG}" --target runtime
- name: Push registry-memory image
run: |
docker login -u $DOCKER_USER -p $DOCKER_PASSWORD
docker push "${ORG}/memory-registry:${TAG}"
docker image rm "${ORG}/memory-registry:${TAG}"
docker push "${ORG}/registry-memory:${TAG}"
docker image rm "${ORG}/registry-memory:${TAG}"
27 changes: 22 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ import (
"context"
"net/url"
"os"
"strings"
"time"

"github.com/spiffe/go-spiffe/v2/svid/x509svid"

"github.com/networkservicemesh/sdk/pkg/registry/common/connect"
"github.com/networkservicemesh/sdk/pkg/registry/common/proxy"

Expand All @@ -32,13 +35,14 @@ import (

nested "github.com/antonfisher/nested-logrus-formatter"
"github.com/kelseyhightower/envconfig"
api_registry "github.com/networkservicemesh/api/pkg/api/registry"
"github.com/sirupsen/logrus"
"github.com/spiffe/go-spiffe/v2/spiffetls/tlsconfig"
"github.com/spiffe/go-spiffe/v2/workloadapi"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"

api_registry "github.com/networkservicemesh/api/pkg/api/registry"

"github.com/networkservicemesh/sdk/pkg/registry/common/setid"

"github.com/networkservicemesh/sdk/pkg/registry/core/chain"
Expand All @@ -51,9 +55,8 @@ import (

// Config is configuration for cmd-registry-memory
type Config struct {
ListenOn url.URL `default:"unix:///listen.on.socket" desc:"url to listen on" split_words:"true"`
ProxyRegistryURL url.URL `desc:"url to the proxy registry that handles this domain" split_words:"true"`
ExpirePeriod time.Duration `default:"1s" desc:"period to check expired NSEs" split_words:"true"`
ListenOn url.URL `default:"unix:///listen.on.socket" desc:"url to listen on" split_words:"true"`
ProxyRegistryURL url.URL `desc:"url to the proxy registry that handles this domain" split_words:"true"`
}

func main() {
Expand Down Expand Up @@ -85,7 +88,21 @@ func main() {
log.Entry(ctx).Infof("Config: %#v", config)

// Get a X509Source
source, err := workloadapi.NewX509Source(ctx)
source, err := workloadapi.NewX509Source(ctx,
workloadapi.WithClientOptions(workloadapi.WithLogger(log.Entry(ctx))),
workloadapi.WithDefaultX509SVIDPicker(func(svids []*x509svid.SVID) *x509svid.SVID {
Copy link
Member

Choose a reason for hiding this comment

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

So I'm not clear why we are using the SVID Picker here...

Copy link
Member Author

@denis-tingaikin denis-tingaikin Aug 16, 2020

Choose a reason for hiding this comment

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

Actually the deployment can fetch few svids. By default workloadapi.NewX509Source just picks first.
So I think we should pick svid for registry if for that has been added spire entry.

Copy link
Member

Choose a reason for hiding this comment

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

Hmm... I'm inclined to not worry about it right now... in practice at least in K8s, I believe its only returning one SVID, and this forces an SVID schema on users they may not want.

Copy link
Member Author

Choose a reason for hiding this comment

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

in practice at least in K8s, I believe its only returning one SVID

I guess it is related to user spire setup...

if len(svids) == 0 {
return nil
}
for _, svid := range svids {
if strings.HasSuffix(svid.ID.Path(), "registry-memory") {
return svid
}
}
return svids[0]
}),
)

if err != nil {
logrus.Fatalf("error getting x509 source: %+v", err)
}
Expand Down
3 changes: 2 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
nested "github.com/antonfisher/nested-logrus-formatter"
"github.com/edwarnicke/exechelper"
"github.com/kelseyhightower/envconfig"
"github.com/networkservicemesh/api/pkg/api/registry"
"github.com/spiffe/go-spiffe/v2/bundle/x509bundle"
"github.com/spiffe/go-spiffe/v2/spiffetls/tlsconfig"
"github.com/spiffe/go-spiffe/v2/svid/x509svid"
Expand All @@ -46,6 +45,8 @@ import (
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/health/grpc_health_v1"

"github.com/networkservicemesh/api/pkg/api/registry"

main "github.com/networkservicemesh/cmd-registry-memory"

"github.com/networkservicemesh/sdk/pkg/tools/spire"
Expand Down
5 changes: 3 additions & 2 deletions pkg/imports/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import (
_ "github.com/edwarnicke/exechelper"
_ "github.com/golang/protobuf/ptypes/timestamp"
_ "github.com/kelseyhightower/envconfig"
_ "github.com/networkservicemesh/api/pkg/api"
_ "github.com/networkservicemesh/api/pkg/api/registry"
_ "github.com/sirupsen/logrus"
_ "github.com/spiffe/go-spiffe/v2/bundle/x509bundle"
_ "github.com/spiffe/go-spiffe/v2/spiffetls/tlsconfig"
Expand All @@ -28,6 +26,9 @@ import (
_ "google.golang.org/grpc/health"
_ "google.golang.org/grpc/health/grpc_health_v1"

_ "github.com/networkservicemesh/api/pkg/api"
_ "github.com/networkservicemesh/api/pkg/api/registry"

_ "github.com/networkservicemesh/sdk/pkg/networkservice/chains/registry"
_ "github.com/networkservicemesh/sdk/pkg/registry/common/expire"
_ "github.com/networkservicemesh/sdk/pkg/registry/common/setid"
Expand Down