-
Notifications
You must be signed in to change notification settings - Fork 68
✨ Helm poc unpack image #811
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
tmshort
merged 1 commit into
operator-framework:helm-poc
from
dtfranz:helm-poc_unpack-image
May 6, 2024
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,21 @@ | ||
| # Note: This dockerfile does not build the binaries | ||
| # required and is intended to be built only with the | ||
| # 'make build' or 'make release' targets. | ||
| # Stage 1: | ||
| FROM gcr.io/distroless/static:debug-nonroot AS builder | ||
|
|
||
| # Stage 2: | ||
| FROM gcr.io/distroless/static:nonroot | ||
|
|
||
| # Grab the cp binary so we can cp the unpack | ||
| # binary to a shared volume in the bundle image | ||
| COPY --from=builder /busybox/cp /cp | ||
|
|
||
| WORKDIR / | ||
|
|
||
| COPY manager manager | ||
| COPY unpack unpack | ||
|
|
||
| EXPOSE 8080 | ||
|
|
||
| USER 65532:65532 | ||
|
|
||
| ENTRYPOINT ["/manager"] | ||
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,121 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "archive/tar" | ||
| "bytes" | ||
| "compress/gzip" | ||
| "encoding/json" | ||
| "fmt" | ||
| "io" | ||
| "io/fs" | ||
| "log" | ||
| "os" | ||
| "path/filepath" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| "k8s.io/apimachinery/pkg/util/sets" | ||
| ) | ||
|
|
||
| func main() { | ||
| var bundleDir string | ||
| var opConVersion bool | ||
|
|
||
| skipRootPaths := sets.NewString( | ||
| "/dev", | ||
| "/etc", | ||
| "/proc", | ||
| "/product_name", | ||
| "/product_uuid", | ||
| "/sys", | ||
| "/bin", | ||
| ) | ||
| cmd := &cobra.Command{ | ||
| Use: "unpack", | ||
| Args: cobra.ExactArgs(0), | ||
| RunE: func(cmd *cobra.Command, _ []string) error { | ||
| if opConVersion { | ||
| // TODO | ||
| //fmt.Println(version.String()) | ||
| os.Exit(0) | ||
| } | ||
| var err error | ||
| bundleDir, err = filepath.Abs(bundleDir) | ||
| if err != nil { | ||
| log.Fatalf("get absolute path of bundle directory %q: %v", bundleDir, err) | ||
| } | ||
|
|
||
| bundleFS := os.DirFS(bundleDir) | ||
| buf := &bytes.Buffer{} | ||
| gzw := gzip.NewWriter(buf) | ||
| tw := tar.NewWriter(gzw) | ||
| if err := fs.WalkDir(bundleFS, ".", func(path string, d fs.DirEntry, err error) error { | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if d.Type()&os.ModeSymlink != 0 { | ||
| return nil | ||
| } | ||
| if bundleDir == "/" { | ||
| // If bundleDir is the filesystem root, skip some known unrelated directories | ||
| fullPath := filepath.Join(bundleDir, path) | ||
| if skipRootPaths.Has(fullPath) { | ||
| return filepath.SkipDir | ||
| } | ||
| } | ||
| info, err := d.Info() | ||
| if err != nil { | ||
| return fmt.Errorf("get file info for %q: %v", path, err) | ||
| } | ||
|
|
||
| h, err := tar.FileInfoHeader(info, "") | ||
| if err != nil { | ||
| return fmt.Errorf("build tar file info header for %q: %v", path, err) | ||
| } | ||
| h.Uid = 0 | ||
| h.Gid = 0 | ||
| h.Uname = "" | ||
| h.Gname = "" | ||
| h.Name = path | ||
|
|
||
| if err := tw.WriteHeader(h); err != nil { | ||
| return fmt.Errorf("write tar header for %q: %v", path, err) | ||
| } | ||
| if d.IsDir() { | ||
| return nil | ||
| } | ||
| f, err := bundleFS.Open(path) | ||
| if err != nil { | ||
| return fmt.Errorf("open file %q: %v", path, err) | ||
| } | ||
| if _, err := io.Copy(tw, f); err != nil { | ||
| return fmt.Errorf("write tar data for %q: %v", path, err) | ||
| } | ||
| return nil | ||
| }); err != nil { | ||
| log.Fatalf("generate tar.gz for bundle dir %q: %v", bundleDir, err) | ||
| } | ||
| if err := tw.Close(); err != nil { | ||
| log.Fatal(err) | ||
| } | ||
| if err := gzw.Close(); err != nil { | ||
| log.Fatal(err) | ||
| } | ||
|
|
||
| bundleMap := map[string]interface{}{ | ||
| "content": buf.Bytes(), | ||
| } | ||
| enc := json.NewEncoder(os.Stdout) | ||
| if err := enc.Encode(bundleMap); err != nil { | ||
| log.Fatalf("encode bundle map as JSON: %v", err) | ||
| } | ||
| return nil | ||
| }, | ||
| } | ||
| cmd.Flags().StringVar(&bundleDir, "bundle-dir", "", "directory in which the bundle can be found") | ||
| cmd.Flags().BoolVar(&opConVersion, "version", false, "displays operator-controller version information") | ||
|
|
||
| if err := cmd.Execute(); err != nil { | ||
| log.Fatal(err) | ||
| } | ||
| } |
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 |
|---|---|---|
|
|
@@ -6,3 +6,23 @@ images: | |
| - name: controller | ||
| newName: quay.io/operator-framework/operator-controller | ||
| newTag: devel | ||
| replacements: | ||
|
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. This is nice! I think in rukpak we had to manually edit the image in manager. |
||
| - source: # replaces UNPACK_IMAGE in manager.yaml with image set by kustomize above | ||
| kind: Deployment | ||
| group: apps | ||
| version: v1 | ||
| name: controller-manager | ||
| namespace: system | ||
| fieldPath: spec.template.spec.containers.[name=manager].image | ||
| targets: | ||
| - select: | ||
| kind: Deployment | ||
| group: apps | ||
| version: v1 | ||
| name: controller-manager | ||
| namespace: system | ||
| fieldPaths: | ||
| - spec.template.spec.containers.[name=manager].args.0 | ||
| options: | ||
| delimiter: "=" | ||
| index: 1 | ||
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
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.