-
Notifications
You must be signed in to change notification settings - Fork 260
Add dropgz module for CNI installer #1335
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
408ca3b
dropgz: self extracting gz installer and cni dropper dockerfile
rbtr a231c05
update integration test for new container name
rbtr 00ea311
add compound closer and address other review feedback
rbtr a739d51
address review comments
rbtr 7d4f324
write files as 755
rbtr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| FROM mcr.microsoft.com/oss/go/microsoft/golang:1.18 AS azure-vnet | ||
| ARG VERSION | ||
| WORKDIR /azure-container-networking | ||
| COPY . . | ||
| RUN CGO_ENABLED=0 go build -a -o bin/azure-vnet -trimpath -ldflags "-X main.version="$VERSION"" -gcflags="-dwarflocationlists=true" cni/network/plugin/main.go | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. build with aimetadata? |
||
|
|
||
| FROM mcr.microsoft.com/cbl-mariner/base/core:2.0 AS compressor | ||
| WORKDIR /dropgz | ||
| COPY dropgz . | ||
| COPY --from=azure-vnet /azure-container-networking/bin/* pkg/embed/fs | ||
| COPY --from=azure-vnet /azure-container-networking/cni/*.conflist pkg/embed/fs | ||
| RUN cd pkg/embed/fs/ && sha256sum * > sum.txt | ||
| RUN gzip --verbose --best --recursive pkg/embed/fs && for f in pkg/embed/fs/*.gz; do mv -- "$f" "${f%%.gz}"; done | ||
|
|
||
| FROM mcr.microsoft.com/oss/go/microsoft/golang:1.18 AS dropgz | ||
| ARG VERSION | ||
| WORKDIR /dropgz | ||
| COPY --from=compressor /dropgz . | ||
| RUN CGO_ENABLED=0 go build -a -o bin/dropgz -trimpath -ldflags "-X github.com/Azure/azure-container-networking/dropgz/internal/buildinfo.Version="$VERSION"" -gcflags="-dwarflocationlists=true" main.go | ||
|
|
||
| FROM scratch | ||
| COPY --from=dropgz /dropgz/bin/dropgz /dropgz | ||
| ENTRYPOINT [ "/dropgz" ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/Azure/azure-container-networking/dropgz/pkg/embed" | ||
| "github.com/Azure/azure-container-networking/dropgz/pkg/hash" | ||
| "github.com/pkg/errors" | ||
| "github.com/spf13/cobra" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| // list subcommand | ||
| var list = &cobra.Command{ | ||
| Use: "list", | ||
| RunE: func(*cobra.Command, []string) error { | ||
| if err := setLogLevel(); err != nil { | ||
| return err | ||
| } | ||
| contents, err := embed.Contents() | ||
| if err != nil { | ||
| return err | ||
| } | ||
| for _, c := range contents { | ||
| fmt.Printf("\t%s\n", c) | ||
| } | ||
| return nil | ||
| }, | ||
| } | ||
|
|
||
| func checksum(srcs, dests []string) error { | ||
| if len(srcs) != len(dests) { | ||
| return errors.Wrapf(embed.ErrArgsMismatched, "%d and %d", len(srcs), len(dests)) | ||
| } | ||
| rc, err := embed.Extract("sum.txt") | ||
| if err != nil { | ||
| return errors.Wrap(err, "failed to extract checksum file") | ||
| } | ||
| defer rc.Close() | ||
|
|
||
| checksums, err := hash.Parse(rc) | ||
| if err != nil { | ||
| return errors.Wrap(err, "failed to parse checksums") | ||
| } | ||
| for i := range srcs { | ||
| valid, err := checksums.Check(srcs[i], dests[i]) | ||
| if err != nil { | ||
| return errors.Wrapf(err, "failed to validate file at %s", dests[i]) | ||
| } | ||
| if !valid { | ||
| return errors.Errorf("%s checksum validation failed", dests[i]) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| var ( | ||
| skipVerify bool | ||
| outs []string | ||
|
Comment on lines
+58
to
+59
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be helpful to document that these are flags... it took me a second or two to figure out why they were globals |
||
| ) | ||
|
|
||
| // deploy subcommand | ||
| var deploy = &cobra.Command{ | ||
| Use: "deploy", | ||
| RunE: func(_ *cobra.Command, srcs []string) error { | ||
| if err := setLogLevel(); err != nil { | ||
| return err | ||
| } | ||
| if len(outs) == 0 { | ||
| outs = srcs | ||
| } | ||
| if len(srcs) != len(outs) { | ||
| return errors.Wrapf(embed.ErrArgsMismatched, "%d files, %d outputs", len(srcs), len(outs)) | ||
| } | ||
| log := z.With(zap.Strings("sources", srcs), zap.Strings("outputs", outs), zap.String("cmd", "deploy")) | ||
| if err := embed.Deploy(log, srcs, outs); err != nil { | ||
| return errors.Wrapf(err, "failed to deploy %s", srcs) | ||
| } | ||
| log.Info("successfully wrote files") | ||
| if skipVerify { | ||
| return nil | ||
| } | ||
| if err := checksum(srcs, outs); err != nil { | ||
| return err | ||
| } | ||
| log.Info("verified file integrity") | ||
| return nil | ||
| }, | ||
| Args: cobra.OnlyValidArgs, | ||
| } | ||
|
|
||
| // verify subcommand | ||
| var verify = &cobra.Command{ | ||
| Use: "verify", | ||
| RunE: func(_ *cobra.Command, srcs []string) error { | ||
| if err := setLogLevel(); err != nil { | ||
| return err | ||
| } | ||
| if len(outs) == 0 { | ||
| outs = srcs | ||
| } | ||
| if len(srcs) != len(outs) { | ||
| return errors.Wrapf(embed.ErrArgsMismatched, "%d sources, %d destinations", len(srcs), len(outs)) | ||
| } | ||
| log := z.With(zap.Strings("sources", srcs), zap.Strings("outputs", outs), zap.String("cmd", "verify")) | ||
| if err := checksum(srcs, outs); err != nil { | ||
| return err | ||
| } | ||
| log.Info("verified files") | ||
| return nil | ||
| }, | ||
| Args: cobra.OnlyValidArgs, | ||
| } | ||
|
|
||
| func init() { | ||
| root.AddCommand(list) | ||
|
|
||
| verify.ValidArgs, _ = embed.Contents() | ||
| verify.Flags().StringSliceVarP(&outs, "output", "o", []string{}, "output file path") | ||
| root.AddCommand(verify) | ||
|
|
||
| deploy.ValidArgs, _ = embed.Contents() // setting this after the command is initialized is required | ||
| deploy.Flags().BoolVar(&skipVerify, "skip-verify", false, "set to disable checksum validation") | ||
| deploy.Flags().StringSliceVarP(&outs, "output", "o", []string{}, "output file path") | ||
| root.AddCommand(deploy) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.