Skip to content

Commit

Permalink
Merge pull request crossplane-contrib#12 from humoflife/deprecate-con…
Browse files Browse the repository at this point in the history
…fig-map-support

deprecate config map support
  • Loading branch information
humoflife authored Apr 23, 2024
2 parents 8cd3370 + 0c75deb commit 9c06a64
Show file tree
Hide file tree
Showing 16 changed files with 12 additions and 310 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
REPO_URL="xpkg.upbound.io/crossplane-contrib/function-shell"
VERSION_TAG="v0.0.6"
VERSION_TAG="v0.1.0"

#PACKAGE_FILES="function-amd64.xpkg,function-arm64.xpkg"
PACKAGE_FILES="function-arm64.xpkg"
Expand Down Expand Up @@ -45,9 +45,9 @@ test: ## Run Code Tests

render: ## Render Examples, Requires make debug first
crossplane beta render \
example/out-of-cluster/xr.yaml \
example/out-of-cluster/composition.yaml \
example/out-of-cluster/functions.yaml
example/xr.yaml \
example/composition.yaml \
example/functions.yaml

debug: ## Run Shell Function For Rendering Examples
go run . --insecure --debug
44 changes: 5 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ is expected to follow the above pattern.
The `function-shell` accepts commands to run in a shell and it
returns the output to specified fields. It accepts the following parameters:

- `shellScriptsConfigMapsRef` - referencing at least one Kubernetes
[`ConfigMap`](https://kubernetes.io/docs/concepts/configuration/configmap/)
with at least one shell script. This script can be written in an arbitrary
shell language, for example bash or python3.
- `shellEnvVarsSecretRef` - referencing environment variables in a
Kubernetes secret. `shellEnvVarsSecretRef` requires a `name`, a
`namespace` and a `key` for the secret. Inside of it, the shell
Expand Down Expand Up @@ -76,32 +72,6 @@ kubectl create clusterrolebinding function-shell-admin-binding \
--serviceaccount="${SA}"
```

The composition reads a `ConfigMap` that contains 2 example scripts.
When you experiment with scripts in ConfigMaps, apply the yaml to the
desired namespace, e.g. `kubectl -n crossplane-system apply -f
example/in-cluster/configmap.yaml`. It is recommended to use
the namespace where the `function-shell` pod is running.

```yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: function-shell-script
data:
hello-from-python.py: |
#!/usr/bin/python3
print ( "hello from python" )
get-datadog-dashboard-ids.sh: |
#!/bin/bash
curl -X GET "${DATADOG_API_URL}" \
-H "Accept: application/json" \
-H "DD-API-KEY: ${DATADOG_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DATADOG_APP_KEY}"|\
jq '.dashboards[] .id';
```
The composition reads a datadog secret that looks like below.
Replace `YOUR_API_KEY` and `YOUR_APP_KEY` with your respective keys.

Expand Down Expand Up @@ -130,13 +100,6 @@ spec:
input:
apiVersion: shell.fn.crossplane.io/v1beta1
kind: Parameters
shellScriptsConfigMapsRef:
- scriptNames:
- hello-from-python.py
- get-datadog-dashboard-ids.sh
name: function-shell-script
namespace: upbound-system
shellEnvVarsSecretRef:
name: datadog-secret
namespace: upbound-system
Expand All @@ -145,8 +108,11 @@ spec:
- key: DATADOG_API_URL
value: "https://api.datadoghq.com/api/v1/dashboard"
shellCommand: |
/scripts/get-datadog-dashboard-ids.sh
python3 /scripts/hello-from-python.py|awk '{print $3}'|tr "p" "P"
curl -X GET "${DATADOG_API_URL}" \
-H "Accept: application/json" \
-H "DD-API-KEY: ${DATADOG_API_KEY}" \
-H "DD-APPLICATION-KEY: ${DATADOG_APP_KEY}"|\
jq '.dashboards[] .id';
stdoutField: status.atFunction.shell.stdout
stderrField: status.atFunction.shell.stderr
```
Expand Down
File renamed without changes.
File renamed without changes.
37 changes: 0 additions & 37 deletions example/in-cluster/composition.yaml

This file was deleted.

17 changes: 0 additions & 17 deletions example/in-cluster/configmap.yaml

This file was deleted.

30 changes: 0 additions & 30 deletions example/in-cluster/definition.yaml

This file was deleted.

8 changes: 0 additions & 8 deletions example/in-cluster/functions.yaml

This file was deleted.

6 changes: 0 additions & 6 deletions example/in-cluster/shell-claim.yaml

This file was deleted.

File renamed without changes.
25 changes: 2 additions & 23 deletions fn.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,27 +70,6 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1beta1.RunFunctionRequ
stderrField = "status.atFunction.shell.stderr"
}

