Skip to content
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
55 changes: 48 additions & 7 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,49 @@
version: "2"
run:
concurrency: 4
timeout: 10m

issues:
exclude-files:
- "zz_generated.*\\.go$"
- "tmp/.*"
allow-parallel-runners: true
linters:
default: none
enable:
- copyloopvar
# - dupl
- errcheck
- ginkgolinter
- goconst
- gocyclo
- govet
- ineffassign
- misspell
# - nakedret
- prealloc
- revive
- staticcheck
- unconvert
# - unparam
- unused
settings:
revive:
rules:
- name: comment-spacings
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- zz_generated.*\.go$
- tmp/.*
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofmt
- goimports
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion api/core/v1alpha1/project_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (p *Project) RemoveCondition(conditionType ConditionType) {
p.Status.Conditions = conditions
}

//+kubebuilder:object:root=true
// +kubebuilder:object:root=true

// ProjectList contains a list of Project
type ProjectList struct {
Expand Down
4 changes: 2 additions & 2 deletions api/core/v1alpha1/project_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (p *Project) SetupWebhookWithManager(mgr ctrl.Manager, memberOverridesName
Complete()
}

//+kubebuilder:webhook:path=/mutate-core-openmcp-cloud-v1alpha1-project,mutating=true,failurePolicy=fail,sideEffects=None,groups=core.openmcp.cloud,resources=projects,verbs=create;update,versions=v1alpha1,name=mproject.kb.io,admissionReviewVersions=v1
// +kubebuilder:webhook:path=/mutate-core-openmcp-cloud-v1alpha1-project,mutating=true,failurePolicy=fail,sideEffects=None,groups=core.openmcp.cloud,resources=projects,verbs=create;update,versions=v1alpha1,name=mproject.kb.io,admissionReviewVersions=v1

var _ webhook.CustomDefaulter = &Project{}

Expand Down Expand Up @@ -63,7 +63,7 @@ func (p *Project) ValidateDelete(ctx context.Context, obj runtime.Object) (warni
return
}

//+kubebuilder:webhook:path=/validate-core-openmcp-cloud-v1alpha1-project,mutating=false,failurePolicy=fail,sideEffects=None,groups=core.openmcp.cloud,resources=projects,verbs=create;update;delete,versions=v1alpha1,name=vproject.kb.io,admissionReviewVersions=v1
// +kubebuilder:webhook:path=/validate-core-openmcp-cloud-v1alpha1-project,mutating=false,failurePolicy=fail,sideEffects=None,groups=core.openmcp.cloud,resources=projects,verbs=create;update;delete,versions=v1alpha1,name=vproject.kb.io,admissionReviewVersions=v1

var _ webhook.CustomValidator = &projectValidator{}

Expand Down
6 changes: 3 additions & 3 deletions api/core/v1alpha1/webhook_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

//+kubebuilder:scaffold:imports
// +kubebuilder:scaffold:imports

"github.com/google/uuid"
envtestutil "github.com/openmcp-project/controller-utils/pkg/envtest"
Expand Down Expand Up @@ -86,7 +86,7 @@ var _ = BeforeSuite(func() {

err = corev1.AddToScheme(testScheme)
Expect(err).NotTo(HaveOccurred())
//+kubebuilder:scaffold:scheme
// +kubebuilder:scaffold:scheme

k8sClient, err = client.New(cfg, client.Options{Scheme: testScheme})
Expect(err).NotTo(HaveOccurred())
Expand All @@ -112,7 +112,7 @@ var _ = BeforeSuite(func() {
err = (&Workspace{}).SetupWebhookWithManager(mgr, "test-override")
Expect(err).NotTo(HaveOccurred())

//+kubebuilder:scaffold:webhook
// +kubebuilder:scaffold:webhook

go func() {
defer GinkgoRecover()
Expand Down
2 changes: 1 addition & 1 deletion api/core/v1alpha1/workspace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func (ws *Workspace) RemoveCondition(conditionType ConditionType) {
ws.Status.Conditions = conditions
}

//+kubebuilder:object:root=true
// +kubebuilder:object:root=true

// WorkspaceList contains a list of Workspace
type WorkspaceList struct {
Expand Down
4 changes: 2 additions & 2 deletions cmd/project-workspace-operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

openmcpv1alpha1 "github.com/openmcp-project/project-workspace-operator/api/core/v1alpha1"
pwocrds "github.com/openmcp-project/project-workspace-operator/api/crds"
//+kubebuilder:scaffold:imports
// +kubebuilder:scaffold:imports
)

const (
Expand Down Expand Up @@ -142,7 +142,7 @@ func (o *Options) run() {
os.Exit(1)
}
}
//+kubebuilder:scaffold:builder
// +kubebuilder:scaffold:builder

if err := mgr.AddHealthzCheck("healthz", healthz.Ping); err != nil {
setupLog.Error(err, "unable to set up health check")
Expand Down
2 changes: 1 addition & 1 deletion hack/common
10 changes: 5 additions & 5 deletions internal/controller/core/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ func (r *CommonReconciler) handleRemainingContentBeforeDelete(ctx context.Contex
if isProject {
namespace = project.Status.Namespace

if len(r.ProjectWorkspaceConfig.Project.ResourcesBlockingDeletion) == 0 {
if len(r.Project.ResourcesBlockingDeletion) == 0 {
return false, nil
}

resourcesBlockingDeletion = r.ProjectWorkspaceConfig.Project.ResourcesBlockingDeletion
resourcesBlockingDeletion = r.Project.ResourcesBlockingDeletion
} else {
namespace = workspace.Status.Namespace

if len(r.ProjectWorkspaceConfig.Workspace.ResourcesBlockingDeletion) == 0 {
if len(r.Workspace.ResourcesBlockingDeletion) == 0 {
return false, nil
}

resourcesBlockingDeletion = r.ProjectWorkspaceConfig.Workspace.ResourcesBlockingDeletion
resourcesBlockingDeletion = r.Workspace.ResourcesBlockingDeletion
}

remainingResources := make([]unstructured.Unstructured, 0)
Expand All @@ -95,7 +95,7 @@ func (r *CommonReconciler) handleRemainingContentBeforeDelete(ctx context.Contex
resList := &unstructured.UnstructuredList{}
resList.SetGroupVersionKind(gvk.ToSchemaGVK())

if err := r.Client.List(ctx, resList, client.InNamespace(namespace)); err != nil {
if err := r.List(ctx, resList, client.InNamespace(namespace)); err != nil {
log.Error(err, "failed to list resources")
return false, err
}
Expand Down
14 changes: 7 additions & 7 deletions internal/controller/core/project_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ type ProjectReconciler struct {
CommonReconciler
}

//+kubebuilder:rbac:groups=core.openmcp.cloud,resources=projects,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=core.openmcp.cloud,resources=projects/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=core.openmcp.cloud,resources=projects/finalizers,verbs=update
//+kubebuilder:rbac:groups="",resources=namespaces;secrets,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=rbac.authorization.k8s.io,resources=clusterroles;clusterrolebindings;rolebindings,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=core.openmcp.cloud,resources=projects,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=core.openmcp.cloud,resources=projects/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=core.openmcp.cloud,resources=projects/finalizers,verbs=update
// +kubebuilder:rbac:groups="",resources=namespaces;secrets,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=rbac.authorization.k8s.io,resources=clusterroles;clusterrolebindings;rolebindings,verbs=get;list;watch;create;update;patch;delete

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
func (r *ProjectReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := log.FromContext(ctx)

project := &v1alpha1.Project{}
if err := r.Client.Get(ctx, req.NamespacedName, project); err != nil {
if err := r.Get(ctx, req.NamespacedName, project); err != nil {
if apierrors.IsNotFound(err) {
log.Info("Project not found")
return ctrl.Result{}, nil
Expand Down Expand Up @@ -159,7 +159,7 @@ func getSubjectsForProjectRole(project *v1alpha1.Project, role v1alpha1.ProjectM

for _, member := range project.Spec.Members {
if hasProjectRole(member, role) {
subjects = append(subjects, member.Subject.RbacV1())
subjects = append(subjects, member.RbacV1())
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/controller/core/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"

openmcpv1alpha1 "github.com/openmcp-project/project-workspace-operator/api/core/v1alpha1"
//+kubebuilder:scaffold:imports
// +kubebuilder:scaffold:imports
)

// These tests use Ginkgo (BDD-style Go testing framework). Refer to
Expand Down Expand Up @@ -49,7 +49,7 @@ var _ = BeforeSuite(func() {
err = openmcpv1alpha1.AddToScheme(scheme.Scheme)
Expect(err).NotTo(HaveOccurred())

//+kubebuilder:scaffold:scheme
// +kubebuilder:scaffold:scheme

k8sClient, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
Expect(err).NotTo(HaveOccurred())
Expand Down
16 changes: 8 additions & 8 deletions internal/controller/core/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ func TestNamespaceForProject(t *testing.T) {
expected: "project-test",
},
// FIXME the current implementation panics if the project is nil
/*{
description: "doesn't fail if nil",
expected: "project-default",
},*/
// {
// description: "doesn't fail if nil",
// expected: "project-default",
// },
}

for _, test := range tests {
Expand All @@ -66,10 +66,10 @@ func TestNamespaceForWorkspace(t *testing.T) {
expected: "my-namespace--ws-test",
},
// FIXME the current implementation panics if the workspace is nil
/*{
description: "doesn't fail if nil",
expected: "tbd",
},*/
// {
// description: "doesn't fail if nil",
// expected: "tbd",
// },
}

for _, test := range tests {
Expand Down
14 changes: 7 additions & 7 deletions internal/controller/core/workspace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ type WorkspaceReconciler struct {
CommonReconciler
}

//+kubebuilder:rbac:groups=core.openmcp.cloud,resources=workspaces,verbs=get;list;watch;create;update;patch;delete
//+kubebuilder:rbac:groups=core.openmcp.cloud,resources=workspaces/status,verbs=get;update;patch
//+kubebuilder:rbac:groups=core.openmcp.cloud,resources=workspaces/finalizers,verbs=update
// +kubebuilder:rbac:groups=core.openmcp.cloud,resources=workspaces,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=core.openmcp.cloud,resources=workspaces/status,verbs=get;update;patch
// +kubebuilder:rbac:groups=core.openmcp.cloud,resources=workspaces/finalizers,verbs=update

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
func (r *WorkspaceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
log := log.FromContext(ctx)

workspace := &v1alpha1.Workspace{}
if err := r.Client.Get(ctx, req.NamespacedName, workspace); err != nil {
if err := r.Get(ctx, req.NamespacedName, workspace); err != nil {
if apierrors.IsNotFound(err) {
log.Info("Workspace not found")
return ctrl.Result{}, nil
Expand Down Expand Up @@ -139,7 +139,7 @@ func (r *WorkspaceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (

func (r *WorkspaceReconciler) getProjectByNamespace(ctx context.Context, namespaceName string) (*v1alpha1.Project, error) {
namespace := &corev1.Namespace{}
if err := r.Client.Get(ctx, types.NamespacedName{Name: namespaceName}, namespace); err != nil {
if err := r.Get(ctx, types.NamespacedName{Name: namespaceName}, namespace); err != nil {
return nil, err
}

Expand All @@ -153,7 +153,7 @@ func (r *WorkspaceReconciler) getProjectByNamespace(ctx context.Context, namespa
}

project := &v1alpha1.Project{}
if err := r.Client.Get(ctx, types.NamespacedName{Name: projectName}, project); err != nil {
if err := r.Get(ctx, types.NamespacedName{Name: projectName}, project); err != nil {
return nil, err
}

Expand Down Expand Up @@ -300,7 +300,7 @@ func getSubjectsForWorkspaceRole(workspace *v1alpha1.Workspace, role v1alpha1.Wo

for _, member := range workspace.Spec.Members {
if hasWorkspaceRole(member, role) {
subjects = append(subjects, member.Subject.RbacV1())
subjects = append(subjects, member.RbacV1())
}
}

Expand Down
Loading