halkyon.io/api@v1.0.0-rc.6/runtime/v1beta1/types.go (about)

     1  package v1beta1
     2  
     3  import (
     4  	"halkyon.io/api/v1beta1"
     5  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     6  	"k8s.io/apimachinery/pkg/runtime/schema"
     7  	"strings"
     8  	"text/template"
     9  )
    10  
    11  const Kind string = "Runtime"
    12  
    13  // EDIT THIS FILE!  THIS IS SCAFFOLDING FOR YOU TO OWN!
    14  // NOTE: json tags are required.  Any new fields you add must have json tags for the fields to be serialized.
    15  
    16  // RuntimeSpec defines the desired state of Runtime
    17  type RuntimeSpec struct {
    18  	// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
    19  	// Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file
    20  	// Add custom validation using kubebuilder tags: https://book-v1.book.kubebuilder.io/beyond_basics/generating_crd.html
    21  	Name              string `json:"name"`
    22  	Version           string `json:"version"`
    23  	GeneratorTemplate string `json:"generator,omitempty"`
    24  	Image             string `json:"image"`
    25  	ExecutablePattern string `json:"executablePattern"`
    26  	// Array of env variables containing extra/additional info to be passed to all applications using this runtime
    27  	Envs []v1beta1.NameValuePair `json:"envs,omitempty"`
    28  }
    29  
    30  type GeneratorOptions struct {
    31  	RuntimeVersion  string
    32  	GroupId         string
    33  	ArtifactId      string
    34  	ProjectVersion  string
    35  	PackageName     string
    36  	ProjectTemplate string
    37  	ArchiveName     string
    38  }
    39  
    40  func ComputeGeneratorURL(generatorTemplate string, options GeneratorOptions) (string, error) {
    41  	t := template.New("generator")
    42  	parsed, err := t.Parse(generatorTemplate)
    43  	if err != nil {
    44  		return "", err
    45  	}
    46  	builder := &strings.Builder{}
    47  	err = parsed.Execute(builder, options)
    48  	if err != nil {
    49  		return "", err
    50  	}
    51  	return builder.String(), nil
    52  }
    53  
    54  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    55  
    56  // Runtime is the Schema for the runtimes API
    57  // +kubebuilder:resource:path=runtimes
    58  // +genclient
    59  // +genclient:nonNamespaced
    60  type Runtime struct {
    61  	metav1.TypeMeta   `json:",inline"`
    62  	metav1.ObjectMeta `json:"metadata,omitempty"`
    63  
    64  	Spec RuntimeSpec `json:"spec,omitempty"`
    65  }
    66  
    67  // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
    68  
    69  // RuntimeList contains a list of Runtime
    70  type RuntimeList struct {
    71  	metav1.TypeMeta `json:",inline"`
    72  	metav1.ListMeta `json:"metadata,omitempty"`
    73  	Items           []Runtime `json:"items"`
    74  }
    75  
    76  func (in *Runtime) GetGroupVersionKind() schema.GroupVersionKind {
    77  	return SchemeGroupVersion.WithKind(Kind)
    78  }