Skip to content
Draft
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
5 changes: 5 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ jobs:
with:
go-version: '=1.21.0'
cache: false
- uses: nolar/setup-k3d-k3s@v1
with:
skip-creation: true
- name: Build binary
run: |
cd $__W_SRC_REL
go mod tidy
make build
make docker-build-no-test IMG=controller:latest
make test
- name: Login to Docker Registry
uses: docker/login-action@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: 1.21
go-version: 1.25
- uses: actions/checkout@v3
- name: Configure git for private modules
env:
Expand Down
16 changes: 6 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ endif

# 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.25.0

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

.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
test: manifests generate fmt vet ## Run tests.
go test ./tests/ -v -ginkgo.v -coverprofile cover.out

##@ Build

Expand All @@ -127,6 +125,10 @@ run: manifests generate fmt vet ## Run a controller from your host.
docker-build: test ## Build docker image with the manager.
docker build -t ${IMG} .

.PHONY: docker-build-no-test
docker-build-no-test:
docker build -t ${IMG} .

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker push ${IMG}
Expand Down Expand Up @@ -181,7 +183,6 @@ $(LOCALBIN):
## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest

## Tool Versions
KUSTOMIZE_VERSION ?= v3.8.7
Expand All @@ -198,11 +199,6 @@ controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessar
$(CONTROLLER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/controller-gen || 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): $(LOCALBIN)
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

.PHONY: bundle
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
operator-sdk generate kustomize manifests -q
Expand Down
2 changes: 1 addition & 1 deletion config/crd/patches/webhook_in_mongodbaccessrequests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
webhook:
clientConfig:
service:
namespace: system
namespace: airlock-system
name: webhook-service
path: /convert
conversionReviewVersions:
Expand Down
2 changes: 1 addition & 1 deletion config/crd/patches/webhook_in_mongodbclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ spec:
webhook:
clientConfig:
service:
namespace: system
namespace: airlock-system
name: webhook-service
path: /convert
conversionReviewVersions:
Expand Down
2 changes: 1 addition & 1 deletion config/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
namespace: airlock-system
spec:
template:
spec:
Expand Down
2 changes: 1 addition & 1 deletion config/default/manager_config_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
namespace: airlock-system
spec:
template:
spec:
Expand Down
11 changes: 6 additions & 5 deletions config/manager/manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ metadata:
app.kubernetes.io/created-by: airlock
app.kubernetes.io/part-of: airlock
app.kubernetes.io/managed-by: kustomize
name: system
name: airlock-system

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah, this will break, it will be called airlock-airlock-system

---
apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
namespace: airlock-system

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't get why those changes to the namespace is needed.

In config/default/kustomization.yaml, there is

namespace: airlock-system

namePrefix: airlock-

so all resources here will go to that namespace, and be named correctly.....

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I'll revert. Did this before saw the kustomize file

labels:
control-plane: controller-manager
app.kubernetes.io/name: deployment
app.kubernetes.io/name: airlock
app.kubernetes.io/instance: controller-manager
app.kubernetes.io/component: manager
app.kubernetes.io/created-by: airlock
Expand All @@ -35,6 +35,7 @@ spec:
kubectl.kubernetes.io/default-container: manager
labels:
control-plane: controller-manager
app.kubernetes.io/name: airlock
spec:
# TODO(user): Uncomment the following code to configure the nodeAffinity expression
# according to the platforms which are supported by your solution.
Expand Down Expand Up @@ -70,8 +71,8 @@ spec:
- /manager
args:
- --leader-elect
image: controller:latest
imagePullPolicy: Always
image: docker.io/library/controller:latest

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

erm, why change this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Will revert. Was checking something.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Will revert. Was checking something.

imagePullPolicy: IfNotPresent

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

and this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Pull policy yes needs changing because I'm importing image to k3d, and always policy will not use that image but try to pull

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Pull policy yes needs changing because I'm importing image to k3d, and always policy will not use that image but try to pull

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Pull policy yes needs changing because I'm importing image to k3d, and always policy will not use that image but try to pull

