Skip to content

Commit

Permalink
chore: re-scaffold kubebuilder project (#451)
Browse files Browse the repository at this point in the history
## Issue
449

## Description
This PR re-scaffolds the project using `kubebuilder alpha generate`. The
2 major changes are:
- Remove all usage of `kube-rbac-proxy` and replace with
[WithAuthenticationAndAuthorization
](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/metrics/filters#WithAuthenticationAndAuthorization)
due to `kube-rbac-proxy` being deprecated
- Initialize e2e tests. For now, we are only testing basic
functionality. The tests should be expanded to cover validator-specific
use-cases.

---------

Signed-off-by: Artur Shad Nik <[email protected]>
  • Loading branch information
arturshadnik authored Dec 11, 2024
1 parent f574d8c commit 025d729
Show file tree
Hide file tree
Showing 37 changed files with 1,061 additions and 504 deletions.
12 changes: 10 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
run:
timeout: 10m
timeout: 5m
allow-parallel-runners: true

issues:
# don't skip warning about doc comments
# don't exclude the default set of lint
exclude-use-default: false
# restore some of the defaults
# (fill in the rest as needed)
exclude-dirs:
- test
- tests
exclude-files:
- ".*_test\\.go"

Expand All @@ -16,6 +18,7 @@ linters:
enable:
- dupl
- errcheck
- copyloopvar
- ginkgolinter
- goconst
- gocyclo
Expand All @@ -33,3 +36,8 @@ linters:
- unconvert
- unparam
- unused

linters-settings:
revive:
rules:
- name: comment-spacings
12 changes: 6 additions & 6 deletions api/v1alpha1/validationresult_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ func DefaultValidationCondition() ValidationCondition {
}
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Age"
//+kubebuilder:printcolumn:name="Plugin",type="string",JSONPath=".spec.plugin",description="Plugin"
//+kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state",description="State"
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Age"
// +kubebuilder:printcolumn:name="Plugin",type="string",JSONPath=".spec.plugin",description="Plugin"
// +kubebuilder:printcolumn:name="State",type="string",JSONPath=".status.state",description="State"

// ValidationResult is the Schema for the validationresults API.
type ValidationResult struct {
Expand Down Expand Up @@ -151,7 +151,7 @@ func (r *ValidationResult) Hash() string {
return base64.StdEncoding.EncodeToString(hash)
}

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

// ValidationResultList contains a list of ValidationResult.
type ValidationResultList struct {
Expand Down
6 changes: 3 additions & 3 deletions api/v1alpha1/validatorconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ type ConditionType string
// HelmChartDeployedCondition defines whether the helm chart was installed/pulled/upgraded correctly.
const HelmChartDeployedCondition ConditionType = "HelmChartDeployed"

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

// ValidatorConfig is the Schema for the validatorconfigs API.
type ValidatorConfig struct {
Expand All @@ -133,7 +133,7 @@ type ValidatorConfig struct {
Status ValidatorConfigStatus `json:"status,omitempty"`
}

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

// ValidatorConfigList contains a list of ValidatorConfig.
type ValidatorConfigList struct {
Expand Down
2 changes: 1 addition & 1 deletion build
13 changes: 2 additions & 11 deletions chart/validator/README.md

Large diffs are not rendered by default.

12 changes: 0 additions & 12 deletions chart/validator/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,6 @@ spec:
runAsNonRoot: false
{{- end }}
containers:
- args: {{- toYaml .Values.controllerManager.kubeRbacProxy.args | nindent 8 }}
env:
- name: KUBERNETES_CLUSTER_DOMAIN
value: {{ quote .Values.kubernetesClusterDomain }}
image: {{ .Values.controllerManager.kubeRbacProxy.image.repository }}:{{ .Values.controllerManager.kubeRbacProxy.image.tag | default .Chart.AppVersion }}
name: kube-rbac-proxy
ports:
- containerPort: 8443
name: https
protocol: TCP
resources: {{- toYaml .Values.controllerManager.kubeRbacProxy.resources | nindent 10 }}
securityContext: {{- toYaml .Values.controllerManager.kubeRbacProxy.containerSecurityContext | nindent 10 }}
- args: {{- toYaml .Values.controllerManager.manager.args | nindent 8 }}
command:
- /manager
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "chart.fullname" . }}-proxy-role
name: {{ include "chart.fullname" . }}-metrics-auth-role
labels:
app.kubernetes.io/component: kube-rbac-proxy
app.kubernetes.io/created-by: validator
app.kubernetes.io/part-of: validator
{{- include "chart.labels" . | nindent 4 }}
Expand All @@ -24,16 +23,15 @@ rules:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "chart.fullname" . }}-proxy-rolebinding
name: {{ include "chart.fullname" . }}-metrics-auth-rolebinding
labels:
app.kubernetes.io/component: kube-rbac-proxy
app.kubernetes.io/created-by: validator
app.kubernetes.io/part-of: validator
{{- include "chart.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: '{{ include "chart.fullname" . }}-proxy-role'
name: '{{ include "chart.fullname" . }}-metrics-auth-role'
subjects:
- kind: ServiceAccount
name: '{{ include "chart.fullname" . }}-controller-manager'
Expand Down
1 change: 0 additions & 1 deletion chart/validator/templates/metrics-reader-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ kind: ClusterRole
metadata:
name: {{ include "chart.fullname" . }}-metrics-reader
labels:
app.kubernetes.io/component: kube-rbac-proxy
app.kubernetes.io/created-by: validator
app.kubernetes.io/part-of: validator
{{- include "chart.labels" . | nindent 4 }}
Expand Down
1 change: 0 additions & 1 deletion chart/validator/templates/metrics-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ kind: Service
metadata:
name: {{ include "chart.fullname" . }}-controller-manager-metrics-service
labels:
app.kubernetes.io/component: kube-rbac-proxy
app.kubernetes.io/created-by: validator
app.kubernetes.io/part-of: validator
control-plane: controller-manager
Expand Down
Loading

0 comments on commit 025d729

Please sign in to comment.