Skip to content

Commit

Permalink
Add deletes spec to PrAutomation CRD (#1163)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljguarino authored Jul 10, 2024
1 parent aa48a35 commit a68742b
Show file tree
Hide file tree
Showing 15 changed files with 213 additions and 79 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ ENV HELM_VERSION=v3.10.3
ENV TERRAFORM_VERSION=v1.2.9

# renovate: datasource=github-releases depName=pluralsh/plural-cli
ENV CLI_VERSION=v0.9.4
ENV CLI_VERSION=v0.9.11

# renovate: datasource=github-tags depName=kubernetes/kubernetes
ENV KUBECTL_VERSION=v1.25.5
Expand Down
6 changes: 5 additions & 1 deletion assets/src/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2511,6 +2511,8 @@ export type ManagedNamespace = {
labels?: Maybe<Scalars['Map']['output']>;
/** the name of this namespace once its placed on a cluster */
name: Scalars['String']['output'];
/** override the name of the kubernetes namespace if `name` is not usable */
namespace?: Maybe<Scalars['String']['output']>;
/** a project this global service is bound to */
project?: Maybe<Project>;
/** a list of pull secrets to attach to this namespace */
Expand Down Expand Up @@ -2543,8 +2545,10 @@ export type ManagedNamespaceAttributes = {
description?: InputMaybe<Scalars['String']['input']>;
/** labels for this namespace */
labels?: InputMaybe<Scalars['Json']['input']>;
/** the name of this namespace once its placed on a cluster */
/** the name of this managed namespace (globally unique) */
name: Scalars['String']['input'];
/** the name of the namespace if `name` doesn't align */
namespace?: InputMaybe<Scalars['String']['input']>;
/** a project this managed namespace will sync across */
projectId?: InputMaybe<Scalars['ID']['input']>;
/** a list of pull secrets to attach to this namespace */
Expand Down
44 changes: 30 additions & 14 deletions charts/controller/crds/deployments.plural.sh_prautomations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ spec:
type: object
type: array
creates:
description: Creates ...
description: Specs for files to be templated and created
properties:
git:
description: Git ...
description: Git Location to source external files from
properties:
files:
description: Optional files to add to the manifests for this
Expand All @@ -216,25 +216,40 @@ spec:
- ref
type: object
templates:
description: Templates ...
description: Template files to use to generate file content
items:
description: PrAutomationTemplate ...
properties:
destination:
description: Destination ...
description: The destination to write the file to
type: string
external:
description: External ...
description: Whether it is being sourced from an external
git repository
type: boolean
source:
description: Source ...
description: The source file to use for templating
type: string
required:
- destination
- external
type: object
type: array
type: object
deletes:
description: Spec for files and folders to be deleted
properties:
files:
description: Individual files to delete
items:
type: string
type: array
folders:
description: Entire folders to delete
items:
type: string
type: array
type: object
documentation:
description: Documentation ...
type: string
Expand Down Expand Up @@ -392,26 +407,27 @@ spec:
description: Title...
type: string
updates:
description: Updates ...
description: Spec for files to be updated, using regex replacement
properties:
files:
description: Files ...
description: Files to update
items:
type: string
type: array
matchStrategy:
description: MatchStrategy ...
description: MatchStrategy, see enum for behavior
type: string
regexReplacements:
description: RegexReplacements ...
description: Full regex + replacement structs in case there is
different behavior per regex
items:
description: RegexReplacement ...
properties:
file:
description: The file this replacement will work on
type: string
regex:
description: Regex ...
description: The regex to match a substring on
type: string
replacement:
description: Replacement to be substituted for the match
Expand All @@ -428,15 +444,15 @@ spec:
type: object
type: array
regexes:
description: Regexes ...
description: The regexes to apply on each file
items:
type: string
type: array
replaceTemplate:
description: ReplaceTemplate ...
description: The template to use when replacing a regex
type: string
yq:
description: Yq ...
description: (Unused so far)
type: string
type: object
type: object
Expand Down
54 changes: 40 additions & 14 deletions controller/api/v1alpha1/prautomation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func (in *PrAutomation) Attributes(clusterID *string, serviceID *string, connect
Branch: in.Spec.Branch,
Updates: in.Spec.Updates.Attributes(),
Creates: in.Spec.Creates.Attributes(),
Deletes: in.Spec.Deletes.Attributes(),
Addon: in.Spec.Addon,
ClusterID: clusterID,
ServiceID: serviceID,
Expand Down Expand Up @@ -167,22 +168,47 @@ type PrAutomationSpec struct {
// +kubebuilder:validation:Optional
Configuration []PrAutomationConfiguration `json:"configuration,omitempty"`

// Creates ...
// Specs for files to be templated and created
// +kubebuilder:validation:Optional
Creates *PrAutomationCreateConfiguration `json:"creates,omitempty"`

// Updates ...
// Spec for files to be updated, using regex replacement
// +kubebuilder:validation:Optional
Updates *PrAutomationUpdateConfiguration `json:"updates,omitempty"`

// Spec for files and folders to be deleted
// +kubebuilder:validation:Optional
Deletes *PrAutomationDeleteConfiguration `json:"deletes,omitempty"`
}

type PrAutomationDeleteConfiguration struct {
// Individual files to delete
// +kubebuilder:validation:Optional
Files []string `json:"files"`

// Entire folders to delete
// +kubebuilder:validation:Optional
Folders []string `json:"folders"`
}

func (in *PrAutomationDeleteConfiguration) Attributes() *console.PrAutomationDeleteSpecAttributes {
if in == nil {
return nil
}

return &console.PrAutomationDeleteSpecAttributes{
Files: in.Files,
Folders: in.Folders,
}
}

// PrAutomationCreateConfiguration ...
type PrAutomationCreateConfiguration struct {
// Git ...
// Git Location to source external files from
// +kubebuilder:validation:Optional
Git *GitRef `json:"git,omitempty"`

// Templates ...
// Template files to use to generate file content
// +kubebuilder:validation:Optional
Templates []PrAutomationTemplate `json:"templates,omitempty"`
}
Expand All @@ -202,15 +228,15 @@ func (in *PrAutomationCreateConfiguration) Attributes() *console.PrAutomationCre

// PrAutomationTemplate ...
type PrAutomationTemplate struct {
// Destination ...
// The destination to write the file to
// +kubebuilder:validation:Required
Destination string `json:"destination"`

// External ...
// Whether it is being sourced from an external git repository
// +kubebuilder:validation:Required
External bool `json:"external"`

// Source ...
// The source file to use for templating
// +kubebuilder:validation:Optional
Source string `json:"source"`
}
Expand All @@ -229,27 +255,27 @@ func (in *PrAutomationTemplate) Attributes() *console.PrAutomationTemplateAttrib

// PrAutomationUpdateConfiguration ...
type PrAutomationUpdateConfiguration struct {
// Files ...
// Files to update
// +kubebuilder:validation:Optional
Files []*string `json:"files,omitempty"`

// MatchStrategy ...
// MatchStrategy, see enum for behavior
// +kubebuilder:validation:Optional
MatchStrategy *console.MatchStrategy `json:"matchStrategy,omitempty"`

// RegexReplacements ...
// Full regex + replacement structs in case there is different behavior per regex
// +kubebuilder:validation:Optional
RegexReplacements []RegexReplacement `json:"regexReplacements,omitempty"`

// Regexes ...
// The regexes to apply on each file
// +kubebuilder:validation:Optional
Regexes []*string `json:"regexes,omitempty"`

// ReplaceTemplate ...
// The template to use when replacing a regex
// +kubebuilder:validation:Optional
ReplaceTemplate *string `json:"replaceTemplate,omitempty"`

// Yq ...
// (Unused so far)
// +kubebuilder:validation:Optional
Yq *string `json:"yq,omitempty"`
}
Expand All @@ -273,7 +299,7 @@ func (in *PrAutomationUpdateConfiguration) Attributes() *console.PrAutomationUpd

// RegexReplacement ...
type RegexReplacement struct {
// Regex ...
// The regex to match a substring on
// +kubebuilder:validation:Required
Regex string `json:"regex"`

Expand Down
30 changes: 30 additions & 0 deletions controller/api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a68742b

Please sign in to comment.