name: manager
securityContext:
allowPrivilegeEscalation: false
Expand Down
2 changes: 1 addition & 1 deletion config/manager/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: controller-manager
namespace: system
namespace: airlock-system
spec:
template:
spec:
Expand Down
2 changes: 1 addition & 1 deletion config/manifests/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ resources:
# version: v1
# kind: Deployment
# name: controller-manager
# namespace: system
# namespace: airlock-system
# patch: |-
# # Remove the manager container's "cert" volumeMount, since OLM will create and mount a set of certs.
# # Update the indices in this path if adding or removing containers/volumeMounts in the manager's Deployment.
Expand Down
2 changes: 1 addition & 1 deletion config/prometheus/monitor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ metadata:
app.kubernetes.io/part-of: airlock
app.kubernetes.io/managed-by: kustomize
name: controller-manager-metrics-monitor
namespace: system
namespace: airlock-system
spec:
endpoints:
- path: /metrics
Expand Down
2 changes: 1 addition & 1 deletion config/rbac/auth_proxy_role_binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ roleRef:
subjects:
- kind: ServiceAccount
name: controller-manager
namespace: system
namespace: airlock-system
2 changes: 1 addition & 1 deletion config/rbac/auth_proxy_service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ metadata:
app.kubernetes.io/part-of: airlock
app.kubernetes.io/managed-by: kustomize
name: controller-manager-metrics-service
namespace: system
namespace: airlock-system
spec:
ports:
- name: https
Expand Down
2 changes: 2 additions & 0 deletions config/rbac/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ resources:
- auth_proxy_role.yaml
- auth_proxy_role_binding.yaml
- auth_proxy_client_clusterrole.yaml

namespace: airlock-system
2 changes: 1 addition & 1 deletion config/rbac/leader_election_role_binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ roleRef:
subjects:
- kind: ServiceAccount
name: controller-manager
namespace: system
namespace: airlock-system
2 changes: 1 addition & 1 deletion config/rbac/role_binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ roleRef:
subjects:
- kind: ServiceAccount
name: controller-manager
namespace: system
namespace: airlock-system
2 changes: 1 addition & 1 deletion config/rbac/service_account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ metadata:
app.kubernetes.io/part-of: airlock
app.kubernetes.io/managed-by: kustomize
name: controller-manager
namespace: system
namespace: airlock-system
13 changes: 6 additions & 7 deletions controllers/mongodbcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/metrics"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
"sigs.k8s.io/controller-runtime/pkg/source"

airlockv1alpha1 "github.com/RocketChat/airlock/api/v1alpha1"
)
Expand Down Expand Up @@ -210,14 +209,14 @@ func (r *MongoDBClusterReconciler) Reconcile(ctx context.Context, req ctrl.Reque
return ctrl.Result{}, utilerrors.NewAggregate([]error{err, r.Status().Update(ctx, mongodbClusterCR)})
}

func (r *MongoDBClusterReconciler) findObjectsForSecret(secret client.Object) []reconcile.Request {
func (r *MongoDBClusterReconciler) findObjectsForSecret(ctx context.Context, secret client.Object) []reconcile.Request {
mongodbClusterCR := &airlockv1alpha1.MongoDBClusterList{}
listOps := &client.ListOptions{
FieldSelector: fields.OneTermEqualSelector("connectionSecret", secret.GetName()),
Namespace: "",
}

err := r.List(context.TODO(), mongodbClusterCR, listOps)
err := r.List(ctx, mongodbClusterCR, listOps)
if err != nil {
return []reconcile.Request{}
}
Expand Down Expand Up @@ -270,19 +269,19 @@ func (r *MongoDBClusterReconciler) SetupWithManager(mgr ctrl.Manager) error {
return ctrl.NewControllerManagedBy(mgr).
For(&airlockv1alpha1.MongoDBCluster{}).
Watches(
&source.Kind{Type: &corev1.Secret{}},
&corev1.Secret{},
handler.EnqueueRequestsFromMapFunc(r.findObjectsForSecret),
builder.WithPredicates(predicate.ResourceVersionChangedPredicate{}),
).
Watches(
&source.Kind{Type: &corev1.Node{}},
handler.EnqueueRequestsFromMapFunc(func(node client.Object) []reconcile.Request {
&corev1.Node{},
handler.EnqueueRequestsFromMapFunc(func(ctx context.Context, node client.Object) []reconcile.Request {
mongodbClusterCR := &airlockv1alpha1.MongoDBClusterList{}
listOps := &client.ListOptions{
Namespace: "",
}

err := r.List(context.TODO(), mongodbClusterCR, listOps)
err := r.List(ctx, mongodbClusterCR, listOps)
if err != nil {
return []reconcile.Request{}
}
Expand Down
Loading
Loading