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

Extract http flags from consul/command pkg #259

Merged
merged 2 commits into from
Jul 7, 2020
Merged

Conversation

lkysow
Copy link
Member

@lkysow lkysow commented May 7, 2020

Extract flags from consul/command into our own package: subcommand/flags. Remove the flags we weren't using, that leaves:

  • -http-addr
    • Not used anywhere but we use CONSUL_HTTP_ADDR everywhere so this flag matches. We do use it in our tests.
  • -token
    • Not used anywhere but we use CONSUL_HTTP_TOKEN in a lot of locations so this flag matches.
  • -token-file
    • Used in mesh gateways and lifecycle sidecars
  • -ca-file
    • Used by get-auto-encrypt-ca command. CONSUL_CACERT is used by almost all of our components.
  • -ca-path
    • This isn't used by anything currently but I can see us needing this in the future to support intermediate certs.
  • -tls-server-name
    • Used by get-auto-encrypt-ca

Testing: Use lkysow/consul-k8s-dev:may27-flags. Test with all of our components, they'll crash if a flag isn't supported. Note, I've tested this myself.

global:
  imageK8S: lkysow/consul-k8s-dev:may27-flags
  image: consul:beta
  name: consul
  tls:
    enabled: true
    autoEncryptEnabled: true
  federation:
    enabled: true
  acls:
    manageSystemACLs: true
connectInject:
  enabled: true
syncCatalog:
  enabled: true
meshGateway:
  enabled: true

@lkysow
Copy link
Member Author

lkysow commented May 7, 2020

@hashicorp/consul-eco-platform this is a draft of what it looks like to remove our dependency on consul/command.

@lkysow lkysow requested a review from a team May 27, 2020 17:26
@lkysow lkysow marked this pull request as ready for review May 27, 2020 17:26
@adilyse adilyse added the area/infrastructure Related to builds, tests, dependencies, etc. of consul-k8s label Jun 24, 2020
Copy link
Contributor

@ishustava ishustava left a comment

Choose a reason for hiding this comment

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

Sorry for taking so long to review this, Luke!

This looks really good! I left a couple of comments/questions inline.

go.mod Show resolved Hide resolved
// This was done so we don't depend on internal Consul implementation.

// DurationValue provides a flag value that's aware if it has been set.
type DurationValue struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

This type is currently only used by the sync-catalog command. I've also found that you could just use time.Duration and the flags would parse correctly (see this example in the lifecycle-sidecar command). I'm wondering if we can replace the type of the flagConsulWritePeriod with time.Duration, then maybe we don't need this at all?

I have tried it out quickly, and it seems to be working (branch). This I think would also be fine to refactor afterward as it seems like it's expanding the scope of this task.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's fine to include, thanks for doing the leg work. Done.


// FlagMapValue is a flag implementation used to provide key=value semantics
// multiple times.
type FlagMapValue map[string]string
Copy link
Contributor

Choose a reason for hiding this comment

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

I couldn't find how this type is used?

Copy link
Member Author

Choose a reason for hiding this comment

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

removed


import "strings"

// Taken from https://github.com/hashicorp/consul/blob/master/command/flags/flag_slice_value.go
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you make all the links tied to a specific git sha? If this code is moved or deleted, then we'd lose this reference.

Copy link
Member Author

Choose a reason for hiding this comment

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

good call, done!

subcommand/flags/http.go Show resolved Hide resolved
"io"
"strings"

text "github.com/kr/text"
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to alias it?

Copy link
Member Author

Choose a reason for hiding this comment

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

no, was just copied. removed.

Flags *flag.FlagSet
}

func (u *Usager) String() string {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to test this 😬 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added a test!

Copy link
Contributor

Choose a reason for hiding this comment

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

🙏

This decouples us from an internal Consul package. We've removed flags
that we aren't using.
Copy link
Contributor

@ishustava ishustava left a comment

Choose a reason for hiding this comment

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

Looks good!! thanks so much for making the changes 🎉

go.mod Show resolved Hide resolved
Flags *flag.FlagSet
}

func (u *Usager) String() string {
Copy link
Contributor

Choose a reason for hiding this comment

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

🙏

@lkysow lkysow merged commit a520d4c into master Jul 7, 2020
@lkysow lkysow deleted the generate-fed-secret branch July 7, 2020 22:53
ndhanushkodi pushed a commit to ndhanushkodi/consul-k8s that referenced this pull request Jul 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/infrastructure Related to builds, tests, dependencies, etc. of consul-k8s
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants