Skip to content

Commit

Permalink
fix place where metrics service is scaffolded by moving from config/r…
Browse files Browse the repository at this point in the history
…bac to config/default
  • Loading branch information
camilamacedo86 committed May 23, 2024
1 parent b7ae59f commit 44d93e7
Show file tree
Hide file tree
Showing 95 changed files with 2,752 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func main() {
var secureMetrics bool
var enableHTTP2 bool
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metric endpoint binds to. "+
"Use the port :8080. If not set, it will be '0' in order to disable the metrics server")
"Use the port :8080. If not set, it will be '0 in order to disable the metrics server")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ patches:
#- path: manager_metrics_patch.yaml
# target:
# kind: Deployment
#- path:metrics_service.yaml

# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ resources:
- role_binding.yaml
- leader_election_role.yaml
- leader_election_role_binding.yaml
- metrics_service.yaml
# For each CRD, "Editor" and "Viewer" roles are scaffolded by
# default, aiding admins in cluster management. Those roles are
# not used by the Project itself. You can comment the following lines
Expand Down
2 changes: 1 addition & 1 deletion docs/book/src/getting-started/testdata/project/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func main() {
var secureMetrics bool
var enableHTTP2 bool
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metric endpoint binds to. "+
"Use the port :8080. If not set, it will be '0' in order to disable the metrics server")
"Use the port :8080. If not set, it will be '0 in order to disable the metrics server")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. "+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ patches:
#- path: manager_metrics_patch.yaml
# target:
# kind: Deployment
#- path:metrics_service.yaml

# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ resources:
- role_binding.yaml
- leader_election_role.yaml
- leader_election_role_binding.yaml
- metrics_service.yaml
# For each CRD, "Editor" and "Viewer" roles are scaffolded by
# default, aiding admins in cluster management. Those roles are
# not used by the Project itself. You can comment the following lines
Expand Down
1 change: 1 addition & 0 deletions docs/book/src/reference/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ in the file `config/default/kustomization.yaml`, see:
#- path: manager_metrics_patch.yaml
# target:
# kind: Deployment
#- path:metrics_service.yaml
```

Note that projects are scaffolded by default passing the flag `--metrics-bind-address=0`
Expand Down
2 changes: 1 addition & 1 deletion pkg/plugins/common/kustomize/v2/scaffolds/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s *initScaffolder) Scaffold() error {

templates := []machinery.Builder{
&rbac.Kustomization{},
&rbac.MetricsService{},
&kdefault.MetricsService{},
&rbac.RoleBinding{},
// We need to create a Role because if the project
// has not CRD define the controller-gen will not generate this file
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ patches:
#- path: manager_metrics_patch.yaml
# target:
# kind: Deployment
#- path:metrics_service.yaml
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
# crd/kustomization.yaml
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package rbac
package kdefault

import (
"path/filepath"
Expand All @@ -33,7 +33,7 @@ type MetricsService struct {
// SetTemplateDefaults implements file.Template
func (f *MetricsService) SetTemplateDefaults() error {
if f.Path == "" {
f.Path = filepath.Join("config", "rbac", "metrics_service.yaml")
f.Path = filepath.Join("config", "default", "metrics_service.yaml")
}

f.TemplateBody = metricsServiceTemplate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,4 @@ const kustomizeRBACTemplate = `resources:
- role_binding.yaml
- leader_election_role.yaml
- leader_election_role_binding.yaml
- metrics_service.yaml
`
2 changes: 1 addition & 1 deletion pkg/plugins/golang/v4/scaffolds/internal/templates/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func main() {
var secureMetrics bool
var enableHTTP2 bool
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metric endpoint binds to. " +
"Use the port :8080. If not set, it will be '0' in order to disable the metrics server")
"Use the port :8080. If not set, it will be '0 in order to disable the metrics server")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
"Enable leader election for controller manager. " +
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/v4/e2e-bjlp/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore build and test binaries.
bin/
27 changes: 27 additions & 0 deletions test/e2e/v4/e2e-bjlp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
bin/*
Dockerfile.cross

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Go workspace file
go.work

# Kubernetes Generated files - skip generated files, except for vendored files
!vendor/**/zz_generated.*

# editor and IDE paraphernalia
.idea
.vscode
*.swp
*.swo
*~
40 changes: 40 additions & 0 deletions test/e2e/v4/e2e-bjlp/.golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
run:
timeout: 5m
allow-parallel-runners: true

issues:
# don't skip warning about doc comments
# don't exclude the default set of lint
exclude-use-default: false
# restore some of the defaults
# (fill in the rest as needed)
exclude-rules:
- path: "api/*"
linters:
- lll
- path: "internal/*"
linters:
- dupl
- lll
linters:
disable-all: true
enable:
- dupl
- errcheck
- exportloopref
- goconst
- gocyclo
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- lll
- misspell
- nakedret
- prealloc
- staticcheck
- typecheck
- unconvert
- unparam
- unused
33 changes: 33 additions & 0 deletions test/e2e/v4/e2e-bjlp/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Build the manager binary
FROM golang:1.22 AS builder
ARG TARGETOS
ARG TARGETARCH

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

# Copy the go source
COPY cmd/main.go cmd/main.go
COPY api/ api/
COPY internal/controller/ internal/controller/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
# was called. For example, if we call make docker-build in a local env which has the Apple Silicon M1 SO
# the docker BUILDPLATFORM arg will be linux/arm64 when for Apple x86 it will be linux/amd64. Therefore,
# by leaving it empty we can ensure that the container and binary shipped on it will have the same platform.
RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
FROM gcr.io/distroless/static:nonroot
WORKDIR /
COPY --from=builder /workspace/manager .
USER 65532:65532

ENTRYPOINT ["/manager"]
Loading

0 comments on commit 44d93e7

Please sign in to comment.