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

Upgrade dependencies, go version, controller-runtime, controller-gen #63

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 1 addition & 5 deletions .github/workflows/unit_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: 1.19
go-version: 1.21

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Setup kubebuilder
run: |
make kubebuilder

- name: Build
run: |
make build
Expand Down
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.19 as builder
FROM golang:1.21 as builder

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -10,14 +10,13 @@ COPY go.sum go.sum
RUN go mod download

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

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o manager main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -v -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
Expand Down
50 changes: 34 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,28 @@
# Image URL to use all building/pushing image targets
IMG ?= keikoproj/alert-manager:latest
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true,preserveUnknownFields=false"
CRD_OPTIONS ?= "crd"

# Tools required to run the full suite of tests properly
OSNAME ?= $(shell uname -s | tr A-Z a-z)
KUBEBUILDER_VER ?= 3.0.0
KUBEBUILDER_ARCH ?= amd64
ENVTEST_K8S_VERSION = 1.28.0

LOCAL ?= true
KUBECONFIG ?= $(HOME)/.kube/config
LOCAL ?= true
RESTRICTED_POLICY_RESOURCES ?= policy-resource
RESTRICTED_S3_RESOURCES ?= s3-resource
AWS_ACCOUNT_ID ?= 123456789012
AWS_REGION ?= us-west-2
CLUSTER_NAME ?= k8s_test_keiko
CLUSTER_OIDC_ISSUER_URL ?= https://google.com/OIDC

LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

ENVTEST ?= $(LOCALBIN)/setup-envtest

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -64,18 +78,25 @@ mock:
done

ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
test: mock manifests generate fmt vet ## Run tests.
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.7.2/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR); setup_envtest_env $(ENVTEST_ASSETS_DIR); LOCAL=$(LOCAL) go test ./... -coverprofile cover.out
test: mock manifests generate fmt vet envtest ## Run tests.
KUBECONFIG=$(KUBECONFIG) \
LOCAL=$(LOCAL) \
RESTRICTED_POLICY_RESOURCES=$(RESTRICTED_POLICY_RESOURCES) \
RESTRICTED_S3_RESOURCES=$(RESTRICTED_S3_RESOURCES) \
AWS_ACCOUNT_ID=$(AWS_ACCOUNT_ID) \
AWS_REGION=$(AWS_REGION) \
CLUSTER_NAME=$(CLUSTER_NAME) \
CLUSTER_OIDC_ISSUER_URL="$(CLUSTER_OIDC_ISSUER_URL)" \
DEFAULT_TRUST_POLICY=$(DEFAULT_TRUST_POLICY) \
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out

##@ Build

build: mock generate fmt vet ## Build manager binary.
go build -o bin/manager main.go
go build -o bin/manager cmd/main.go

run: manifests generate fmt vet ## Run a controller from your host.
go run ./main.go
go run cmd/main.go

docker-build: test ## Build docker image with the manager.
docker build -t ${IMG} .
Expand All @@ -101,7 +122,7 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.1)
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.13.0)

KUSTOMIZE = $(shell pwd)/bin/kustomize
kustomize: ## Download kustomize locally if necessary.
Expand All @@ -121,10 +142,7 @@ rm -rf $$TMP_DIR ;\
}
endef


.PHONY: kubebuilder
kubebuilder:
@echo "Downloading and installing Kubebuilder - this requires sudo privileges"
curl -fsSL -O "https://github.com/kubernetes-sigs/kubebuilder/releases/download/v$(KUBEBUILDER_VER)/kubebuilder_$(OSNAME)_$(KUBEBUILDER_ARCH)"
chmod +x kubebuilder_$(OSNAME)_$(KUBEBUILDER_ARCH) && sudo mv kubebuilder_$(OSNAME)_$(KUBEBUILDER_ARCH) /usr/local/bin/

.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
4 changes: 2 additions & 2 deletions api/v1alpha1/OrderedMap.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
// +kubebuilder:object:generate=false
type OrderedMap map[string]string

