Skip to content

Commit

Permalink
Do not show internal config when running swctl (#95)
Browse files Browse the repository at this point in the history
* Do not show internal config when running swctl

Signed-off-by: Peter Motičák <[email protected]>

* Bump vpp-agent version

Signed-off-by: Peter Motičák <[email protected]>

---------

Signed-off-by: Peter Motičák <[email protected]>
  • Loading branch information
pemoticak authored Jun 9, 2023
1 parent 6837476 commit 7285bb9
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 15 deletions.
26 changes: 20 additions & 6 deletions cmd/swctl/cmd_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,50 @@ import (
"fmt"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"golang.org/x/exp/slices"

"go.pantheon.tech/stonework/plugins/puntmgr"
)

// TODO:
// - internal config: add support for showing only non-internal user config - which excludes stonework-CNF wiring (punts)
// - run the agentctl with the default host set to stonework (using the -H or running inside stonework image)

type ConfigCmdOptions struct {
Args []string
ShowInternal bool
Args []string
}

func (opts *ConfigCmdOptions) InstallFlags(flagset *pflag.FlagSet) {
flagset.BoolVar(&opts.ShowInternal, "show-internal", false, "Add Stonework internal configuration to output if possible")
}

func NewConfigCmd(cli Cli) *cobra.Command {
var (
opts ConfigCmdOptions
)
cmd := &cobra.Command{
Use: "config [flags] ACTION",
Short: "Manage config of StoneWork components",
Args: cobra.ArbitraryArgs,
DisableFlagParsing: true,
Use: "config [flags] ACTION",
Short: "Manage config of StoneWork components",
Args: cobra.ArbitraryArgs,
// DisableFlagParsing: true,
RunE: func(cmd *cobra.Command, args []string) error {
opts.Args = args
return runConfigCmd(cli, opts)
},
}
opts.InstallFlags(cmd.PersistentFlags())
return cmd
}

func runConfigCmd(cli Cli, opts ConfigCmdOptions) error {
args := opts.Args

if slices.Contains(args, "get") && !opts.ShowInternal {
hideInternalFlag := "--labels=\"!" + puntmgr.InternalConfigLabelKey + "=" + puntmgr.InternalConfigLabelValue + "\""
args = append(args, hideInternalFlag)
}

out, err := cli.Exec("agentctl config", args)
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74
go.fd.io/govpp v0.7.0
go.ligato.io/cn-infra/v2 v2.5.0-alpha.0.20220211111933-3d9ff310b1fa
go.ligato.io/vpp-agent/v3 v3.5.0-alpha.0.20230518104332-63ef115e3f6f
go.ligato.io/vpp-agent/v3 v3.5.0-alpha.0.20230602112701-a5dcb5a2d575
google.golang.org/grpc v1.47.0
google.golang.org/protobuf v1.28.2-0.20230222093303-bc1253ad3743
gopkg.in/yaml.v3 v3.0.1
Expand Down Expand Up @@ -112,6 +112,7 @@ require (
go.uber.org/multierr v1.6.0 // indirect
go.uber.org/zap v1.17.0 // indirect
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 // indirect
golang.org/x/net v0.2.0 // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -929,8 +929,8 @@ go.fd.io/govpp v0.7.0 h1:8qideC7G0xPeYz2sjwni8GKWWbNk45Ev73oR1igKDYY=
go.fd.io/govpp v0.7.0/go.mod h1:VxUPq8HGQH6/9IL9saMURL3UcHsUuN8XmETuao5HA7o=
go.ligato.io/cn-infra/v2 v2.5.0-alpha.0.20220211111933-3d9ff310b1fa h1:PbrmPqtS8K7jVVXbs9w2n0AzEqT3KGW/0bXWrSgEoOo=
go.ligato.io/cn-infra/v2 v2.5.0-alpha.0.20220211111933-3d9ff310b1fa/go.mod h1:N4rrtufgHchultyJuN8ClAS7szH3IhcfDcC3LX9cRRo=
go.ligato.io/vpp-agent/v3 v3.5.0-alpha.0.20230518104332-63ef115e3f6f h1:Rr21I4CCnMe2ryM9Me2ApzgzbQ2wA8xLIdk8ISkvNqs=
go.ligato.io/vpp-agent/v3 v3.5.0-alpha.0.20230518104332-63ef115e3f6f/go.mod h1:rbqXVq1y82p2rBzu++cW6ec1aSqZ3PxE1jPK5ywWefI=
go.ligato.io/vpp-agent/v3 v3.5.0-alpha.0.20230602112701-a5dcb5a2d575 h1:Oi54dXfcHFAMzFV/Mguy+lF5VAiHEpHFceXzVogo+vY=
go.ligato.io/vpp-agent/v3 v3.5.0-alpha.0.20230602112701-a5dcb5a2d575/go.mod h1:rbqXVq1y82p2rBzu++cW6ec1aSqZ3PxE1jPK5ywWefI=
go.mozilla.org/pkcs7 v0.0.0-20200128120323-432b2356ecb1/go.mod h1:SNgMg+EgDFwmvSmLRTNKC5fegJjB7v23qTQ0XLGUNHk=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
Expand Down Expand Up @@ -987,6 +987,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 h1:k/i9J1pBpvlfR+9QsetwPyERsqu1GIbi967PQMq3Ivc=
golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20200119044424-58c23975cae1/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
Expand Down
3 changes: 1 addition & 2 deletions plugins/puntmgr/isisx.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ import (
)

// isisxPunt implements PuntHandler for PuntRequest_ISISX
type isisxPunt struct {
}
type isisxPunt struct{}

func NewIsisxPuntHandler() PuntHandler {
return &isisxPunt{}
Expand Down
72 changes: 68 additions & 4 deletions plugins/puntmgr/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,17 @@ import (
"net"
"sync"

"go.ligato.io/cn-infra/v2/datasync/kvdbsync/local"
"go.ligato.io/cn-infra/v2/infra"
"go.ligato.io/cn-infra/v2/rpc/grpc"
"go.ligato.io/cn-infra/v2/servicelabel"
"google.golang.org/protobuf/proto"

"go.ligato.io/vpp-agent/v3/client"
"go.ligato.io/vpp-agent/v3/pkg/models"
kvs "go.ligato.io/vpp-agent/v3/plugins/kvscheduler/api"
"go.ligato.io/vpp-agent/v3/plugins/linux/nsplugin"
"go.ligato.io/vpp-agent/v3/plugins/orchestrator/contextdecorator"
"go.ligato.io/vpp-agent/v3/plugins/vpp/ifplugin"
linux_namespace "go.ligato.io/vpp-agent/v3/proto/ligato/linux/namespace"

Expand All @@ -38,7 +42,12 @@ import (
pb "go.pantheon.tech/stonework/proto/puntmgr"
)

// Punt Manager plugins allows for multiple ligato plugins and even distributed agents to request packet punting
// These constants specify label for Internal StoneWork configuration (that is configuration
// not configured by the user or SW-Modules).
const InternalConfigLabelKey = "io.ligato.from-client"
const InternalConfigLabelValue = "stonework"

// Punt icManager plugins allows for multiple ligato plugins and even distributed agents to request packet punting
// between VPP and the same or distinct Linux network namespace(s). Unless there is a conflict between punt requests,
// the manager will ensure that common configuration items are shared and properly updated (e.g. ABX rules, TAP
// connection, etc.). The manager supports different kinds of packet punting approaches for L2 or L3 source VPP
Expand Down Expand Up @@ -101,8 +110,9 @@ type PuntManagerNamingAPI interface {
}

// InterconnectLink is one of the:
// - AF-UNIX socket
// - pair of interfaces (memif or TAP)
// - AF-UNIX socket
// - pair of interfaces (memif or TAP)
//
// and each type has type-specific parameters.
type InterconnectLink interface {
isInterconnectLink()
Expand Down Expand Up @@ -368,7 +378,7 @@ func (p *Plugin) AddPunt(cnfMsLabel, key string, puntReq *pb.PuntRequest) error
icReqs := puntHandler.GetInterconnectReqs(puntReq)

// try to create interconnects
localTxn := p.CfgClient.ChangeRequest()
localTxn := newPuntChangeRequest(map[string]string{InternalConfigLabelKey: InternalConfigLabelValue})
icType := puntReq.InterconnectType
enableGso := puntReq.EnableGso
interconnects, err := p.icManager.AddInterconnects(localTxn, remoteTxn, id, icReqs, icType, enableGso, withMultiplex)
Expand Down Expand Up @@ -659,3 +669,57 @@ func isSubsetOf(slice1, slice2 []string) bool {
}
return true
}

type puntChangeRequest struct {
txn *client.LazyValTxn
labels map[string]string
err error
}

func newPuntChangeRequest(labels map[string]string) *puntChangeRequest {
return &puntChangeRequest{
txn: client.NewLazyValTxn(local.DefaultRegistry.PropagateChanges),
labels: labels,
}
}

func (r *puntChangeRequest) Update(items ...proto.Message) client.ChangeRequest {
if r.err != nil {
return r
}
for _, item := range items {
key, err := models.GetKey(item)
if err != nil {
r.err = err
return r
}
r.txn.Put(key, client.UpdateItem{Message: item, Labels: r.labels})
}
return r
}

func (r *puntChangeRequest) Delete(items ...proto.Message) client.ChangeRequest {
if r.err != nil {
return r
}
for _, item := range items {
key, err := models.GetKey(item)
if err != nil {
r.err = err
return r
}
r.txn.Delete(key)
}
return r
}

func (r *puntChangeRequest) Send(ctx context.Context) error {
if r.err != nil {
return r.err
}
_, withDataSrc := contextdecorator.DataSrcFromContext(ctx)
if !withDataSrc {
ctx = contextdecorator.DataSrcContext(ctx, "localclient")
}
return r.txn.Commit(ctx)
}

0 comments on commit 7285bb9

Please sign in to comment.