Skip to content

Commit bc9c01e

Browse files
committed
feat(space-tpl): some fixes before the merge
1 parent 28392c4 commit bc9c01e

File tree

7 files changed

+43
-33
lines changed

7 files changed

+43
-33
lines changed

.golangci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ linters-settings:
2222
linters:
2323
enable-all: true
2424
disable:
25+
- depguard
2526
- nestif
2627
- nonamedreturns
2728
- exhaustruct

Makefile

+11-6
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ apidoc: apidocs-gen ## Generate CRD Documentation
114114

115115
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
116116
golangci-lint: ## Download golangci-lint locally if necessary.
117-
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2)
117+
$(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint@v1.54.2)
118118

119119
# Linting code as PR is expecting
120120
.PHONY: golint
@@ -193,13 +193,14 @@ undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/confi
193193
# Helm
194194
SRC_ROOT = $(shell git rev-parse --show-toplevel)
195195

196+
HELM_DOCS = $(shell pwd)/bin/helm-docs
197+
.PHONY: helm-docs-ensure
198+
helm-docs-ensure: ## Download helm-docs locally if necessary.
199+
$(call go-install-tool,$(HELM_DOCS),github.com/norwoodj/helm-docs/cmd/[email protected])
196200

197201
.PHONY: helm-docs
198-
helm-docs: HELMDOCS_VERSION := v1.11.0
199-
helm-docs: docker ## Run helm-docs within docker.
200-
@docker run --rm -v "$(SRC_ROOT):/helm-docs" jnorwood/helm-docs:$(HELMDOCS_VERSION) --chart-search-root /helm-docs
201-
202-
202+
helm-docs: helm-docs-ensure ## Run helm-docs.
203+
$(HELM_DOCS) --chart-search-root $(shell pwd)/charts
203204

204205
.PHONY: helm-lint
205206
helm-lint: docker ## Run ct test linter in docker.
@@ -255,3 +256,7 @@ $(CONTROLLER_GEN): $(LOCALBIN)
255256
envtest: $(ENVTEST) ## Download envtest-setup locally if necessary.
256257
$(ENVTEST): $(LOCALBIN)
257258
test -s $(LOCALBIN)/setup-envtest || GOBIN=$(LOCALBIN) go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest
259+
260+
261+
.PHONY: merge-request
262+
merge-request: manifests installer golint apidoc helm-docs ## Run Local checks before a opening merge request

config/samples/space_with_tpl_ref_overrides.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ spec:
1212
templateRef:
1313
group: nauticus.io/v1alpha1
1414
kind: SpaceTemplate # Specify the Kind of the referenced resource
15-
name: spacetemplate-sample # Name of the SpaceTemplate
15+
name: space-tpl-sample # Name of the SpaceTemplate
1616
owners:
1717
- name: smile
1818
kind: User

controllers/space/controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
ctrl "sigs.k8s.io/controller-runtime"
1616
)
1717

18-
// SpaceReconciler reconciles a Space object.
18+
// Reconciler reconciles a Space object.
1919
type Reconciler struct {
2020
shared.Reconciler
2121
}

