-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat: add images manifest command #133
Conversation
Version version.Cmd `cmd:"" help:"Display version information."` | ||
Verbose verbose `short:"v" help:"Enable verbose output."` | ||
} | ||
|
||
func (c *Cmd) BeforeApply(ctx *kong.Context) error { | ||
if _, envVarDNT := os.LookupEnv("DO_NOT_TRACK"); envVarDNT { | ||
pterm.Info.Println("Telemetry collection disabled (DO_NOT_TRACK)") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This moved to the local
command, so that it doesn't print at the top of commands like images manifest
which aren't related to telemetry.
t.Fatal(err) | ||
} | ||
} | ||
|
||
func TestCommand_Install_HelmValues(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After refactoring the building of InstallOpts
, this test became a dupe of TestCommand_Install
because Install()
doesn't build any values YAML now, it receives the fully formed values YAML from the caller.
@@ -148,6 +170,10 @@ func (i *InstallCmd) Run(ctx context.Context, provider k8s.Provider, telClient t | |||
} | |||
|
|||
func parseVolumeMounts(specs []string) ([]k8s.ExtraVolumeMount, error) { | |||
if len(specs) == 0 { | |||
return nil, nil | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows tests to pass easily with zero-value struct fields, because the code below uses make
which doesn't return a nil slice when there are no volume mounts.
kong.Description("Airbyte's command line tool for managing a local Airbyte installation."), | ||
kong.UsageOnError(), | ||
) | ||
_, err := k.Parse([]string{"--values", "/testdata/thisfiledoesnotexist"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code is relying on Kong's existingfile
validation now, instead of having a manual check (for better or worse)
@@ -43,7 +42,7 @@ type Client interface { | |||
// Attr should be called to add additional attributes to this activity. | |||
Attr(key, val string) | |||
// User returns the user identifier being used by this client | |||
User() uuid.UUID | |||
User() string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As noted in the PR description, having User()
return a string simplifies some test code slightly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you expand on exactly how this simplifies the test code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go.mod
Outdated
@@ -14,13 +14,14 @@ require ( | |||
github.com/opencontainers/image-spec v1.1.0-rc6 | |||
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 | |||
github.com/pterm/pterm v0.12.79 | |||
github.com/stretchr/testify v1.8.4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we communicate this to the rest of the team.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@colesnodgrass @perangel I used testify/assert to assert a list of values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been avoiding using the testify package as I don't think it's necessary for most situations, and it feels a little overkill to bring it in for one function.
Most of the code in abctl
uses the cmp
package and we can easily use that package for verifying the two lists match
func compareList(t *testing.T, expect, actual []string) {
t.Helper()
sort.Strings(expect)
sort.Strings(actual)
if d := cmp.Diff(expect, actual); d != "" {
t.Error(d)
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really causing any trouble? It's handy and popular.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I'm personally not a huge fan of testify (I also haven't looked at in in years, so maybe it is worth taking another look with older eyes). If everyone else wants to start using it, I'll be fine with that. I care mostly about simplicity and consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we foresee adding other sub-commands under the images
command? In other words, do we need two levels here (abctl images manifest
) or should we collapse this into a single new images
command (abctl images
)?
internal/cmd/images/manifest_cmd.go
Outdated
|
||
type ManifestCmd struct { | ||
Chart string `help:"Path to chart." xor:"chartver"` | ||
ChartVersion string `help:"Version to install." xor:"chartver"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The help
comment seems incorrect, as this isn't being installed by this command.
internal/cmd/images/manifest_cmd.go
Outdated
// It returns a unique, sorted list of images found. | ||
func findAllImages(chartYaml string) []string { | ||
objs := decodeK8sResources(chartYaml) | ||
imageSet := map[string]bool{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use map[string]struct{}{}
as the bool
value isn't being used for anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer bool because it's shorter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get the shorter argument. In this specific case I'm ok with the bool
approach. However, in general, for faux-set implementations I still prefer the struct{}
approach as there is never a question of "What if I set this bool value to false
, does the code behave differently?"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I do wish Go would add a container/set package. I wrote a small one in the code to replace the map[string]bool
@@ -43,7 +42,7 @@ type Client interface { | |||
// Attr should be called to add additional attributes to this activity. | |||
Attr(key, val string) | |||
// User returns the user identifier being used by this client | |||
User() uuid.UUID | |||
User() string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you expand on exactly how this simplifies the test code?
In can imagine a command that does the copying of images from our repo to the customers private repository. |
This makes sense. Should this be |
https://github.com/airbytehq/airbyte-internal-issues/issues/10018
This adds
abctl images manifest
which prints a list of container images used by the Airbyte platform.It takes
--chart
,--chart-version
, and--values
flags (similar tolocal install
) which can affect the outcome. For example, if you'revalues.yaml
configures the enterprise edition, the image manifest will include keycloak and any other enterprise-specific images.I needed to refactor some code in order to share Helm functions between the
install
andimages
commands. In particular, I've pulled a lot of Helm values building up intoBuildAirbyteValues
andInstallCmd.InstallOpts()
. I also pulled some shared contants into a newcommon
package.I deduped the
mockTelemetryClient
intotelemetry.MockClient
and simplified it a bit, so the test code using this is simpler. I refactoredtelemetry.Client.User() UUID
totelemetry.Client.User() string
(segment still uses a UUID behind the scenes of course, it's just not exposed in the Go interface anymore).Testing the manifest command involves pulling down actual charts (1.1.0 and a recent nightly version). This is somewhat lame, but without this the test wouldn't actually test much.