Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customform refactor #125

Open
braghettos opened this issue Oct 22, 2024 · 1 comment
Open

Customform refactor #125

braghettos opened this issue Oct 22, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@braghettos
Copy link
Member

Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like
A clear and concise description of what you want to happen.

Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.

Additional context
Add any other context or screenshots about the feature request here.

@braghettos braghettos added the enhancement New feature or request label Oct 22, 2024
@braghettos braghettos self-assigned this Oct 22, 2024
@braghettos
Copy link
Member Author

braghettos commented Oct 22, 2024

CustomForm

This is the new customform:

{
    "apiVersion": "templates.krateo.io/v1alpha1",
    "kind": "CustomForm",
    "metadata": {
        "annotations": {
            "kubectl.kubernetes.io/last-applied-configuration": "{\"apiVersion\":\"templates.krateo.io/v1alpha1\",\"kind\":\"CustomForm\",\"metadata\":{\"annotations\":{},\"name\":\"fireworksapp-tgz-customform\",\"namespace\":\"demo-system\"},\"spec\":{\"actions\":[{\"template\":{\"apiVersion\":\"composition.krateo.io/v1-1-6\",\"name\":\"submit\",\"payloadToOverride\":[{\"name\":\"metadata.name\",\"value\":\"${ git.toRepo.name }\"},{\"name\":\"metadata.namespace\",\"value\":\"${ git.toRepo.name + \\\"-ns\\\" }\"}],\"resource\":\"fireworksapps\",\"verb\":\"POST\"}}],\"api\":[{\"headers\":[\"Accept: application/json\"],\"name\":\"getCRD\",\"path\":\"/apis/apiextensions.k8s.io/v1/customresourcedefinitions/fireworksapps.composition.krateo.io\",\"verb\":\"GET\"},{\"headers\":[\"Accept: application/json\"],\"name\":\"getNamespaces\",\"path\":\"/api/v1/namespaces\",\"verb\":\"GET\"}],\"app\":{\"template\":{\"propertiesToHide\":[\"argocd\",\"git.properties.fromRepo\",\"git.required[] | select(. == \\\"fromRepo\\\")\"],\"propertiesToOverride\":[{\"name\":\"git.properties.toRepo.properties.deletionPolicy.default\",\"value\":\"${ [.getNamespaces | .items[].metadata.name][1] | tojson }\"},{\"name\":\"git.properties.toRepo.properties.deletionPolicy.enum\",\"value\":\"${ [.getNamespaces | .items[].metadata.name] }\"}],\"schema\":\"${ .getCRD | .spec.versions[] | select(.name == \\\"v1-1-6\\\") | .schema.openAPIV3Schema.properties.spec.properties }\"}},\"propsRef\":{\"name\":\"fireworksapp-tgz-customform\",\"namespace\":\"demo-system\"},\"type\":\"customform\"}}\n"
        },
        "creationTimestamp": "2024-10-22T08:55:40Z",
        "name": "fireworksapp-tgz-customform",
        "namespace": "demo-system",
        "resourceVersion": "3097",
        "uid": "987fcbb0-356e-4737-86a0-895b7c7f43bf"
    },
    "spec": {
        "actions": [
            {
                "template": {
                    "apiVersion": "composition.krateo.io/v1-1-6",
                    "name": "submit",
                    "payloadToOverride": [
                        {
                            "name": "metadata.name",
                            "value": "${ git.toRepo.name }"
                        },
                        {
                            "name": "metadata.namespace",
                            "value": "${ git.toRepo.name + \"-ns\" }"
                        }
                    ],
                    "resource": "fireworksapps",
                    "verb": "POST"
                }
            }
        ],
        "api": [
            {
                "headers": [
                    "Accept: application/json"
                ],
                "name": "getCRD",
                "path": "/apis/apiextensions.k8s.io/v1/customresourcedefinitions/fireworksapps.composition.krateo.io",
                "verb": "GET"
            },
            {
                "headers": [
                    "Accept: application/json"
                ],
                "name": "getNamespaces",
                "path": "/api/v1/namespaces",
                "verb": "GET"
            }
        ],
        "app": {
            "template": {
                "propertiesToHide": [
                    "argocd",
                    "git.properties.fromRepo",
                    "git.required[] | select(. == \"fromRepo\")"
                ],
                "propertiesToOverride": [
                    {
                        "name": "git.properties.toRepo.properties.deletionPolicy.default",
                        "value": "${ [.getNamespaces | .items[].metadata.name][1] | tojson }"
                    },
                    {
                        "name": "git.properties.toRepo.properties.deletionPolicy.enum",
                        "value": "${ [.getNamespaces | .items[].metadata.name] }"
                    }
                ],
                "schema": "${ .getCRD | .spec.versions[] | select(.name == \"v1-1-6\") | .schema.openAPIV3Schema.properties.spec.properties }"
            }
        },
        "propsRef": {
            "name": "fireworksapp-tgz-customform",
            "namespace": "demo-system"
        },
        "type": "customform"
    },
    "status": {
        "actions": [
            {
                "template": {
                    "apiVersion": "composition.krateo.io/v1-1-6",
                    "name": "submit",
                    "path": "/call?verb=post\u0026resource=fireworksapps\u0026uri=/apis/composition.krateo.io/v1-1-6",
                    "payloadToOverride": [
                        {
                            "name": "metadata.name",
                            "value": "${ git.toRepo.name }"
                        },
                        {
                            "name": "metadata.namespace",
                            "value": "${ git.toRepo.name + \"-ns\" }"
                        }
                    ],
                    "resource": "fireworksapps",
                    "verb": "post"
                }
            }
        ],
        "content": {
            "schema": {
                "app": {
                    "properties": {
                        "service": {
                            "properties": {
                                "port": {
                                    "default": 31180,
                                    "maximum": 32767,
                                    "minimum": 30000,
                                    "type": "integer"
                                },
                                "type": {
                                    "default": "NodePort",
                                    "enum": [
                                        "NodePort",
                                        "LoadBalancer"
                                    ],
                                    "type": "string"
                                }
                            },
                            "required": [
                                "port",
                                "type"
                            ],
                            "type": "object"
                        }
                    },
                    "required": [
                        "service"
                    ],
                    "type": "object"
                },
                "git": {
                    "properties": {
                        "deletionPolicy": {
                            "default": "Orphan",
                            "enum": [
                                "Delete",
                                "Orphan"
                            ],
                            "type": "string"
                        },
                        "insecure": {
                            "default": true,
                            "type": "boolean"
                        },
                        "toRepo": {
                            "properties": {
                                "apiUrl": {
                                    "default": "https://api.github.com",
                                    "type": "string"
                                },
                                "branch": {
                                    "default": "main",
                                    "type": "string"
                                },
                                "credentials": {
                                    "properties": {
                                        "authMethod": {
                                            "default": "basic",
                                            "enum": [
                                                "basic",
                                                "bearer"
                                            ],
                                            "type": "string"
                                        },
                                        "secretRef": {
                                            "properties": {
                                                "key": {
                                                    "default": "token",
                                                    "type": "string"
                                                },
                                                "name": {
                                                    "default": "github-repo-creds",
                                                    "type": "string"
                                                },
                                                "namespace": {
                                                    "default": "krateo-system",
                                                    "type": "string"
                                                }
                                            },
                                            "required": [
                                                "key",
                                                "name",
                                                "namespace"
                                            ],
                                            "type": "object"
                                        }
                                    },
                                    "required": [
                                        "authMethod",
                                        "secretRef"
                                    ],
                                    "type": "object"
                                },
                                "deletionPolicy": {
                                    "default": "demo-system",
                                    "enum": [
                                        "default",
                                        "demo-system",
                                        "fireworks-app",
                                        "fireworksapp-system",
                                        "krateo-system",
                                        "kube-node-lease",
                                        "kube-public",
                                        "kube-system"
                                    ],
                                    "type": "string"
                                },
                                "initialize": {
                                    "default": true,
                                    "type": "boolean"
                                },
                                "name": {
                                    "default": "fireworksapp-test-v2",
                                    "type": "string"
                                },
                                "org": {
                                    "default": "krateoplatformops-archive",
                                    "type": "string"
                                },
                                "path": {
                                    "default": "/",
                                    "type": "string"
                                },
                                "private": {
                                    "default": false,
                                    "type": "boolean"
                                },
                                "scmUrl": {
                                    "default": "https://github.com",
                                    "type": "string"
                                }
                            },
                            "required": [
                                "apiUrl",
                                "branch",
                                "credentials",
                                "deletionPolicy",
                                "initialize",
                                "name",
                                "org",
                                "path",
                                "private",
                                "scmUrl"
                            ],
                            "type": "object"
                        },
                        "unsupportedCapabilities": {
                            "default": true,
                            "type": "boolean"
                        }
                    },
                    "required": [
                        "deletionPolicy",
                        "insecure",
                        "toRepo",
                        "unsupportedCapabilities"
                    ],
                    "type": "object"
                }
            }
        },
        "name": "fireworksapp-tgz-customform",
        "props": {
            "description": "The co-inventor of YAML",
            "onSubmitName": "submit",
            "onSubmitVerb": "POST",
            "title": "Brian Ingerson"
        },
        "type": "customform",
        "uid": "987fcbb0-356e-4737-86a0-895b7c7f43bf"
    }
}