controllers/space/reconciler.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -127,33 +127,33 @@ func (r *Reconciler) reconcileSpace(ctx context.Context, space *nauticusiov1alph
127127

128128
func (r *Reconciler) reconcileSpaceFromTemplate(ctx context.Context, space *nauticusiov1alpha1.Space) (result reconcile.Result, err error) {
129129
// Fetch data from the SpaceTemplate
130-
spacetpl, err := r.FetchSpaceTemplate(ctx, space.Spec.TemplateRef.Name)
130+
spaceTpl, err := r.FetchSpaceTemplate(ctx, space.Spec.TemplateRef.Name)
131131
if err != nil {
132132
r.Log.Info("SpaceTemplate:", "SpaceTemplate does not exist", space.Spec.TemplateRef.Name)
133133

134134
return ctrl.Result{}, err
135135
}
136136

137137
// Merge and override space.ResourceQuota and spacetemplate.ResourceQuota
138-
rs, err := MergeResourceQuotas(space, spacetpl)
138+
rs, err := MergeResourceQuotas(space, spaceTpl)
139139
if err == nil {
140140
space.Spec.ResourceQuota = *rs
141141
}
142142
// Merge and override space.AdditionalRoleBindings and spacetemplate.AdditionalRoleBindings
143-
rb, err := MergeRoleBindings(space, spacetpl)
143+
rb, err := MergeRoleBindings(space, spaceTpl)
144144
if err == nil {
145145
space.Spec.AdditionalRoleBindings = rb
146146
}
147147

148148
if reflect.ValueOf(space.Spec.NetworkPolicies).IsZero() {
149-
space.Spec.NetworkPolicies = spacetpl.Spec.NetworkPolicies
149+
space.Spec.NetworkPolicies = spaceTpl.Spec.NetworkPolicies
150150
}
151151

152152
if reflect.ValueOf(space.Spec.LimitRanges).IsZero() {
153-
space.Spec.LimitRanges = spacetpl.Spec.LimitRanges
153+
space.Spec.LimitRanges = spaceTpl.Spec.LimitRanges
154154
}
155155
// Create or update the Space in the cluster
156-
r.Log.Info("Reconciling Space from", "SpaceTemplate", spacetpl.Name)
156+
r.Log.Info("Reconciling Space from", "SpaceTemplate", spaceTpl.Name)
157157

158158
return r.reconcileSpace(ctx, space)
159159
}

controllers/space/utlis_test.go

+21-17
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ package space
44

55
import (
66
"errors"
7+
"reflect"
8+
"testing"
9+
710
nauticusiov1alpha1 "github.com/edixos/nauticus/api/v1alpha1"
811
corev1 "k8s.io/api/core/v1"
912
v1 "k8s.io/api/rbac/v1"
1013
"k8s.io/apimachinery/pkg/api/resource"
11-
"reflect"
12-
"testing"
1314
)
1415

1516
func TestMergeResourceQuotas(t *testing.T) {
@@ -148,11 +149,12 @@ func TestMergeRoleBindings(t *testing.T) {
148149
space: &nauticusiov1alpha1.Space{
149150
Spec: nauticusiov1alpha1.SpaceSpec{
150151
AdditionalRoleBindings: []nauticusiov1alpha1.AdditionalRoleBinding{
151-
{RoleRef: v1.RoleRef{
152-
APIGroup: "rbac.authorization.k8s.io",
153-
Kind: "ClusterRole",
154-
Name: "editor",
155-
},
152+
{
153+
RoleRef: v1.RoleRef{
154+
APIGroup: "rbac.authorization.k8s.io",
155+
Kind: "ClusterRole",
156+
Name: "editor",
157+
},
156158
Subjects: []v1.Subject{
157159
{
158160
Name: "bob",
@@ -170,11 +172,12 @@ func TestMergeRoleBindings(t *testing.T) {
170172
spaceTemplate: &nauticusiov1alpha1.SpaceTemplate{
171173
Spec: nauticusiov1alpha1.SpaceTemplateSpec{
172174
AdditionalRoleBindings: []nauticusiov1alpha1.AdditionalRoleBinding{
173-
{RoleRef: v1.RoleRef{
174-
APIGroup: "rbac.authorization.k8s.io",
175-
Kind: "ClusterRole",
176-
Name: "viewer",
177-
},
175+
{
176+
RoleRef: v1.RoleRef{
177+
APIGroup: "rbac.authorization.k8s.io",
178+
Kind: "ClusterRole",
179+
Name: "viewer",
180+
},
178181
Subjects: []v1.Subject{
179182
{
180183
Name: "alice",
@@ -233,11 +236,12 @@ func TestMergeRoleBindings(t *testing.T) {
233236
spaceTemplate: &nauticusiov1alpha1.SpaceTemplate{
234237
Spec: nauticusiov1alpha1.SpaceTemplateSpec{
235238
AdditionalRoleBindings: []nauticusiov1alpha1.AdditionalRoleBinding{
236-
{RoleRef: v1.RoleRef{
237-
APIGroup: "rbac.authorization.k8s.io",
238-
Kind: "ClusterRole",
239-
Name: "viewer",
240-
},
239+
{
240+
RoleRef: v1.RoleRef{
241+
APIGroup: "rbac.authorization.k8s.io",
242+
Kind: "ClusterRole",
243+
Name: "viewer",
244+
},
241245
Subjects: []v1.Subject{
242246
{
243247
Name: "alice",

docs/tutorials/space-templates-tutorial.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ In this example, a Space named `space-tpl-ref-override` references a SpaceTempla
3131
* The `templateRef` references the `space-tpl-sample` SpaceTemplate.
3232
* This demonstrates the flexibility of SpaceTemplates, allowing Spaces to maintain standard configurations while adjusting specific settings as needed.
3333

34-
```yaml title="config/samples/space_wth_tpl_ref_overrides.yaml"
34+
```yaml title="config/samples/space_with_tpl_ref_overrides.yaml"
3535
{% include "../../config/samples/space_with_tpl_ref_overrides.yaml" %}
3636
```
3737
#### Example: Merging Additional Role Bindings
@@ -41,6 +41,6 @@ In this example, a Space named `space-tpl-ref-merge` references a Space Template
4141
* The templateRef references the `space-tpl-sample` SpaceTemplate.
4242
* The Space includes additional role bindings for both `viewer` and `editor` roles, with specific subjects.
4343
* The merged role bindings enrich the Space's access control settings, ensuring flexibility and control.
44-
```yaml title="config/samples/space_wth_tpl_merge.yaml"
44+
```yaml title="config/samples/space_with_tpl_merge.yaml"
4545
{% include "../../config/samples/space_with_tpl_merge.yaml" %}
4646
```

0 commit comments

Comments
 (0)