//MarshalJSON function is a custom implementation of json.Marshal for OrderedMap
// MarshalJSON function is a custom implementation of json.Marshal for OrderedMap
func (s OrderedMap) MarshalJSON() ([]byte, error) {
m := treemap.NewWithStringComparator()

Expand All @@ -20,7 +20,7 @@ func (s OrderedMap) MarshalJSON() ([]byte, error) {
return m.ToJSON()
}

//UnmarshalJson function is a custom implementation of json to unmarshal OrderedMap
// UnmarshalJson function is a custom implementation of json to unmarshal OrderedMap
func (s *OrderedMap) UnmarshalJSON(b []byte) error {
// Just regular unmarshal into map[string]string should work fine
var foo map[string]string
Expand Down
8 changes: 4 additions & 4 deletions api/v1alpha1/alertsconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type AlertsConfigSpec struct {
GlobalParams OrderedMap `json:"globalParams,omitempty"`
}

//GVK struct represents the alert type and can be used as a global as well as in individual alert section
// GVK struct represents the alert type and can be used as a global as well as in individual alert section
type GVK struct {
//Group - CRD Group name which this config/s is related to
Group string `json:"group,omitempty"`
Expand All @@ -47,7 +47,7 @@ type GVK struct {
Kind string `json:"kind,omitempty"`
}

//Config section provides the AlertsConfig for each individual alert
// Config section provides the AlertsConfig for each individual alert
// +optional
type Config struct {
//GVK can be used to provide CRD group, version and kind- If there is a global GVK already provided this will overwrite it
Expand Down Expand Up @@ -77,8 +77,8 @@ type AssociatedAlert struct {
Generation int64 `json:"generation,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state",description="current state of the alerts config"
// +kubebuilder:printcolumn:name="RetryCount",type="integer",JSONPath=".status.retryCount",description="Retry count"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="time passed since alerts config creation"
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the alertmanager v1alpha1 API group
//+kubebuilder:object:generate=true
//+groupName=alertmanager.keikoproj.io
// +kubebuilder:object:generate=true
// +groupName=alertmanager.keikoproj.io
package v1alpha1

import (
Expand Down
6 changes: 3 additions & 3 deletions api/v1alpha1/wavefrontalert_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ type WavefrontAlertStatus struct {
AlertsStatus map[string]AlertStatus `json:"alertsStatus,omitempty"`
}

//AlertStatus consists of individual alert details
// AlertStatus consists of individual alert details
type AlertStatus struct {
ID string `json:"id"`
Name string `json:"alertName"`
Expand All @@ -149,8 +149,8 @@ type AssociatedAlertsConfig struct {
CR string `json:"CR,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=wavefrontalerts,scope=Namespaced,shortName=wfalerts,singular=wavefrontalert
// +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state",description="current state of the wavefront alert"
// +kubebuilder:printcolumn:name="RetryCount",type="integer",JSONPath=".status.retryCount",description="Retry count"
Expand Down
1 change: 0 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions main.go → cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ package main
import (
"context"
"flag"
"github.com/keikoproj/alert-manager/controllers/common"
"os"

"github.com/keikoproj/alert-manager/internal/config"
"github.com/keikoproj/alert-manager/internal/controllers/common"
"github.com/keikoproj/alert-manager/pkg/k8s"
"github.com/keikoproj/alert-manager/pkg/log"
"github.com/keikoproj/alert-manager/pkg/wavefront"
"os"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
"sigs.k8s.io/controller-runtime/pkg/webhook"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
_ "k8s.io/client-go/plugin/pkg/client/auth"
Expand All @@ -38,8 +42,8 @@ import (

wf "github.com/WavefrontHQ/go-wavefront-management-api"
alertmanagerv1alpha1 "github.com/keikoproj/alert-manager/api/v1alpha1"
"github.com/keikoproj/alert-manager/controllers"
configcommon "github.com/keikoproj/alert-manager/internal/config/common"
"github.com/keikoproj/alert-manager/internal/controllers"
//+kubebuilder:scaffold:imports
)

Expand Down Expand Up @@ -76,8 +80,8 @@ func main() {

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
MetricsBindAddress: metricsAddr,
Port: 9443,
Metrics: metricsserver.Options{BindAddress: metricsAddr},
WebhookServer: webhook.NewServer(webhook.Options{Port: 9443}),
HealthProbeBindAddress: probeAddr,
LeaderElection: enableLeaderElection,
LeaderElectionID: "0cecb213.keikoproj.io",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.13.0
name: alertsconfigs.alertmanager.keikoproj.io
spec:
group: alertmanager.keikoproj.io
Expand Down Expand Up @@ -174,9 +172,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.4.1
creationTimestamp: null
controller-gen.kubebuilder.io/version: v0.13.0
name: wavefrontalerts.alertmanager.keikoproj.io
spec:
group: alertmanager.keikoproj.io
Expand Down Expand Up @@ -205,9 +203,3 @@ spec:
storage: true
subresources:
status: {}
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
2 changes: 0 additions & 2 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
creationTimestamp: null
name: role
rules:
- apiGroups:
Expand Down
Loading
Loading