Please note:

  1. in the status.props there are onSubmitVerb and onSubmitName which the frontend will use to look into status.actions the template that has status.actions[].template.name = status.props.onSubmitName and status.actions[].template.verb = status.props.onSubmitVerb
  2. when the frontend submits the form payload, the frontend must check the status.actions[].template.payloadToOverride that eventually will contain keys to add (if missing in the payload) or override (if already available in the payload) to the form payload

New backend APIs

The legacy backend API can be called in the following way:

curl 'http://48.209.154.250:8081/call?uri=/apis/templates.krateo.io/v1alpha1/namespaces/krateo-system/collections/templates-row' \
  -H 'x-krateo-groups: admins' \
  -H 'x-krateo-user: admin' \
  --insecure

This is the new API that requires a payload and the query parameters have changed:

curl -v \
  -H 'Referer: http://48.209.154.250:8081' \
  -H 'x-krateo-user: admin' \
  -H 'x-krateo-groups: admins' \
  -H 'Content-Type: application/json' \
  -d '{"apiVersion":"templates.krateo.io/v1alpha1","kind":"Collection","metadata":{"name":"templates-row","namespace":"krateo-system"}}' \
  "http://48.209.154.250:8081/call?verb=get&resource=collections&uri=/apis/templates.krateo.io/v1alpha1/"

@braghettos braghettos assigned codev99 and unassigned braghettos Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants