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

[ENHANCEMENT] Update dependencies and improve docs #21

Merged
merged 19 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
33 changes: 26 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,18 @@ ifeq ($(USE_IMAGE_DIGESTS), true)
BUNDLE_GEN_FLAGS += --use-image-digests
endif

## Versions

# Set the Operator SDK version to use. By default, what is installed on the system is used.
# This is useful for CI or a project to utilize a specific version of the operator-sdk toolkit.
OPERATOR_SDK_VERSION ?= v1.32.0
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.31.0
# ENVTEST_VERSION refers to the version of the envtest binary.
ENVTEST_VERSION ?= release-0.19

# Image URL to use all building/pushing image targets
IMG ?= $(IMAGE_TAG_BASE):$(VERSION)
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.26.0

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
Expand Down Expand Up @@ -119,7 +123,7 @@ vet: ## Run go vet against code.

.PHONY: test
test: manifests generate fmt vet envtest ## Run tests.
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)" go test $(shell go list ./...) -v -ginkgo.v -coverprofile cover.out

.PHONY: lint
lint: ## Run linting.
Expand Down Expand Up @@ -196,11 +200,11 @@ $(LOCALBIN):
## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION)

## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
CONTROLLER_TOOLS_VERSION ?= v0.14.0
CONTROLLER_TOOLS_VERSION ?= v0.16.0

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
Expand All @@ -218,10 +222,11 @@ $(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen && $(LOCALBIN)/controller-gen --version | grep -q $(CONTROLLER_TOOLS_VERSION) || \
GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION)


.PHONY: envtest
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
envtest: $(ENVTEST) ## Download setup-envtest locally if necessary.
$(ENVTEST): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest,$(ENVTEST_VERSION))

.PHONY: operator-sdk
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
Expand Down Expand Up @@ -295,3 +300,17 @@ catalog-build: opm ## Build a catalog image.
.PHONY: catalog-push
catalog-push: ## Push a catalog image.
$(MAKE) docker-push IMG=$(CATALOG_IMG)

# go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist
# $1 - target path with name of binary (ideally with version)
# $2 - package url which can be installed
# $3 - specific version of package
define go-install-tool
@[ -f $(1) ] || { \
set -e; \
package=$(2)@$(3) ;\
echo "Downloading $${package}" ;\
GOBIN=$(LOCALBIN) go install $${package} ;\
mv "$$(echo "$(1)" | sed "s/-$(3)$$//")" $(1) ;\
}
endef
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ make install
2. Install custom resources:

```sh
bin/kustomize build config/samples | kubectl apply -f -
kubectl apply -k config/samples
```

3. Build and push your image to the location specified by `IMG`:
Expand Down Expand Up @@ -90,7 +90,8 @@ kubectl delete -f config/samples/v1alpha1_perses.yaml --namespace default
If you are editing the API definitions, generate the manifests such as CRs or CRDs using:

```sh
make manifests
make manifests # Generate YAML manifests like CRDs, RBAC etc.
make generate # Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
```

**NOTE:** Run `make --help` for more information on all potential `make` targets
Expand Down
14 changes: 9 additions & 5 deletions api/v1alpha1/perses_config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package v1alpha1

import (
"github.com/barkimedes/go-deepcopy"
"fmt"

"github.com/brunoga/deep"
"github.com/perses/perses/pkg/model/api/config"
)

Expand All @@ -10,11 +12,13 @@ type PersesConfig struct {
}

func (in *PersesConfig) DeepCopyInto(out *PersesConfig) {
temp, err := deepcopy.Anything(in)
if in == nil {
return
}

copied, err := deep.Copy(in)
if err != nil {
panic(err)
panic(fmt.Errorf("failed to deep copy PersesConfig: %w", err))
}

*out = *(temp.(*PersesConfig))
*out = *copied
}
14 changes: 9 additions & 5 deletions api/v1alpha1/perses_dashboard.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package v1alpha1

import (
"github.com/barkimedes/go-deepcopy"
"fmt"

"github.com/brunoga/deep"
persesv1 "github.com/perses/perses/pkg/model/api/v1"
)

Expand All @@ -10,11 +12,13 @@ type Dashboard struct {
}

func (in *Dashboard) DeepCopyInto(out *Dashboard) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for deep copy in the Perses repo we are using this package github.com/brunoga/deep. Works pretty well.
Maybe it's more efficient than marshalling and unmarshalling the data 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the pointer, Augustin. I have manually marshalled and unmarshalled as I was getting issue during deepcopying using go-deepcopy library. The github.com/brunoga/deep works great and I have fixed in this commit 4e2fa72 :)

temp, err := deepcopy.Anything(in)
if in == nil {
return
}

copied, err := deep.Copy(in)
if err != nil {
panic(err)
panic(fmt.Errorf("failed to deep copy Dashboard: %w", err))
}

*out = *(temp.(*Dashboard))
*out = *copied
}
14 changes: 9 additions & 5 deletions api/v1alpha1/perses_datasource.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package v1alpha1

import (
"github.com/barkimedes/go-deepcopy"
"fmt"

"github.com/brunoga/deep"
persesv1 "github.com/perses/perses/pkg/model/api/v1"
)

Expand All @@ -10,11 +12,13 @@ type Datasource struct {
}

func (in *Datasource) DeepCopyInto(out *Datasource) {
temp, err := deepcopy.Anything(in)
if in == nil {
return
}

copied, err := deep.Copy(in)
if err != nil {
panic(err)
panic(fmt.Errorf("failed to deep copy Datasource: %w", err))
}

*out = *(temp.(*Datasource))
*out = *copied
}
Loading