Skip to content

Commit

Permalink
feat: Add NexusCleanupPolicy Custom Resource (#25)
Browse files Browse the repository at this point in the history
Change-Id: I70146a91ce45f722b78a0dc6fdd48a745d4b6bbe
  • Loading branch information
zmotso committed Feb 16, 2024
1 parent 4d917c9 commit 7e1ba42
Show file tree
Hide file tree
Showing 30 changed files with 2,069 additions and 3 deletions.
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,13 @@ resources:
kind: NexusBlobStore
path: github.com/epam/edp-nexus-operator/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: epam.com
group: edp
kind: NexusCleanupPolicy
path: github.com/epam/edp-nexus-operator/api/v1alpha1
version: v1alpha1
version: "3"
103 changes: 103 additions & 0 deletions api/v1alpha1/nexuscleanuppolicy_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package v1alpha1

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

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

// NexusCleanupPolicySpec defines the desired state of NexusCleanupPolicy.
type NexusCleanupPolicySpec struct {
// Name is a unique name for the cleanup policy.
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
// +kubebuilder:validation:MaxLength=512
// +required
// +kubebuilder:example="go-cleanup-policy"
Name string `json:"name"`

// Format that this cleanup policy can be applied to.
// +required
// +kubebuilder:example="go"
// +kubebuilder:validation:Enum=apt;bower;cocoapods;conan;conda;docker;gitlfs;go;helm;maven2;npm;nuget;p2;pypi;r;raw;rubygems;yum
Format string `json:"format"`

// Description of the cleanup policy.
// +optional
// +kubebuilder:example="Cleanup policy for go format"
Description string `json:"description,omitempty"`

// Criteria for the cleanup policy.
// +required
Criteria Criteria `json:"criteria"`

// NexusRef is a reference to Nexus custom resource.
// +required
NexusRef common.NexusRef `json:"nexusRef"`
}

type Criteria struct {
// ReleaseType removes components that are of the following release type.
// +optional
// +kubebuilder:example="RELEASES"
// +kubebuilder:validation:Enum=RELEASES;PRERELEASES;""
ReleaseType string `json:"releaseType,omitempty"`

// LastBlobUpdated removes components published over “x” days ago.
// +optional
// +kubebuilder:example="30"
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=24855
LastBlobUpdated int `json:"lastBlobUpdated,omitempty"`

// LastDownloaded removes components downloaded over “x” days.
// +optional
// +kubebuilder:example="30"
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=24855
LastDownloaded int `json:"lastDownloaded,omitempty"`

// AssetRegex removes components that match the given regex.
// +optional
// +kubebuilder:example=".*"
AssetRegex string `json:"assetRegex,omitempty"`
}

// NexusCleanupPolicyStatus defines the observed state of NexusCleanupPolicy.
type NexusCleanupPolicyStatus struct {
// Value is a status of the cleanup policy.
// +optional
Value string `json:"value,omitempty"`

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

func (in *NexusCleanupPolicy) GetNexusRef() common.NexusRef {
return in.Spec.NexusRef
}

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

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

Spec NexusCleanupPolicySpec `json:"spec,omitempty"`
Status NexusCleanupPolicyStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&NexusCleanupPolicy{}, &NexusCleanupPolicyList{})
}
106 changes: 106 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.

137 changes: 137 additions & 0 deletions config/crd/bases/edp.epam.com_nexuscleanuppolicies.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.13.0
name: nexuscleanuppolicies.edp.epam.com
spec:
group: edp.epam.com
names:
kind: NexusCleanupPolicy
listKind: NexusCleanupPolicyList
plural: nexuscleanuppolicies
singular: nexuscleanuppolicy
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: NexusCleanupPolicy is the Schema for the cleanuppolicies 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: NexusCleanupPolicySpec defines the desired state of NexusCleanupPolicy
properties:
criteria:
description: Criteria for the cleanup policy.
properties:
assetRegex:
description: AssetRegex removes components that match the given
regex.
example: .*
type: string
lastBlobUpdated:
description: LastBlobUpdated removes components published over
“x” days ago.
example: "30"
maximum: 24855
minimum: 1
type: integer
lastDownloaded:
description: LastDownloaded removes components downloaded over
“x” days.
example: "30"
maximum: 24855
minimum: 1
type: integer
releaseType:
description: ReleaseType removes components that are of the following
release type.
enum:
- RELEASES
- PRERELEASES
- ""
example: RELEASES
type: string
type: object
description:
description: Description of the cleanup policy.
example: Cleanup policy for go format
type: string
format:
description: Format that this cleanup policy can be applied to.
enum:
- apt
- bower
- cocoapods
- conan
- conda
- docker
- gitlfs
- go
- helm
- maven2
- npm
- nuget
- p2
- pypi
- r
- raw
- rubygems
- yum
example: go
type: string
name:
description: Name is a unique name for the cleanup policy.
example: go-cleanup-policy
maxLength: 512
type: string
x-kubernetes-validations:
- message: Value is immutable
rule: self == oldSelf
nexusRef:
description: NexusRef is a reference to Nexus custom resource.
properties:
kind:
default: Nexus
description: Kind specifies the kind of the Nexus resource.
type: string
name:
description: Name specifies the name of the Nexus resource.
type: string
required:
- name
type: object
required:
- criteria
- format
- name
- nexusRef
type: object
status:
description: NexusCleanupPolicyStatus defines the observed state of NexusCleanupPolicy.
properties:
error:
description: Error is an error message if something went wrong.
type: string
value:
description: Value is a status of the cleanup policy.
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 @@ -8,6 +8,7 @@ resources:
- bases/edp.epam.com_nexusrepositories.yaml
- bases/edp.epam.com_nexusscripts.yaml
- bases/edp.epam.com_nexusblobstores.yaml
- bases/edp.epam.com_nexuscleanuppolicies.yaml
#+kubebuilder:scaffold:crdkustomizeresource

patchesStrategicMerge:
Expand All @@ -19,6 +20,7 @@ patchesStrategicMerge:
#- patches/webhook_in_nexusrepositories.yaml
#- patches/webhook_in_nexusscripts.yaml
#- patches/webhook_in_nexusblobstores.yaml
#- patches/webhook_in_nexuscleanuppolicies.yaml
#+kubebuilder:scaffold:crdkustomizewebhookpatch

# [CERTMANAGER] To enable cert-manager, uncomment all the sections with [CERTMANAGER] prefix.
Expand All @@ -29,6 +31,7 @@ patchesStrategicMerge:
#- patches/cainjection_in_nexusrepositories.yaml
#- patches/cainjection_in_nexusscripts.yaml
#- patches/cainjection_in_nexusblobstores.yaml
#- patches/cainjection_in_nexuscleanuppolicies.yaml
#+kubebuilder:scaffold:crdkustomizecainjectionpatch

# the following config is for teaching kustomize how to do kustomization for CRDs.
Expand Down
Loading

0 comments on commit 7e1ba42

Please sign in to comment.