Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 83
✨ 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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| 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"] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -209,22 +209,24 @@ export GO_BUILD_GCFLAGS ?= all=-trimpath=${PWD} | ||
| export GO_BUILD_TAGS ?= upstream | ||
| export GO_BUILD_FLAGS ?= | ||
| BUILDCMD = go build $(GO_BUILD_FLAGS) -tags '$(GO_BUILD_TAGS)' -ldflags '$(GO_BUILD_LDFLAGS)' -gcflags '$(GO_BUILD_GCFLAGS)' -asmflags '$(GO_BUILD_ASMFLAGS)' -o $(BUILDBIN)/manager ./cmd/manager | ||
| BINARIES=manager unpack | ||
| $(BINARIES): | ||
| go build $(GO_BUILD_FLAGS) -tags '$(GO_BUILD_TAGS)' -ldflags '$(GO_BUILD_LDFLAGS)' -gcflags '$(GO_BUILD_GCFLAGS)' -asmflags '$(GO_BUILD_ASMFLAGS)' -o $(BUILDBIN)/$@ ./cmd/$@ | ||
| .PHONY: build-deps | ||
| build-deps: manifests generate fmt vet | ||
| .PHONY: build go-build-local | ||
| build: build-deps go-build-local #HELP Build manager binary for current GOOS and GOARCH. Default target. | ||
| go-build-local: BUILDBIN = bin | ||
| go-build-local: | ||
| $(BUILDCMD) | ||
| go-build-local: $(BINARIES) | ||
| .PHONY: build-linux go-build-linux | ||
| build-linux: build-deps go-build-linux #EXHELP Build manager binary for GOOS=linux and local GOARCH. | ||
| go-build-linux: BUILDBIN = bin/linux | ||
| go-build-linux: | ||
| GOOS=linux $(BUILDCMD) | ||
| go-build-linux: GOOS=linux | ||
| go-build-linux: $(BINARIES) | ||
varshaprasad96 marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| .PHONY: run | ||
| run: docker-build kind-cluster kind-load kind-deploy #HELP Build the operator-controller then deploy it into a new kind cluster. | ||
| 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) | ||
| } | ||
| } |
| 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 | ||
Uh oh!
There was an error while loading. Please reload this page.