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

feat: add version command #3379

Merged
merged 2 commits into from
Jan 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ Adding a new version? You'll need three changes:
if the controlled objects succeeded or failed to be translated to Kong
configuration.
[#3359](https://github.com/Kong/kubernetes-ingress-controller/pull/3359)
- Added `version` command
[#3379](https://github.com/Kong/kubernetes-ingress-controller/pull/3379)

### Fixed

Expand Down
12 changes: 6 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ RUN go mod download

COPY pkg/ pkg/
COPY internal/ internal/
COPY Makefile .

# Build
ARG TAG
ARG COMMIT
ARG REPO_INFO

RUN CGO_ENABLED=0 GOOS=linux GOARCH="${TARGETARCH}" GO111MODULE=on go build -a -o manager -ldflags "-s -w -X github.com/kong/kubernetes-ingress-controller/v2/internal/manager/metadata.Release=$TAG -X github.com/kong/kubernetes-ingress-controller/v2/internal/manager/metadata.Commit=$COMMIT -X github.com/kong/kubernetes-ingress-controller/v2/internal/manager/metadata.Repo=$REPO_INFO" ./internal/cmd/main.go

RUN CGO_ENABLED=0 GOOS=linux GOARCH="${TARGETARCH}" GO111MODULE=on make _build

### FIPS 140-2 binary
# Build the manager binary
Expand Down Expand Up @@ -62,7 +62,7 @@ ARG TAG
ARG COMMIT
ARG REPO_INFO

RUN CGO_ENABLED=0 GOOS=linux GOARCH="${TARGETARCH}" GO111MODULE=on go build -a -o manager -ldflags "-s -w -X github.com/kong/kubernetes-ingress-controller/v2/internal/manager/metadata.Release=$TAG -X github.com/kong/kubernetes-ingress-controller/v2/internal/manager/metadata.Commit=$COMMIT -X github.com/kong/kubernetes-ingress-controller/v2/internal/manager/metadata.Repo=$REPO_INFO" ./internal/cmd/fips/main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH="${TARGETARCH}" GO111MODULE=on make _build.fips

# Build a manager binary with debug symbols and download Delve
FROM builder as builder-delve
Expand All @@ -71,7 +71,7 @@ ARG TARGETPLATFORM
ARG TARGETOS
ARG TARGETARCH

RUN CGO_ENABLED=0 GOOS=linux GOARCH="${TARGETARCH}" GO111MODULE=on go build -a -o manager-debug -gcflags=all="-N -l" -ldflags "-X github.com/kong/kubernetes-ingress-controller/v2/internal/manager/metadata.Release=$TAG -X github.com/kong/kubernetes-ingress-controller/v2/internal/manager/metadata.Commit=$COMMIT -X github.com/kong/kubernetes-ingress-controller/v2/internal/manager/metadata.Repo=$REPO_INFO" ./internal/cmd/main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH="${TARGETARCH}" GO111MODULE=on make _build.debug

### Debug
# Create an image that runs a debug build with a Delve remote server on port 2345
Expand Down Expand Up @@ -105,7 +105,7 @@ LABEL name="Kong Ingress Controller" \
RUN groupadd --system kic && \
adduser --system kic -g kic -u 1000

COPY --from=builder /workspace/manager .
COPY --from=builder /workspace/bin/manager .
COPY LICENSE /licenses/
COPY LICENSES /licenses/

Expand Down Expand Up @@ -171,7 +171,7 @@ LABEL name="Kong Ingress Controller" \
description="Use Kong for Kubernetes Ingress. Configure plugins, health checking, load balancing and more in Kong for Kubernetes Services, all using Custom Resource Definitions (CRDs) and Kubernetes-native tooling."

WORKDIR /
COPY --from=builder /workspace/manager .
COPY --from=builder /workspace/bin/manager .
USER 65532:65532

ENTRYPOINT ["/manager"]
39 changes: 32 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,36 @@ clean:
@rm -f coverage*.out

.PHONY: build
build: generate fmt vet lint
go build -a -o bin/manager -ldflags "-s -w \
-X $(REPO_URL)/v2/internal/metadata.Release=$(TAG) \
-X $(REPO_URL)/v2/internal/metadata.Commit=$(COMMIT) \
-X $(REPO_URL)/v2/internal/metadata.Repo=$(REPO_INFO)" internal/cmd/main.go
build: generate fmt vet lint _build

.PHONY: build.fips
build.fips: generate fmt vet lint _build.fips

.PHONY: _build
_build:
$(MAKE) _build.template MAIN=./internal/cmd/main.go

.PHONY: _build.fips
_build.fips:
$(MAKE) _build.template MAIN=./internal/cmd/fips/main.go

.PHONY: _build.template
_build.template:
go build -o bin/manager -ldflags "-s -w \
-X $(REPO_URL)/v2/internal/manager/metadata.Release=$(TAG) \
-X $(REPO_URL)/v2/internal/manager/metadata.Commit=$(COMMIT) \
-X $(REPO_URL)/v2/internal/manager/metadata.Repo=$(REPO_INFO)" ${MAIN}

.PHONY: _build.debug
_build.debug:
$(MAKE) _build.template.debug MAIN=./internal/cmd/main.go

.PHONY: _build.template.debug
_build.template.debug:
go build -o bin/manager-debug -gcflags=all="-N -l" -ldflags " \
-X $(REPO_URL)/v2/internal/manager/metadata.Release=$(TAG) \
-X $(REPO_URL)/v2/internal/manager/metadata.Commit=$(COMMIT) \
-X $(REPO_URL)/v2/internal/manager/metadata.Repo=$(REPO_INFO)" ${MAIN}

.PHONY: fmt
fmt:
Expand Down Expand Up @@ -229,8 +254,8 @@ container:
--build-arg REPO_INFO=${REPO_INFO} \
-t ${IMAGE}:${TAG} .

.PHONY: container
debug-container:
.PHONY: container.debug
container.debug:
docker buildx build \
-f Dockerfile \
--target debug \
Expand Down
26 changes: 26 additions & 0 deletions internal/cmd/rootcmd/rootcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@
package rootcmd

import (
"encoding/json"
"fmt"

"github.com/spf13/cobra"

"github.com/kong/kubernetes-ingress-controller/v2/internal/manager"
"github.com/kong/kubernetes-ingress-controller/v2/internal/manager/metadata"
)

// Execute is the entry point to the controller manager.
Expand All @@ -18,7 +22,29 @@ func Execute() {
},
SilenceUsage: true,
}
versionCmd = &cobra.Command{
Use: "version",
Short: "Show JSON version information",
RunE: func(cmd *cobra.Command, args []string) error {
type Version struct {
Release string `json:"release"`
Repo string `json:"repo"`
Commit string `json:"commit"`
}
out, err := json.Marshal(Version{
Release: metadata.Release,
Repo: metadata.Repo,
Commit: metadata.Commit,
})
if err != nil {
return fmt.Errorf("failed to print version information: %w", err)
}
fmt.Printf("%s\n", out)
return nil
},
}
)
rootCmd.AddCommand(versionCmd)
rootCmd.Flags().AddFlagSet(cfg.FlagSet())
cobra.CheckErr(rootCmd.Execute())
}
14 changes: 7 additions & 7 deletions internal/manager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,15 @@ func (c *Config) FlagSet() *pflag.FlagSet {
flagSet.StringSliceVar(&c.FilterTags, "kong-admin-filter-tag", []string{"managed-by-ingress-controller"}, "The tag used to manage and filter entities in Kong. This flag can be specified multiple times to specify multiple tags. This setting will be silently ignored if the Kong instance has no tags support.")
flagSet.IntVar(&c.Concurrency, "kong-admin-concurrency", 10, "Max number of concurrent requests sent to Kong's Admin API.")
flagSet.StringSliceVar(&c.WatchNamespaces, "watch-namespace", nil,
`Namespace(s) to watch for Kubernetes resources. Defaults to all namespaces. To watch multiple namespaces, use
a comma-separated list of namespaces.`)
`Namespace(s) to watch for Kubernetes resources. Defaults to all namespaces.`+
`To watch multiple namespaces, use a comma-separated list of namespaces.`)

// Ingress status
flagSet.StringVar(&c.PublishService, "publish-service", "", `Service fronting Ingress resources in "namespace/name"
format. The controller will update Ingress status information with this Service's endpoints.`)
flagSet.StringSliceVar(&c.PublishStatusAddress, "publish-status-address", []string{}, `User-provided addresses in
comma-separated string format, for use in lieu of "publish-service" when that Service lacks useful address
information (for example, in bare-metal environments).`)
flagSet.StringVar(&c.PublishService, "publish-service", "",
`Service fronting Ingress resources in "namespace/name" format. The controller will update Ingress status information with this Service's endpoints.`)
flagSet.StringSliceVar(&c.PublishStatusAddress, "publish-status-address", []string{},
`User-provided addresses in comma-separated string format, for use in lieu of "publish-service" `+
`when that Service lacks useful address information (for example, in bare-metal environments).`)
flagSet.BoolVar(&c.UpdateStatus, "update-status", true,
`Indicates if the ingress controller should update the status of resources (e.g. IP/Hostname for v1.Ingress, e.t.c.)`)

Expand Down