Files
argo-cd/util/lua/impacted_resource.go
reggie-k 9d904ae7c0 feat: Create job action (#12174 and #4116) (#12925)
* Kind wildcard support in health customizations

Signed-off-by: reggie <reginakagan@gmail.com>

* Updated health customizations docs to using the correct field with a /

Signed-off-by: reggie <reginakagan@gmail.com>

* Updated health customizations docs to using the correct field with a /

Signed-off-by: reggie <reginakagan@gmail.com>

* Document resource kind wildcard for custom health check

Signed-off-by: reggie <reginakagan@gmail.com>

* Implemented wildcard * support in API Group and Resource Kind and updated docs

Signed-off-by: reggie <reginakagan@gmail.com>

* Implemented wildcard * support in API Group and Resource Kind and updated docs

Signed-off-by: reggie <reginakagan@gmail.com>

* Implemented wildcard * support in API Group and Resource Kind and updated docs

Signed-off-by: reggie <reginakagan@gmail.com>

* Added a custom create-from CronJob action

Signed-off-by: reggie <reginakagan@gmail.com>

* in progress

Signed-off-by: reggie <reginakagan@gmail.com>

* in progress

Signed-off-by: reggie <reginakagan@gmail.com>

* in progress

Signed-off-by: reggie <reginakagan@gmail.com>

* in progress

Signed-off-by: reggie <reginakagan@gmail.com>

* added a ns in the action.lua and fixed tests

Signed-off-by: reggie <reginakagan@gmail.com>

* create-job

Signed-off-by: reggie <reginakagan@gmail.com>

* in progress

Signed-off-by: reggie <reginakagan@gmail.com>

* more changes

Signed-off-by: reggie <reginakagan@gmail.com>

* full unit tests and action returning an array

Signed-off-by: reggie <reginakagan@gmail.com>

* cleanup

Signed-off-by: reggie <reginakagan@gmail.com>

* fix the custom tests

Signed-off-by: reggie <reginakagan@gmail.com>

* e2e tests

Signed-off-by: reggie <reginakagan@gmail.com>

* json marshaling annotations ImpactedResource, e2e tests and docs

Signed-off-by: reggie <reginakagan@gmail.com>

* more docs and tests

Signed-off-by: reggie <reginakagan@gmail.com>

* upstream sync

Signed-off-by: reggie <reginakagan@gmail.com>

* fix wrong return upon going over the impacted resources + docs + fixing e2e tests

Signed-off-by: reggie <reginakagan@gmail.com>

* docs

Signed-off-by: reggie <reginakagan@gmail.com>

* better error handling

Signed-off-by: reggie <reginakagan@gmail.com>

* K8SOperation as an enum

Signed-off-by: reggie <reginakagan@gmail.com>

* added dry-run for create operation

Signed-off-by: reggie <reginakagan@gmail.com>

* small changes

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* ref to my gitops-engine fork out

Signed-off-by: reggie <reginakagan@gmail.com>

* ref to my gitops-engine fork out

Signed-off-by: reggie <reginakagan@gmail.com>

* ref to my gitops-engine fork out

Signed-off-by: reggie <reginakagan@gmail.com>

* ref to my gitops-engine fork out

Signed-off-by: reggie <reginakagan@gmail.com>

* ref to my gitops-engine fork out

Signed-off-by: reggie <reginakagan@gmail.com>

* gitops engine dependency and test fixes

Signed-off-by: reggie <reginakagan@gmail.com>

* add workflows action

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* cronworkflow and workflowtemplate actions

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* update gitops-engine

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

---------

Signed-off-by: reggie <reginakagan@gmail.com>
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
2023-06-23 14:45:53 -04:00

51 lines
1.7 KiB
Go

package lua
import (
"fmt"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
// This struct represents a wrapper, that is returned from Lua custom action script, around the unstructured k8s resource + a k8s operation
// that will need to be performed on this returned resource.
// Currently only "create" and "patch" operations are supported for custom actions.
// This replaces the traditional architecture of "Lua action returns the source resource for ArgoCD to patch".
// This enables ArgoCD to create NEW resources upon custom action.
// Note that the Lua code in the custom action is coupled to this type, since Lua json output is then unmarshalled to this struct.
// Avoided using iota, since need the mapping of the string value the end users will write in Lua code ("create" and "patch").
// TODO: maybe there is a nicer general way to marshal and unmarshal, instead of explicit iteration over the enum values.
type K8SOperation string
const (
CreateOperation K8SOperation = "create"
PatchOperation K8SOperation = "patch"
)
type ImpactedResource struct {
UnstructuredObj *unstructured.Unstructured `json:"resource"`
K8SOperation K8SOperation `json:"operation"`
}
func (op *K8SOperation) UnmarshalJSON(data []byte) error {
switch string(data) {
case `"create"`:
*op = CreateOperation
case `"patch"`:
*op = PatchOperation
default:
return fmt.Errorf("unsupported operation: %s", data)
}
return nil
}
func (op K8SOperation) MarshalJSON() ([]byte, error) {
switch op {
case CreateOperation:
return []byte(`"create"`), nil
case PatchOperation:
return []byte(`"patch"`), nil
default:
return nil, fmt.Errorf("unsupported operation: %s", op)
}
}