sigs.k8s.io/kubebuilder/v3@v3.14.0/pkg/plugin/external/types.go (about)

     1  /*
     2  Copyright 2022 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package external
    18  
    19  import "sigs.k8s.io/kubebuilder/v3/pkg/plugin"
    20  
    21  // PluginRequest contains all information kubebuilder received from the CLI
    22  // and plugins executed before it.
    23  type PluginRequest struct {
    24  	// APIVersion defines the versioned schema of PluginRequest that is being sent from Kubebuilder.
    25  	// Initially, this will be marked as alpha (v1alpha1).
    26  	APIVersion string `json:"apiVersion"`
    27  
    28  	// Args holds the plugin specific arguments that are received from the CLI
    29  	// which are to be passed down to the external plugin.
    30  	Args []string `json:"args"`
    31  
    32  	// Command contains the command to be executed by the plugin such as init, create api, etc.
    33  	Command string `json:"command"`
    34  
    35  	// Universe represents the modified file contents that gets updated over a series of plugin runs
    36  	// across the plugin chain. Initially, it starts out as empty.
    37  	Universe map[string]string `json:"universe"`
    38  }
    39  
    40  // PluginResponse is returned to kubebuilder by the plugin and contains all files
    41  // written by the plugin following a certain command.
    42  type PluginResponse struct {
    43  	// APIVersion defines the versioned schema of the PluginResponse that is back sent back to Kubebuilder.
    44  	// Initially, this will be marked as alpha (v1alpha1)
    45  	APIVersion string `json:"apiVersion"`
    46  
    47  	// Command holds the command that gets executed by the plugin such as init, create api, etc.
    48  	Command string `json:"command"`
    49  
    50  	// Metadata contains the plugin specific help text that the plugin returns to Kubebuilder when it receives
    51  	// `--help` flag from Kubebuilder.
    52  	Metadata plugin.SubcommandMetadata `json:"metadata"`
    53  
    54  	// Universe in the PluginResponse represents the updated file contents that was written by the plugin.
    55  	Universe map[string]string `json:"universe"`
    56  
    57  	// Error is a boolean type that indicates whether there were any errors due to plugin failures.
    58  	Error bool `json:"error,omitempty"`
    59  
    60  	// ErrorMsgs contains the specific error messages of the plugin failures.
    61  	ErrorMsgs []string `json:"errorMsgs,omitempty"`
    62  
    63  	// Flags contains the plugin specific flags that the plugin returns to Kubebuilder when it receives
    64  	// a request for a list of supported flags from Kubebuilder
    65  	Flags []Flag `json:"flags,omitempty"`
    66  }
    67  
    68  // Flag is meant to represent a CLI flag that is used by Kubebuilder to define flags that are parsed
    69  // for use with an external plugin
    70  type Flag struct {
    71  	// Name is the name that should be used when creating the flag.
    72  	// i.e a name of "domain" would become the CLI flag "--domain"
    73  	Name string
    74  
    75  	// Type is the type of flag that should be created. The types that
    76  	// Kubebuilder supports are: string, bool, int, and float.
    77  	// any value other than the supported will be defaulted to be a string
    78  	Type string
    79  
    80  	// Default is the default value that should be used for a flag.
    81  	// Kubebuilder will attempt to convert this value to the defined
    82  	// type for this flag.
    83  	Default string
    84  
    85  	// Usage is a description of the flag and when/why/what it is used for.
    86  	Usage string
    87  }