Skip to content

Commit

Permalink
feat(spacetemplates): Provide pre-configured templates for creating s…
Browse files Browse the repository at this point in the history
…paces

feat(spacetemplates): Provide pre-configured templates for creating spaces
  • Loading branch information
smileisak authored Nov 18, 2023
2 parents 97ba5c3 + bc9c01e commit de97cde
Show file tree
Hide file tree
Showing 47 changed files with 5,069 additions and 456 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Golang Unit tests

on:
push:
branches: [ "*" ]
pull_request:
branches: [ "*" ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ '1.19', '1.20', '1.21.x' ]

steps:
- uses: actions/checkout@v4
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
- name: Install dependencies
run: go get .
- name: Run unit tests with Go CLI
run: go test ./... -v
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ linters-settings:
linters:
enable-all: true
disable:
- depguard
- nestif
- nonamedreturns
- exhaustruct
Expand Down Expand Up @@ -54,4 +55,5 @@ service:

run:
skip-files:
- "zz_.*\\.go$"
- "zz_.*\\.go$"
- "_test*.go"
17 changes: 11 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ apidoc: apidocs-gen ## Generate CRD Documentation

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

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

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

.PHONY: helm-docs
helm-docs: HELMDOCS_VERSION := v1.11.0
helm-docs: docker ## Run helm-docs within docker.
@docker run --rm -v "$(SRC_ROOT):/helm-docs" jnorwood/helm-docs:$(HELMDOCS_VERSION) --chart-search-root /helm-docs


helm-docs: helm-docs-ensure ## Run helm-docs.
$(HELM_DOCS) --chart-search-root $(shell pwd)/charts

.PHONY: helm-lint
helm-lint: docker ## Run ct test linter in docker.
Expand Down Expand Up @@ -255,3 +256,7 @@ $(CONTROLLER_GEN): $(LOCALBIN)
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: merge-request
merge-request: manifests installer golint apidoc helm-docs ## Run Local checks before a opening merge request
13 changes: 13 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Code generated by tool. DO NOT EDIT.
# This file is used to track the info used to scaffold your project
# and allow the plugins properly work.
# More info: https://book.kubebuilder.io/reference/project-config.html
domain: nauticus.io
layout:
- go.kubebuilder.io/v3
Expand All @@ -13,4 +17,13 @@ resources:
kind: Space
path: github.com/edixos/nauticus/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: nauticus.io
group: nauticus.io
kind: SpaceTemplate
path: github.com/edixos/nauticus/api/v1alpha1
version: v1alpha1
version: "3"
20 changes: 20 additions & 0 deletions api/v1alpha1/space_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ type SpaceSpec struct {
LimitRanges LimitRangesSpec `json:"limitRanges,omitempty"`
// Specifies a list of service account to create within the Space. Optional
ServiceAccounts ServiceAccountsSpec `json:"serviceAccounts,omitempty"`
// Reference to a SpaceTemplate
TemplateRef SpaceTemplateReference `json:"templateRef,omitempty"`
}

// SpaceTemplateReference.
type SpaceTemplateReference struct {
// Name of the SpaceTemplate.
Name string `json:"name,omitempty"`
// Kind specifies the kind of the referenced resource, which should be "SpaceTemplate".
Kind string `json:"kind,omitempty"`
// Group is the API group of the SpaceTemplate, "nauticus.io/v1alpha1".
Group string `json:"group,omitempty"`
}

// SpaceStatus defines the observed state of Space.
Expand All @@ -55,6 +67,14 @@ type Space struct {
Status SpaceStatus `json:"status,omitempty"`
}

func (s *Space) GetConditions() []metav1.Condition {
return s.Status.Conditions
}

func (s *Space) SetConditions(conditions []metav1.Condition) {
s.Status.Conditions = conditions
}

//+kubebuilder:object:root=true

// SpaceList contains a list of Space.
Expand Down
66 changes: 66 additions & 0 deletions api/v1alpha1/spacetemplate_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2022-2023 Edixos
// SPDX-License-Identifier: Apache-2.0

package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// SpaceTemplateSpec defines the desired state of SpaceTemplate.
type SpaceTemplateSpec struct {
// Specifies a list of ResourceQuota resources assigned to the Space. The assigned values are inherited by the namespace created by the Space. Optional.
ResourceQuota corev1.ResourceQuotaSpec `json:"resourceQuota,omitempty"`
// Specifies additional RoleBindings assigned to the Space. Nauticus will ensure that the namespace in the Space always contain the RoleBinding for the given ClusterRole. Optional.
AdditionalRoleBindings AdditionalRoleBindingsSpec `json:"additionalRoleBindings,omitempty"`
// Specifies the NetworkPolicies assigned to the Tenant. The assigned NetworkPolicies are inherited by the namespace created in the Space. Optional.
NetworkPolicies NetworkPolicies `json:"networkPolicies,omitempty"`
// Specifies the resource min/max usage restrictions to the Space. Optional.
LimitRanges LimitRangesSpec `json:"limitRanges,omitempty"`
}

// SpaceTemplateStatus defines the observed state of SpaceTemplate.
type SpaceTemplateStatus struct {
// Conditions List of status conditions to indicate the status of Space
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster, categories={spacetemplate}
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Age"
// +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status",description="Ready"

// SpaceTemplate is the Schema for the spacetemplates API.
type SpaceTemplate struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec SpaceTemplateSpec `json:"spec,omitempty"`
Status SpaceTemplateStatus `json:"status,omitempty"`
}

func (in *SpaceTemplate) GetConditions() []metav1.Condition {
return in.Status.Conditions
}

func (in *SpaceTemplate) SetConditions(conditions []metav1.Condition) {
in.Status.Conditions = conditions
}

//+kubebuilder:object:root=true

// SpaceTemplateList contains a list of SpaceTemplate.
type SpaceTemplateList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []SpaceTemplate `json:"items"`
}

func init() {
SchemeBuilder.Register(&SpaceTemplate{}, &SpaceTemplateList{})
}
122 changes: 122 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

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

Loading

0 comments on commit de97cde

Please sign in to comment.