var shellScripts map[string][]string
if in.ShellScriptsConfigMapsRef != nil {
shellScripts, err = loadShellScripts(log, in.ShellScriptsConfigMapsRef)
if err != nil {
response.Fatal(rsp, errors.Wrapf(err, "cannot process shell script ConfigMaps"))
return rsp, nil
}
}

copyShellScripts := ""
if len(shellScripts) > 0 {
for shellScriptName, shellScript := range shellScripts {
copyShellScripts = "rm -f ./scripts/" + shellScriptName + ";"
for _, line := range shellScript {
escapedLine := strings.ReplaceAll(line, "'", "\"'\"")
copyShellScripts = copyShellScripts + "echo '" + escapedLine + "'>> ./scripts/" + shellScriptName + ";"
}
copyShellScripts = copyShellScripts + "/bin/chmod +x ./scripts/" + shellScriptName + ";"
}
}

shellCmd := ""
if len(in.ShellCommand) == 0 && len(in.ShellCommandField) == 0 {
log.Info("no shell command in in.ShellCommand nor in.ShellCommandField")
Expand Down Expand Up @@ -128,7 +107,7 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1beta1.RunFunctionRequ
log.Info(shellCmd)

var stdout, stderr bytes.Buffer
cmd := shell.Commandf(exportCmds + copyShellScripts + shellCmd)
cmd := shell.Commandf(exportCmds + shellCmd)
cmd.Stdout = &stdout
cmd.Stderr = &stderr
err = cmd.Run()
Expand All @@ -153,4 +132,4 @@ func (f *Function) RunFunction(_ context.Context, req *fnv1beta1.RunFunctionRequ
}

return rsp, nil
}
}
14 changes: 0 additions & 14 deletions input/v1alpha1/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ type Parameters struct {
// +optional
ShellEnvVars []ShellEnvVar `json:"shellEnvVars,omitempty"`

// shellScriptFiles
// +optional
ShellScriptsConfigMapsRef []ShellScriptsConfigMapRef `json:"shellScriptsConfigMapsRef"`

// shellCmd
// +optional
ShellCommand string `json:"shellCommand,omitempty"`
Expand Down Expand Up @@ -61,13 +57,3 @@ type ShellEnvVarsSecretRef struct {
// Namespace where Kubernetes secret resides
Namespace string `json:"namespace,omitempty"`
}

type ShellScriptsConfigMapRef struct {
// The name of the script entries in a ConfigMap
// Each ConfigMap can contain multiple scripts
ScriptNames []string `json:"scriptNames,omitempty"`
// Name of Kubernetes ConfigMap
Name string `json:"name,omitempty"`
// Namespace where Kubernetes ConfigMap resides
Namespace string `json:"namespace,omitempty"`
}
27 changes: 0 additions & 27 deletions input/v1alpha1/zz_generated.deepcopy.go

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

21 changes: 1 addition & 20 deletions package/input/template.fn.crossplane.io_parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,25 +67,6 @@ spec:
description: Namespace where Kubernetes secret resides
type: string
type: object
shellScriptsConfigMapsRef:
description: shellScriptFiles
items:
properties:
name:
description: Name of Kubernetes ConfigMap
type: string
namespace:
description: Namespace where Kubernetes ConfigMap resides
type: string
scriptNames:
description: |-
The name of the script entries in a ConfigMap
Each ConfigMap can contain multiple scripts
items:
type: string
type: array
type: object
type: array
stderrField:
description: stderrField
type: string
Expand All @@ -94,4 +75,4 @@ spec:
type: string
type: object
served: true
storage: true
storage: true
Loading

0 comments on commit 9c06a64

Please sign in to comment.