Skip to content

Commit

Permalink
feat: Add SonarQualityGate custom resource (#3)
Browse files Browse the repository at this point in the history
Jira: EPMDEDP-12128
Change-Id: I2278646af5f8f5451460174b27ceb8dc4919c858
  • Loading branch information
zmotso committed Aug 18, 2023
1 parent d55719f commit abd7e5d
Show file tree
Hide file tree
Showing 42 changed files with 2,232 additions and 365 deletions.
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,13 @@ resources:
kind: SonarUser
path: github.com/epam/edp-sonar-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: epam.com
group: edp
kind: SonarQualityGate
path: github.com/epam/edp-sonar-operator/api/v1alpha1
version: v1alpha1
version: "3"
93 changes: 93 additions & 0 deletions api/v1alpha1/sonarqualitygate_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/epam/edp-sonar-operator/api/common"
)

// SonarQualityGateSpec defines the desired state of SonarQualityGate
type SonarQualityGateSpec struct {
// Name is a name of quality gate.
// Name should be unique across all quality gates.
// Don't change this field after creation otherwise quality gate will be recreated.
// +required
// +kubebuilder:validation:MaxLength=100
// +kubebuilder:example="My Quality Gate"
Name string `json:"name"`

// Default is a flag to set quality gate as default.
// Only one quality gate can be default.
// If several quality gates have default flag, the random one will be chosen.
// Default quality gate can't be deleted. You need to set another quality gate as default before.
// +optional
// +kubebuilder:example="true"
Default bool `json:"default"`

// Conditions is a list of conditions for quality gate.
// Key is a metric name, value is a condition.
// +optional
// +nullable
// +kubebuilder:example={new_code_smells: {error: "10", op: "LT"}}
Conditions map[string]Condition `json:"conditions"`

// SonarRef is a reference to Sonar custom resource.
// +required
SonarRef common.SonarRef `json:"sonarRef"`
}

// Condition defines the condition for quality gate.
type Condition struct {
// Error is condition error threshold.
// +required
// +kubebuilder:validation:MaxLength=64
// +kubebuilder:example="10"
Error string `json:"error"`

// Op is condition operator.
// LT = is lower than
// GT = is greater than
// +optional
// +kubebuilder:validation:Enum=LT;GT
Op string `json:"op,omitempty"`
}

// SonarQualityGateStatus defines the observed state of SonarQualityGate
type SonarQualityGateStatus struct {
// Value is a status of the user.
// +optional
Value string `json:"value,omitempty"`

// Error is an error message if something went wrong.
// +optional
Error string `json:"error,omitempty"`
}

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

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

Spec SonarQualityGateSpec `json:"spec,omitempty"`
Status SonarQualityGateStatus `json:"status,omitempty"`
}

func (in *SonarQualityGate) GetSonarRef() common.SonarRef {
return in.Spec.SonarRef
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&SonarQualityGate{}, &SonarQualityGateList{})
}
112 changes: 112 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.

109 changes: 109 additions & 0 deletions config/crd/bases/edp.epam.com_sonarqualitygates.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.12.1
name: sonarqualitygates.edp.epam.com
spec:
group: edp.epam.com
names:
kind: SonarQualityGate
listKind: SonarQualityGateList
plural: sonarqualitygates
singular: sonarqualitygate
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: SonarQualityGate is the Schema for the sonarqualitygates API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: SonarQualityGateSpec defines the desired state of SonarQualityGate
properties:
conditions:
additionalProperties:
description: Condition defines the condition for quality gate.
properties:
error:
description: Error is condition error threshold.
example: "10"
maxLength: 64
type: string
op:
description: Op is condition operator. LT = is lower than GT
= is greater than
enum:
- LT
- GT
type: string
required:
- error
type: object
description: Conditions is a list of conditions for quality gate.
Key is a metric name, value is a condition.
example:
new_code_smells:
error: "10"
op: LT
nullable: true
type: object
default:
description: Default is a flag to set quality gate as default. Only
one quality gate can be default. If several quality gates have default
flag, the random one will be chosen. Default quality gate can't
be deleted. You need to set another quality gate as default before.
example: "true"
type: boolean
name:
description: Name is a name of quality gate. Name should be unique
across all quality gates. Don't change this field after creation
otherwise quality gate will be recreated.
example: My Quality Gate
maxLength: 100
type: string
sonarRef:
description: SonarRef is a reference to Sonar custom resource.
properties:
kind:
default: Sonar
description: Kind specifies the kind of the Sonar resource.
type: string
name:
description: Name specifies the name of the Sonar resource.
type: string
required:
- name
type: object
required:
- name
- sonarRef
type: object
status:
description: SonarQualityGateStatus defines the observed state of SonarQualityGate
properties:
error:
description: Error is an error message if something went wrong.
type: string
value:
description: Value is a status of the user.
type: string
type: object
type: object
served: true
storage: true
subresources:
status: {}
3 changes: 3 additions & 0 deletions config/crd/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@
resources:
- bases/v2.edp.epam.com_sonars.yaml
- bases/edp.epam.com_sonarusers.yaml
- bases/edp.epam.com_sonarqualitygates.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix.
# patches here are for enabling the conversion webhook for each CRD
#- patches/webhook_in_sonars.yaml
#- patches/webhook_in_sonarusers.yaml
#- patches/webhook_in_sonarqualitygates.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
# patches here are for enabling the CA injection for each CRD
#- patches/cainjection_in_sonars.yaml
#- patches/cainjection_in_sonarusers.yaml
#- patches/cainjection_in_sonarqualitygates.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
7 changes: 7 additions & 0 deletions config/crd/patches/cainjection_in_sonarqualitygates.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# The following patch adds a directive for certmanager to inject CA into the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
cert-manager.io/inject-ca-from: $(CERTIFICATE_NAMESPACE)/$(CERTIFICATE_NAME)
name: sonarqualitygates.edp.epam.com
16 changes: 16 additions & 0 deletions config/crd/patches/webhook_in_sonarqualitygates.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# The following patch enables a conversion webhook for the CRD
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
name: sonarqualitygates.edp.epam.com
spec:
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
namespace: system
name: webhook-service
path: /convert
conversionReviewVersions:
- v1
Loading

0 comments on commit abd7e5d

Please sign in to comment.