Skip to content

Commit

Permalink
Recurring Scheduled Resource Creation Support (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
yunussandikci committed Aug 11, 2024
1 parent b5afc84 commit e693400
Show file tree
Hide file tree
Showing 30 changed files with 452 additions and 180 deletions.
4 changes: 2 additions & 2 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ linters:
enable-all: true
disable:
- exhaustruct # Disallows to left unused fields in structs
- exhaustivestruct # Disallows to left unused fields in structs
- wrapcheck # Disallows to use non-wrapped errors
- gochecknoinits # Disallows to use init functions
- ireturn # Disallows to return Interfaces
Expand All @@ -22,5 +21,6 @@ run:
go: '1.22'
timeout: 10m
tests: false
skip-dirs:
issues:
exclude-dirs:
- cmd/benchmark
5 changes: 3 additions & 2 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package main
import (
"fmt"

"github.com/NCCloud/mayfly/pkg/apis/v1alpha2"

"github.com/NCCloud/mayfly/pkg/controllers/expiration"
"github.com/NCCloud/mayfly/pkg/controllers/scheduledresource"

"github.com/NCCloud/mayfly/pkg/apis/v1alpha1"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"

"github.com/NCCloud/mayfly/pkg/common"
Expand All @@ -29,7 +30,7 @@ func main() {
scheme := runtime.NewScheme()
config := common.NewConfig()

utilruntime.Must(v1alpha1.AddToScheme(scheme))
utilruntime.Must(v1alpha2.AddToScheme(scheme))
ctrl.SetLogger(logger)

logger.Info("Configuration", "config", config)
Expand Down
28 changes: 20 additions & 8 deletions deploy/crds/cloud.namecheap.com_scheduledresources.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@ spec:
scope: Namespaced
versions:
- additionalPrinterColumns:
- jsonPath: .spec.in
name: In
- jsonPath: .spec.schedule
name: Schedule
type: string
- jsonPath: .status.nextRun
name: Next Run
type: string
- jsonPath: .status.lastRun
name: Last Run
type: string
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
- jsonPath: .status.condition
name: Condition
type: string
name: v1alpha1
- jsonPath: .metadata.creationTimestamp
name: Age
type: date
name: v1alpha2
schema:
openAPIV3Schema:
properties:
Expand All @@ -49,18 +55,24 @@ spec:
properties:
content:
type: string
in:
schedule:
type: string
required:
- content
- in
- schedule
type: object
status:
properties:
condition:
type: string
lastRun:
type: string
nextRun:
type: string
required:
- condition
- lastRun
- nextRun
type: object
type: object
served: true
Expand Down
6 changes: 2 additions & 4 deletions devops.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env bash

export CONTROLLER_GEN_VERSION="v0.15.0"
export GOLANGCI_LINT_VERSION="v1.58.1"
export MOCKERY_GEN_VERSION="v2.42.3"
export GOLANGCI_LINT_VERSION="v1.59.1"
export MOCKERY_GEN_VERSION="v2.44.1"
export GOFUMPT_VERSION="v0.6.0"
export TESTENV_VERSION="1.25.x!"

Expand Down Expand Up @@ -36,8 +36,6 @@ generate() {
rm -rf deploy/crds
controller-gen object paths="./..."
controller-gen crd paths="./..." output:dir=deploy/crds
sed '/Compiled/d' pkg/apis/v1alpha1/zz_generated.deepcopy.go > pkg/apis/v1alpha1/zz_generated.deepcopy.gotmp
mv pkg/apis/v1alpha1/zz_generated.deepcopy.gotmp pkg/apis/v1alpha1/zz_generated.deepcopy.go
crd-ref-docs --source-path=./pkg/apis --config .apidoc.yaml --renderer markdown --output-path=./docs/api.md
mockery
}
Expand Down
14 changes: 8 additions & 6 deletions docs/api.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# API Reference

## Packages
- [cloud.namecheap.com/v1alpha1](#cloudnamecheapcomv1alpha1)
- [cloud.namecheap.com/v1alpha2](#cloudnamecheapcomv1alpha2)


## cloud.namecheap.com/v1alpha1
## cloud.namecheap.com/v1alpha2

Package v1alpha1 contains API Schema definitions for the v1alpha1 API group
Package v1alpha2 contains API Schema definitions for the v1alpha2 API group

### Resource Types
- [ScheduledResource](#scheduledresource)
Expand All @@ -26,7 +26,7 @@ _Appears in:_

| Field | Description |
| --- | --- |
| `Created` | |
| `Finished` | |
| `Scheduled` | |
| `Failed` | |

Expand All @@ -45,7 +45,7 @@ _Appears in:_

| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `apiVersion` _string_ | `cloud.namecheap.com/v1alpha1` | | |
| `apiVersion` _string_ | `cloud.namecheap.com/v1alpha2` | | |
| `kind` _string_ | `ScheduledResource` | | |
| `metadata` _[ObjectMeta](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.25/#objectmeta-v1-meta)_ | Refer to Kubernetes API documentation for fields of `metadata`. | | |
| `spec` _[ScheduledResourceSpec](#scheduledresourcespec)_ | | | |
Expand All @@ -65,7 +65,7 @@ _Appears in:_

| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `in` _string_ | | | |
| `schedule` _string_ | | | |
| `content` _string_ | | | |


Expand All @@ -82,6 +82,8 @@ _Appears in:_

| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `nextRun` _string_ | | | |
| `lastRun` _string_ | | | |
| `condition` _[Condition](#condition)_ | | | |


18 changes: 0 additions & 18 deletions examples/combination.yaml

This file was deleted.

18 changes: 0 additions & 18 deletions examples/exact-duration-combination.yaml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apiVersion: v1
kind: Secret
metadata:
name: expiration-example
name: expiration-duration
namespace: default
annotations:
mayfly.cloud.namecheap.com/expire: "50s"
mayfly.cloud.namecheap.com/expire: "10s"
data:
.secret-file: dmFsdWUtMg0KDQo=
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: v1
kind: Secret
metadata:
name: exact-expiration-example
name: expiration-exact-date
namespace: default
annotations:
mayfly.cloud.namecheap.com/expire: "2024-12-31T00:00:00Z"
Expand Down
14 changes: 14 additions & 0 deletions examples/scheduled-resource-cronjob.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: cloud.namecheap.com/v1alpha2
kind: ScheduledResource
metadata:
name: scheduled-resource-cronjob
spec:
schedule: "*/10 * * * * *" # Creates every 10 second
content: |
apiVersion: v1
kind: Secret
metadata:
name: scheduled-resource-cronjob-example
namespace: default
data:
.secret-file: dmFsdWUtMg0KDQo=
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apiVersion: cloud.namecheap.com/v1alpha1
apiVersion: cloud.namecheap.com/v1alpha2
kind: ScheduledResource
metadata:
name: scheduled-resource-example
name: scheduled-resource-duration
spec:
in: "5s"
schedule: "10s" # Creates in 10 seconds
content: |
apiVersion: v1
kind: Secret
metadata:
name: scheduled-resource-example
name: scheduled-resource-duration-example
namespace: default
data:
.secret-file: dmFsdWUtMg0KDQo=
14 changes: 14 additions & 0 deletions examples/scheduled-resource-exact-date.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: cloud.namecheap.com/v1alpha2
kind: ScheduledResource
metadata:
name: scheduled-resource-exact-date
spec:
schedule: "2024-12-31T00:00:00Z" # Creates at exact date
content: |
apiVersion: v1
kind: Secret
metadata:
name: scheduled-resource-exact-date-example
namespace: default
data:
.secret-file: dmFsdWUtMg0KDQo=
16 changes: 16 additions & 0 deletions examples/scheduled-resource-with-expiration-combination.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
apiVersion: cloud.namecheap.com/v1alpha2
kind: ScheduledResource
metadata:
name: scheduled-resource-with-expiration-combination
spec:
schedule: "*/20 * * * * *" # Creates every 20 seconds
content: |
apiVersion: v1
kind: Secret
metadata:
generateName: scheduled-resource-with-expiration-combination-example-
namespace: default
annotations:
mayfly.cloud.namecheap.com/expire: "10s" # Deletes in 10 seconds after created
data:
.secret-file: dmFsdWUtMg0KDQo=
Loading

0 comments on commit e693400

Please sign in to comment.