github.com/crossplane-contrib/function-cue@v0.2.2-0.20240508161918-5100fcb5a058/input/v1beta1/input.go (about)

     1  // Licensed to Elasticsearch B.V. under one or more contributor
     2  // license agreements. See the NOTICE file distributed with
     3  // this work for additional information regarding copyright
     4  // ownership. Elasticsearch B.V. licenses this file to you under
     5  // the Apache License, Version 2.0 (the "License"); you may
     6  // not use this file except in compliance with the License.
     7  // You may obtain a copy of the License at
     8  //
     9  //     http://www.apache.org/licenses/LICENSE-2.0
    10  //
    11  // Unless required by applicable law or agreed to in writing,
    12  // software distributed under the License is distributed on an
    13  // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    14  // KIND, either express or implied.  See the License for the
    15  // specific language governing permissions and limitations
    16  // under the License.
    17  
    18  // Package v1beta1 contains the input type for the cue function runner.
    19  // +kubebuilder:object:generate=true
    20  // +groupName=cue.fn.crossplane.io
    21  // +versionName=v1beta1
    22  package v1beta1
    23  
    24  import (
    25  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    26  )
    27  
    28  // This isn't a custom resource, in the sense that we never install its CRD.
    29  // It is a KRM-like object, so we generate a CRD to describe its schema.
    30  
    31  // A ScriptSource is a source from which a script can be loaded.
    32  type ScriptSource string
    33  
    34  // Supported script sources.
    35  const (
    36  	// ScriptSourceInline specifies a script inline.
    37  	ScriptSourceInline ScriptSource = "Inline"
    38  )
    39  
    40  // CueInput can be used to provide input to the function.
    41  // +kubebuilder:object:root=true
    42  // +kubebuilder:storageversion
    43  // +kubebuilder:resource:categories=crossplane
    44  type CueInput struct {
    45  	metav1.TypeMeta   `json:",inline"`
    46  	metav1.ObjectMeta `json:"metadata,omitempty"`
    47  	// Source of this script. Currently only Inline is supported.
    48  	// +kubebuilder:validation:Enum=Inline
    49  	// +kubebuilder:default=Inline
    50  	Source ScriptSource `json:"source"`
    51  	// Script specifies an inline script
    52  	// +optional
    53  	Script string `json:"script,omitempty"`
    54  	// RequestVar is the variable name that the function will use to provide inputs to the
    55  	// cue script. Defaults to "#request"
    56  	RequestVar string `json:"requestVar,omitempty"`
    57  	// ResponseVar is the variable name that the function will expect the response to be returned as.
    58  	// Defaults to "response". The special value "." means "use the entire object returned by the script".
    59  	ResponseVar string `json:"responseVar,omitempty"`
    60  	// LegacyDesiredOnlyResponse provides backward compatibility with older versions
    61  	// of the function when the function only expected the desired state to be returned.
    62  	// When set, the response is unmarshalled into a State message instead of
    63  	// the RunFunctionResponse message.
    64  	// Deprecated: This attribute will be removed in a future release.
    65  	LegacyDesiredOnlyResponse bool `json:"legacyDesiredOnlyResponse,omitempty"`
    66  	// Debug prints inputs to and outputs of the cue script for all XRs.
    67  	// Inputs are pre-processed to remove typically irrelevant information like
    68  	// the last applied kubectl annotation, managed fields etc.
    69  	// Objects are displayed in compact cue format. (the equivalent of `cue fmt -s`)
    70  	// When false, individual XRs can still be debugged by annotating them with
    71  	//    function-cue/debug: "true"
    72  	// +optional
    73  	Debug bool `json:"debug,omitempty"`
    74  	// DebugNew controls whether a new XR that is being processed by the function
    75  	// has debug output. A "new" XR is determined by the request having only an
    76  	// observed composite but no other observed resources. This allows debug output for
    77  	// first-time reconciles of XRs when the user has not yet had the opportunity to
    78  	// annotate them.
    79  	// +optional
    80  	DebugNew bool `json:"debugNew,omitempty"`
    81  	// DebugRaw disables the pre-processing of inputs.
    82  	// +optional
    83  	DebugRaw bool `json:"debugRaw,omitempty"`
    84  	// DebugScript displays the full generated script that is executed.
    85  	// +optional
    86  	DebugScript bool `json:"debugScript,omitempty"`
    87  }