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

chore(*) delete CLI flag '--bootstrap-version' #2965

Merged
merged 5 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 3 additions & 2 deletions app/kuma-dp/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func newRunCmd(opts kuma_cmd.RunCmdOpts, rootCtx *RootContext) *cobra.Command {
return nil
},
}

var bootstrapVersion string
cmd.PersistentFlags().StringVar(&cfg.Dataplane.Name, "name", cfg.Dataplane.Name, "Name of the Dataplane")
cmd.PersistentFlags().Var(&cfg.Dataplane.AdminPort, "admin-port", `Port (or range of ports to choose from) for Envoy Admin API to listen on. Empty value indicates that Envoy Admin API should not be exposed over TCP. Format: "9901 | 9901-9999 | 9901- | -9901"`)
cmd.PersistentFlags().StringVar(&cfg.Dataplane.Mesh, "mesh", cfg.Dataplane.Mesh, "Mesh that Dataplane belongs to")
Expand All @@ -226,7 +226,8 @@ func newRunCmd(opts kuma_cmd.RunCmdOpts, rootCtx *RootContext) *cobra.Command {
cmd.PersistentFlags().StringVar(&cfg.ControlPlane.CaCertFile, "ca-cert-file", cfg.ControlPlane.CaCertFile, "Path to CA cert by which connection to the Control Plane will be verified if HTTPS is used")
cmd.PersistentFlags().StringVar(&cfg.DataplaneRuntime.BinaryPath, "binary-path", cfg.DataplaneRuntime.BinaryPath, "Binary path of Envoy executable")
cmd.PersistentFlags().Uint32Var(&cfg.DataplaneRuntime.Concurrency, "concurrency", cfg.DataplaneRuntime.Concurrency, "Number of Envoy worker threads")
cmd.PersistentFlags().StringVar(&cfg.Dataplane.BootstrapVersion, "bootstrap-version", cfg.Dataplane.BootstrapVersion, "Bootstrap version (and API version) of xDS config. If empty, default version defined in Kuma CP will be used. (ex. '2', '3')")
cmd.PersistentFlags().StringVar(&bootstrapVersion, "bootstrap-version", "", "Bootstrap version (and API version) of xDS config. If empty, default version defined in Kuma CP will be used. (ex. '2', '3')")
_ = cmd.PersistentFlags().MarkDeprecated("bootstrap-version", "Envoy API v3 is used and can not be changed")
cmd.PersistentFlags().StringVar(&cfg.DataplaneRuntime.ConfigDir, "config-dir", cfg.DataplaneRuntime.ConfigDir, "Directory in which Envoy config will be generated")
cmd.PersistentFlags().StringVar(&cfg.DataplaneRuntime.TokenPath, "dataplane-token-file", cfg.DataplaneRuntime.TokenPath, "Path to a file with dataplane token (use 'kumactl generate dataplane-token' to get one)")
cmd.PersistentFlags().StringVar(&cfg.DataplaneRuntime.Token, "dataplane-token", cfg.DataplaneRuntime.Token, "Dataplane Token")
Expand Down
5 changes: 2 additions & 3 deletions app/kuma-dp/cmd/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
kuma_cmd "github.com/kumahq/kuma/pkg/cmd"
kumadp "github.com/kumahq/kuma/pkg/config/app/kuma-dp"
"github.com/kumahq/kuma/pkg/test"
"github.com/kumahq/kuma/pkg/xds/bootstrap/types"
)

var _ = Describe("run", func() {
Expand Down Expand Up @@ -95,10 +94,10 @@ var _ = Describe("run", func() {

// given
rootCtx := DefaultRootContext()
rootCtx.BootstrapGenerator = func(_ string, cfg kumadp.Config, _ envoy.BootstrapParams) ([]byte, types.BootstrapVersion, error) {
rootCtx.BootstrapGenerator = func(_ string, cfg kumadp.Config, _ envoy.BootstrapParams) ([]byte, error) {
respBytes, err := ioutil.ReadFile(filepath.Join("testdata", "bootstrap-config.golden.yaml"))
Expect(err).ToNot(HaveOccurred())
return respBytes, "", nil
return respBytes, nil
}
_, writer := io.Pipe()
cmd := NewRootCmd(opts, rootCtx)
Expand Down
30 changes: 12 additions & 18 deletions app/kuma-dp/pkg/dataplane/envoy/envoy.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,21 @@ import (
"github.com/kumahq/kuma/pkg/core/resources/model/rest"
"github.com/kumahq/kuma/pkg/core/runtime/component"
pkg_log "github.com/kumahq/kuma/pkg/log"
"github.com/kumahq/kuma/pkg/xds/bootstrap/types"
)

var (
runLog = core.Log.WithName("kuma-dp").WithName("run").WithName("envoy")
)

type BootstrapParams struct {
Dataplane *rest.Resource
BootstrapVersion types.BootstrapVersion
DNSPort uint32
EmptyDNSPort uint32
EnvoyVersion EnvoyVersion
DynamicMetadata map[string]string
Dataplane *rest.Resource
DNSPort uint32
EmptyDNSPort uint32
EnvoyVersion EnvoyVersion
DynamicMetadata map[string]string
}

type BootstrapConfigFactoryFunc func(url string, cfg kuma_dp.Config, params BootstrapParams) ([]byte, types.BootstrapVersion, error)
type BootstrapConfigFactoryFunc func(url string, cfg kuma_dp.Config, params BootstrapParams) ([]byte, error)

type Opts struct {
Config kuma_dp.Config
Expand Down Expand Up @@ -125,13 +123,12 @@ func (e *Envoy) Start(stop <-chan struct{}) error {
}
runLog.Info("fetched Envoy version", "version", envoyVersion)
runLog.Info("generating bootstrap configuration")
bootstrapConfig, version, err := e.opts.Generator(e.opts.Config.ControlPlane.URL, e.opts.Config, BootstrapParams{
Dataplane: e.opts.Dataplane,
BootstrapVersion: types.BootstrapVersion(e.opts.Config.Dataplane.BootstrapVersion),
DNSPort: e.opts.DNSPort,
EmptyDNSPort: e.opts.EmptyDNSPort,
EnvoyVersion: *envoyVersion,
DynamicMetadata: e.opts.DynamicMetadata,
bootstrapConfig, err := e.opts.Generator(e.opts.Config.ControlPlane.URL, e.opts.Config, BootstrapParams{
Dataplane: e.opts.Dataplane,
DNSPort: e.opts.DNSPort,
EmptyDNSPort: e.opts.EmptyDNSPort,
EnvoyVersion: *envoyVersion,
DynamicMetadata: e.opts.DynamicMetadata,
})
if err != nil {
return errors.Errorf("Failed to generate Envoy bootstrap config. %v", err)
Expand Down Expand Up @@ -166,9 +163,6 @@ func (e *Envoy) Start(stop <-chan struct{}) error {
"--disable-hot-restart",
"--log-level", e.opts.LogLevel.String(),
}
if version != "" { // version is always send by Kuma CP, but we check empty for backwards compatibility reasons (new Kuma DP connects to old Kuma CP)
args = append(args, "--bootstrap-version", string(version))
}

// If the concurrency is explicit, use that. On Linux, users
// can also implicitly set concurrency using cpusets.
Expand Down
23 changes: 11 additions & 12 deletions app/kuma-dp/pkg/dataplane/envoy/envoy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (

kuma_dp "github.com/kumahq/kuma/pkg/config/app/kuma-dp"
"github.com/kumahq/kuma/pkg/test"
"github.com/kumahq/kuma/pkg/xds/bootstrap/types"
)

var _ = Describe("Envoy", func() {
Expand Down Expand Up @@ -90,9 +89,9 @@ var _ = Describe("Envoy", func() {
ConfigDir: configDir,
},
}
sampleConfig := func(string, kuma_dp.Config, BootstrapParams) ([]byte, types.BootstrapVersion, error) {
sampleConfig := func(string, kuma_dp.Config, BootstrapParams) ([]byte, error) {
return []byte(`node:
id: example`), types.BootstrapV2, nil
id: example`), nil
}
expectedConfigFile := filepath.Join(configDir, "bootstrap.yaml")

Expand All @@ -119,12 +118,12 @@ var _ = Describe("Envoy", func() {
// and
if runtime.GOOS == "linux" {
Expect(strings.TrimSpace(buf.String())).To(Equal(
fmt.Sprintf("--config-path %s --drain-time-s 15 --disable-hot-restart --log-level off --bootstrap-version 2 --cpuset-threads",
fmt.Sprintf("--config-path %s --drain-time-s 15 --disable-hot-restart --log-level off --cpuset-threads",
expectedConfigFile)),
)
} else {
Expect(strings.TrimSpace(buf.String())).To(Equal(
fmt.Sprintf("--config-path %s --drain-time-s 15 --disable-hot-restart --log-level off --bootstrap-version 2",
fmt.Sprintf("--config-path %s --drain-time-s 15 --disable-hot-restart --log-level off",
expectedConfigFile)),
)
}
Expand Down Expand Up @@ -154,9 +153,9 @@ var _ = Describe("Envoy", func() {
},
}

sampleConfig := func(string, kuma_dp.Config, BootstrapParams) ([]byte, types.BootstrapVersion, error) {
sampleConfig := func(string, kuma_dp.Config, BootstrapParams) ([]byte, error) {
return []byte(`node:
id: example`), types.BootstrapV2, nil
id: example`), nil
}

expectedConfigFile := filepath.Join(configDir, "bootstrap.yaml")
Expand All @@ -183,7 +182,7 @@ var _ = Describe("Envoy", func() {
Expect(err).ToNot(HaveOccurred())
// and
Expect(strings.TrimSpace(buf.String())).To(Equal(
fmt.Sprintf("--config-path %s --drain-time-s 15 --disable-hot-restart --log-level off --bootstrap-version 2 --concurrency 9",
fmt.Sprintf("--config-path %s --drain-time-s 15 --disable-hot-restart --log-level off --concurrency 9",
expectedConfigFile)),
)
}))
Expand All @@ -196,8 +195,8 @@ var _ = Describe("Envoy", func() {
ConfigDir: configDir,
},
}
sampleConfig := func(string, kuma_dp.Config, BootstrapParams) ([]byte, types.BootstrapVersion, error) {
return nil, "", nil
sampleConfig := func(string, kuma_dp.Config, BootstrapParams) ([]byte, error) {
return nil, nil
}

By("starting a mock dataplane")
Expand Down Expand Up @@ -235,8 +234,8 @@ var _ = Describe("Envoy", func() {
ConfigDir: configDir,
},
}
sampleConfig := func(string, kuma_dp.Config, BootstrapParams) ([]byte, types.BootstrapVersion, error) {
return nil, "", nil
sampleConfig := func(string, kuma_dp.Config, BootstrapParams) ([]byte, error) {
return nil, nil
}

By("starting a mock dataplane")
Expand Down
41 changes: 20 additions & 21 deletions app/kuma-dp/pkg/dataplane/envoy/remote_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ func IsInvalidRequestErr(err error) bool {
return strings.HasPrefix(err.Error(), "Invalid request: ")
}

func (b *remoteBootstrap) Generate(url string, cfg kuma_dp.Config, params BootstrapParams) ([]byte, types.BootstrapVersion, error) {
func (b *remoteBootstrap) Generate(url string, cfg kuma_dp.Config, params BootstrapParams) ([]byte, error) {
bootstrapUrl, err := net_url.Parse(url)
if err != nil {
return nil, "", err
return nil, err
}

if bootstrapUrl.Scheme == "https" {
if cfg.ControlPlane.CaCert != "" {
certPool := x509.NewCertPool()
if ok := certPool.AppendCertsFromPEM([]byte(cfg.ControlPlane.CaCert)); !ok {
return nil, "", errors.New("could not add certificate")
return nil, errors.New("could not add certificate")
}
b.client.Transport = &http.Transport{
TLSClientConfig: &tls.Config{
Expand All @@ -66,14 +66,13 @@ func (b *remoteBootstrap) Generate(url string, cfg kuma_dp.Config, params Bootst

backoff, err := retry.NewConstant(cfg.ControlPlane.Retry.Backoff)
if err != nil {
return nil, "", errors.Wrap(err, "could not create retry backoff")
return nil, errors.Wrap(err, "could not create retry backoff")
}
backoff = retry.WithMaxDuration(cfg.ControlPlane.Retry.MaxDuration, backoff)
var respBytes []byte
var version types.BootstrapVersion
err = retry.Do(context.Background(), backoff, func(ctx context.Context) error {
log.Info("trying to fetch bootstrap configuration from the Control Plane")
respBytes, version, err = b.requestForBootstrap(bootstrapUrl, cfg, params)
respBytes, err = b.requestForBootstrap(bootstrapUrl, cfg, params)
if err == nil {
return nil
}
Expand All @@ -90,26 +89,26 @@ func (b *remoteBootstrap) Generate(url string, cfg kuma_dp.Config, params Bootst
return retry.RetryableError(err)
})
if err != nil {
return nil, "", err
return nil, err
}
return respBytes, version, nil
return respBytes, nil
}

func (b *remoteBootstrap) requestForBootstrap(url *net_url.URL, cfg kuma_dp.Config, params BootstrapParams) ([]byte, types.BootstrapVersion, error) {
func (b *remoteBootstrap) requestForBootstrap(url *net_url.URL, cfg kuma_dp.Config, params BootstrapParams) ([]byte, error) {
url.Path = "/bootstrap"
var dataplaneResource string
if params.Dataplane != nil {
dpJSON, err := json.Marshal(params.Dataplane)
if err != nil {
return nil, "", err
return nil, err
}
dataplaneResource = string(dpJSON)
}
token := ""
if cfg.DataplaneRuntime.TokenPath != "" {
tokenData, err := ioutil.ReadFile(cfg.DataplaneRuntime.TokenPath)
if err != nil {
return nil, "", err
return nil, err
}
token = string(tokenData)
}
Expand All @@ -125,7 +124,7 @@ func (b *remoteBootstrap) requestForBootstrap(url *net_url.URL, cfg kuma_dp.Conf
AdminPort: cfg.Dataplane.AdminPort.Lowest(),
DataplaneToken: token,
DataplaneResource: dataplaneResource,
BootstrapVersion: params.BootstrapVersion,
BootstrapVersion: types.BootstrapV3, // set BootstrapVersion to be compatible with old Kuma CPs
CaCert: cfg.ControlPlane.CaCert,
Version: types.Version{
KumaDp: types.KumaDpVersion{
Expand All @@ -145,32 +144,32 @@ func (b *remoteBootstrap) requestForBootstrap(url *net_url.URL, cfg kuma_dp.Conf
}
jsonBytes, err := json.Marshal(request)
if err != nil {
return nil, "", errors.Wrap(err, "could not marshal request to json")
return nil, errors.Wrap(err, "could not marshal request to json")
}
resp, err := b.client.Post(url.String(), "application/json", bytes.NewReader(jsonBytes))
if err != nil {
return nil, "", errors.Wrap(err, "request to bootstrap server failed")
return nil, errors.Wrap(err, "request to bootstrap server failed")
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, "", errors.Wrapf(err, "Unable to read the response with status code: %d. Make sure you are using https URL", resp.StatusCode)
return nil, errors.Wrapf(err, "Unable to read the response with status code: %d. Make sure you are using https URL", resp.StatusCode)
}
if resp.StatusCode == http.StatusNotFound && len(bodyBytes) == 0 {
return nil, "", DpNotFoundErr
return nil, DpNotFoundErr
}
if resp.StatusCode == http.StatusNotFound && string(bodyBytes) == "404: Page Not Found" { // response body of Go HTTP Server when hit for invalid endpoint
return nil, "", errors.New("There is no /bootstrap endpoint for provided CP address. Double check if the address passed to the CP has a DP Server port (5678 by default), not HTTP API (5681 by default)")
return nil, errors.New("There is no /bootstrap endpoint for provided CP address. Double check if the address passed to the CP has a DP Server port (5678 by default), not HTTP API (5681 by default)")
}
if resp.StatusCode/100 == 4 {
return nil, "", InvalidRequestErr(string(bodyBytes))
return nil, InvalidRequestErr(string(bodyBytes))
}
return nil, "", errors.Errorf("unexpected status code: %d", resp.StatusCode)
return nil, errors.Errorf("unexpected status code: %d", resp.StatusCode)
}
respBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, "", errors.Wrap(err, "could not read the body of the response")
return nil, errors.Wrap(err, "could not read the body of the response")
}
return respBytes, types.BootstrapVersion(resp.Header.Get(types.BootstrapVersionHeader)), nil
return respBytes, nil
}
Loading