Skip to content

Commit

Permalink
LocalScript resource (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
fraliv13 authored Nov 22, 2024
1 parent e7d90ce commit 0d39153
Show file tree
Hide file tree
Showing 32 changed files with 1,776 additions and 177 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.20'
go-version: '1.21'

- name: Build
run: make build-linux
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: '1.20'
go-version: '1.21'

- name: Set release version
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/v}" >> $GITHUB_ENV
Expand Down
2 changes: 1 addition & 1 deletion GenerateCRD.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Prerequisites

1. Install go v1.20 from [here](https://golang.org/doc/install)
1. Install go v1.21 from [here](https://golang.org/doc/install)

2. Install make
```bash
Expand Down
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,62 @@ spec:
target:
category: Tenant
```
### LocalScript

`LocalScript` is a Custom Resource Definition (CRD) that represents a script that executes locally.

Definition can be found [here](./helm/crds/provisioning.totalsoft.ro_localscripts.yaml)

## Spec

The `LocalScript` spec has the following fields:

- `createScriptContent`: Script that runs on resource creation and update.
- `deleteScriptContent`: Script that runs on resource deletion.
- `shell`: The shell to use to run the script. Can be `bash` or `pwsh`.
- `environment`: The environment variables to be passed to the script. It can contain placeholders like `{{ .Tenant.Code }}` or `{{ .Platform }}`.
- `workingDir`: The working directory where the script will be executed.
- `forceUpdateTag`: Update this value to trigger the script even if the content or environment are unchanged. Caution: it performs delete-replace and triggers the Delete script.
- `domainRef`: The reference to the domain that the user belongs to.
- `platformRef`: The reference to the platform that the user belongs to.
- `target`: The target of the script. Can be `Tenant` or `Platform`.
- `exports`: The exports of the script.
- `dependsOn`: The dependencies of the script.

## Example

Here's an example of a `LocalScript` resource:

```yaml
apiVersion: provisioning.totalsoft.ro/v1alpha1
kind: LocalScript
metadata:
name: prepare-data
namespace: provisioning-test
spec:
createScriptContent: |
Get-Date
Get-Location
Write-Host "Env1: " $env:env1
Write-Host "Tenant:" $env:tenant
deleteScriptContent: Write-Host "Deleted"
shell: pwsh
forceUpdateTag: '3'
domainRef: domain1
workingDir: c:/temp
environment:
env1: env1Val2
tenant: '{{ .Tenant.Code }}'
exports:
- domain: domain1
scriptOutput:
toConfigMap:
keyTemplate: MultiTenancy__Tenants__{{ .Tenant.Code }}__ScriptOutput
platformRef: provisioning.test
target:
category: Tenant
```



## configuration.totalsoft.ro
Expand Down
17 changes: 12 additions & 5 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
FROM alpine:latest as alpine
FROM alpine:latest as builder
RUN apk add -U --no-cache ca-certificates curl
RUN curl -fsSL https://get.pulumi.com | sh
#RUN /root/.pulumi/bin/pulumi plugin install resource azure-native 1.60.0

FROM gcr.io/distroless/base:debug-nonroot
FROM alpine:latest
ARG PKG_FILES
WORKDIR /
COPY --from=alpine /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=alpine --chown=nonroot /root/.pulumi/ /home/nonroot/.pulumi/
COPY --chown=nonroot /$PKG_FILES /

RUN apk add -U --no-cache powershell bash

RUN addgroup -g 1300 -S nonroot \
&& adduser -u 1300 -S nonroot -G nonroot

COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder --chown=nonroot /root/.pulumi/ /home/nonroot/.pulumi/
COPY --chown=nonroot /$PKG_FILES /
ENV PATH="/home/nonroot/.pulumi/bin:${PATH}"
USER nonroot
97 changes: 53 additions & 44 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
module totalsoft.ro/platform-controllers

go 1.20
go 1.21

toolchain go1.22.9

require (
dario.cat/mergo v1.0.0
github.com/blang/semver v3.5.1+incompatible
github.com/fluxcd/helm-controller/api v0.33.0
github.com/google/uuid v1.3.0
github.com/google/uuid v1.6.0
github.com/hashicorp/vault/api v1.9.1
github.com/hashicorp/vault/api/auth/kubernetes v0.4.0
github.com/json-iterator/go v1.1.12
Expand All @@ -19,14 +21,15 @@ require (
github.com/pulumi/pulumi-azure-native-sdk/sql/v2 v2.4.0
github.com/pulumi/pulumi-azure-native-sdk/storage/v2 v2.4.0
github.com/pulumi/pulumi-azuread/sdk/v5 v5.38.0
github.com/pulumi/pulumi-command/sdk v1.0.1
github.com/pulumi/pulumi-kubernetes/sdk/v3 v3.28.1
github.com/pulumi/pulumi-random/sdk/v4 v4.13.2
github.com/pulumi/pulumi-vault/sdk/v5 v5.11.0
github.com/pulumi/pulumi/sdk/v3 v3.84.0
github.com/pulumi/pulumi/sdk/v3 v3.122.0
github.com/pulumiverse/pulumi-mssql/sdk v0.0.8
github.com/stretchr/testify v1.8.1
google.golang.org/grpc v1.57.0
google.golang.org/protobuf v1.31.0
github.com/stretchr/testify v1.9.0
google.golang.org/grpc v1.63.2
google.golang.org/protobuf v1.33.0
k8s.io/api v0.27.2
k8s.io/apiextensions-apiserver v0.27.2
k8s.io/apimachinery v0.27.2
Expand All @@ -38,21 +41,22 @@ require (
)

require (
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20221026131551-cf6655e29de4 // indirect
github.com/acomagu/bufpipe v1.0.3 // indirect
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect
github.com/agext/levenshtein v1.2.1 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/cenkalti/backoff/v3 v3.0.0 // indirect
github.com/cenkalti/backoff/v3 v3.2.2 // indirect
github.com/charmbracelet/bubbles v0.16.1 // indirect
github.com/charmbracelet/bubbletea v0.24.2 // indirect
github.com/charmbracelet/bubbletea v0.25.0 // indirect
github.com/charmbracelet/lipgloss v0.7.1 // indirect
github.com/cheggaaa/pb v1.0.29 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/djherbis/times v1.5.0 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
Expand All @@ -61,88 +65,94 @@ require (
github.com/fluxcd/pkg/apis/kustomize v1.0.0 // indirect
github.com/fluxcd/pkg/apis/meta v1.0.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.4.0 // indirect
github.com/go-git/go-git/v5 v5.6.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-git/go-git/v5 v5.12.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/glog v1.1.0 // indirect
github.com/golang/glog v1.2.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-retryablehttp v0.6.6 // indirect
github.com/hashicorp/go-retryablehttp v0.7.1 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.6 // indirect
github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect
github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/hcl/v2 v2.16.1 // indirect
github.com/hashicorp/hcl/v2 v2.17.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.0 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.1 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/nxadm/tail v1.4.11 // indirect
github.com/opentracing/basictracer-go v1.1.0 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pgavlin/fx v0.1.6 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pkg/term v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 // indirect
github.com/pulumi/esc v0.9.1 // indirect
github.com/pulumi/pulumi-azure-native-sdk/v2 v2.4.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/sabhiram/go-gitignore v0.0.0-20210923224102-525f6e181f06 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/skeema/knownhosts v1.1.0 // indirect
github.com/spf13/cobra v1.6.1 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/texttheater/golang-levenshtein v1.0.1 // indirect
github.com/tweekmonster/luser v0.0.0-20161003172636-3fa38070dbd7 // indirect
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/zclconf/go-cty v1.12.1 // indirect
github.com/zclconf/go-cty v1.13.2 // indirect
go.uber.org/atomic v1.10.0 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.8.0 // indirect
golang.org/x/term v0.8.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230706204954-ccb25ca9f130 // indirect
golang.org/x/tools v0.22.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240311173647-c811ad7063a7 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
Expand All @@ -152,5 +162,4 @@ require (
sigs.k8s.io/controller-runtime v0.14.6 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
sourcegraph.com/sourcegraph/appdash v0.0.0-20211028080628-e2786a622600 // indirect
)
Loading

0 comments on commit 0d39153

Please sign in to comment.