kubecli

package
v0.0.0-...-a716c8a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2020 License: Apache-2.0 Imports: 41 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ApiGroupName = "/apis/" + v1.SubresourceGroupName
)
View Source
const (
	WebsocketMessageBufferSize = 10240
)

Variables

View Source
var GetKubevirtClientFromClientConfig = func(cmdConfig clientcmd.ClientConfig) (KubevirtClient, error) {
	config, err := cmdConfig.ClientConfig()
	if err != nil {
		return nil, err
	}
	return GetKubevirtClientFromRESTConfig(config)

}

this function is defined as a closure so iut could be overwritten by unit tests

Functions

func Copy

func Copy(dst *websocket.Conn, src *websocket.Conn) (int64, error)

func CopyFrom

func CopyFrom(dst io.Writer, src *websocket.Conn) (written int64, err error)

func CopyTo

func CopyTo(dst *websocket.Conn, src io.Reader) (written int64, err error)

func DefaultClientConfig

func DefaultClientConfig(flags *pflag.FlagSet) clientcmd.ClientConfig

DefaultClientConfig creates a clientcmd.ClientConfig with the following hierarchy:

  1. Use the kubeconfig builder. The number of merges and overrides here gets a little crazy. Stay with me.

  2. Merge the kubeconfig itself. This is done with the following hierarchy rules:

  3. CommandLineLocation - this parsed from the command line, so it must be late bound. If you specify this, then no other kubeconfig files are merged. This file must exist.

  4. If $KUBECONFIG is set, then it is treated as a list of files that should be merged.

  5. HomeDirectoryLocation Empty filenames are ignored. Files with non-deserializable content produced errors. The first file to set a particular value or map key wins and the value or map key is never changed. This means that the first file to set CurrentContext will have its context preserved. It also means that if two files specify a "red-user", only values from the first file's red-user are used. Even non-conflicting entries from the second file's "red-user" are discarded.

  6. Determine the context to use based on the first hit in this chain

  7. command line argument - again, parsed from the command line, so it must be late bound

  8. CurrentContext from the merged kubeconfig file

  9. Empty is allowed at this stage

  10. Determine the cluster info and auth info to use. At this point, we may or may not have a context. They are built based on the first hit in this chain. (run it twice, once for auth, once for cluster)

  11. command line argument

  12. If context is present, then use the context value

  13. Empty is allowed

  14. Determine the actual cluster info to use. At this point, we may or may not have a cluster info. Build each piece of the cluster info based on the chain:

  15. command line argument

  16. If cluster info is present and a value for the attribute is present, use it.

  17. If you don't have a server location, bail.

  18. Auth info is build using the same rules as cluster info, EXCEPT that you can only have one authentication technique per auth info. The following conditions result in an error:

  19. If there are two conflicting techniques specified from the command line, fail.

  20. If the command line does not specify one, and the auth info has conflicting techniques, fail.

  21. If the command line specifies one and the auth info specifies another, honor the command line technique.

  22. Use default values and potentially prompt for auth information

    However, if it appears that we're running in a kubernetes cluster container environment, then run with the auth info kubernetes mounted for us. Specifically: The env vars KUBERNETES_SERVICE_HOST and KUBERNETES_SERVICE_PORT are set, and the file /var/run/secrets/kubernetes.io/serviceaccount/token exists and is not a directory.

Initially copied from https://github.com/kubernetes/kubernetes/blob/09f321c80bfc9bca63a5530b56d7a1a3ba80ba9b/pkg/kubectl/cmd/util/factory_client_access.go#L174

func Dial

func Dial(address string, tlsConfig *tls.Config) (*websocket.Conn, *http.Response, error)

func FlagSet

func FlagSet() *flag.FlagSet

func GetConfig

func GetConfig() (*restclient.Config, error)

func GetKubevirtClientConfig

func GetKubevirtClientConfig() (*rest.Config, error)

func Init

func Init()

Init adds the default `kubeconfig` and `master` flags. It is not added by default to allow integration into the different controller generators which normally add these flags too.

func NewUpgrader

func NewUpgrader() *websocket.Upgrader

func RequestFromConfig

func RequestFromConfig(config *rest.Config, vmi string, namespace string, resource string) (*http.Request, error)

Types

type AsyncSubresourceError

type AsyncSubresourceError struct {
	StatusCode int
	// contains filtered or unexported fields
}

func (*AsyncSubresourceError) Error

func (a *AsyncSubresourceError) Error() string

func (*AsyncSubresourceError) GetStatusCode

func (a *AsyncSubresourceError) GetStatusCode() int

type KubeVirtInterface

type KubeVirtInterface interface {
	Get(name string, options *k8smetav1.GetOptions) (*v1.KubeVirt, error)
	List(opts *k8smetav1.ListOptions) (*v1.KubeVirtList, error)
	Create(instance *v1.KubeVirt) (*v1.KubeVirt, error)
	Update(*v1.KubeVirt) (*v1.KubeVirt, error)
	Delete(name string, options *k8smetav1.DeleteOptions) error
	Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.KubeVirt, err error)
	UpdateStatus(*v1.KubeVirt) (*v1.KubeVirt, error)
	PatchStatus(name string, pt types.PatchType, data []byte) (result *v1.KubeVirt, err error)
}

type KubevirtClient

type KubevirtClient interface {
	VirtualMachineInstance(namespace string) VirtualMachineInstanceInterface
	VirtualMachineInstanceMigration(namespace string) VirtualMachineInstanceMigrationInterface
	ReplicaSet(namespace string) ReplicaSetInterface
	VirtualMachine(namespace string) VirtualMachineInterface
	KubeVirt(namespace string) KubeVirtInterface
	VirtualMachineInstancePreset(namespace string) VirtualMachineInstancePresetInterface
	VirtualMachineSnapshot(namespace string) vmsnapshotv1alpha1.VirtualMachineSnapshotInterface
	VirtualMachineSnapshotContent(namespace string) vmsnapshotv1alpha1.VirtualMachineSnapshotContentInterface
	VirtualMachineRestore(namespace string) vmsnapshotv1alpha1.VirtualMachineRestoreInterface
	ServerVersion() *ServerVersion
	RestClient() *rest.RESTClient
	GeneratedKubeVirtClient() generatedclient.Interface
	NetworkClient() networkclient.Interface
	ExtensionsClient() extclient.Interface
	SecClient() secv1.SecurityV1Interface
	DiscoveryClient() discovery.DiscoveryInterface
	PrometheusClient() promclient.Interface
	KubernetesSnapshotClient() k8ssnapshotclient.Interface
	kubernetes.Interface
	Config() *rest.Config
}

func GetKubevirtClient

func GetKubevirtClient() (KubevirtClient, error)

func GetKubevirtClientFromFlags

func GetKubevirtClientFromFlags(master string, kubeconfig string) (KubevirtClient, error)

func GetKubevirtClientFromRESTConfig

func GetKubevirtClientFromRESTConfig(config *rest.Config) (KubevirtClient, error)

func GetKubevirtSubresourceClient

func GetKubevirtSubresourceClient() (KubevirtClient, error)

func GetKubevirtSubresourceClientFromFlags

func GetKubevirtSubresourceClientFromFlags(master string, kubeconfig string) (KubevirtClient, error)

type RoundTripCallback

type RoundTripCallback func(conn *websocket.Conn, resp *http.Response, err error) error

type SerialConsoleOptions

type SerialConsoleOptions struct {
	ConnectionTimeout time.Duration
}

type ServerVersion

type ServerVersion struct {
	// contains filtered or unexported fields
}

func (*ServerVersion) Get

func (v *ServerVersion) Get() (*version.Info, error)

type StreamInterface

type StreamInterface interface {
	Stream(options StreamOptions) error
}

type StreamOptions

type StreamOptions struct {
	In  io.Reader
	Out io.Writer
}

type VirtHandlerClient

type VirtHandlerClient interface {
	ForNode(nodeName string) VirtHandlerConn
	Port(port int) VirtHandlerClient
	Namespace(namespace string) VirtHandlerClient
}

func NewVirtHandlerClient

func NewVirtHandlerClient(client KubevirtClient) VirtHandlerClient

type VirtHandlerConn

type VirtHandlerConn interface {
	ConnectionDetails() (ip string, port int, err error)
	ConsoleURI(vmi *virtv1.VirtualMachineInstance) (string, error)
	VNCURI(vmi *virtv1.VirtualMachineInstance) (string, error)
	PauseURI(vmi *virtv1.VirtualMachineInstance) (string, error)
	UnpauseURI(vmi *virtv1.VirtualMachineInstance) (string, error)
	Pod() (pod *v1.Pod, err error)
	Put(url string, tlsConfig *tls.Config) error
	Get(url string, tlsConfig *tls.Config) (string, error)
	GuestInfoURI(vmi *virtv1.VirtualMachineInstance) (string, error)
	UserListURI(vmi *virtv1.VirtualMachineInstance) (string, error)
	FilesystemListURI(vmi *virtv1.VirtualMachineInstance) (string, error)
}

type VirtualMachineInstanceInterface

type VirtualMachineInstanceInterface interface {
	Get(name string, options *k8smetav1.GetOptions) (*v1.VirtualMachineInstance, error)
	List(opts *k8smetav1.ListOptions) (*v1.VirtualMachineInstanceList, error)
	Create(instance *v1.VirtualMachineInstance) (*v1.VirtualMachineInstance, error)
	Update(*v1.VirtualMachineInstance) (*v1.VirtualMachineInstance, error)
	Delete(name string, options *k8smetav1.DeleteOptions) error
	Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.VirtualMachineInstance, err error)
	SerialConsole(name string, options *SerialConsoleOptions) (StreamInterface, error)
	VNC(name string) (StreamInterface, error)
	Pause(name string) error
	Unpause(name string) error
	GuestOsInfo(name string) (v1.VirtualMachineInstanceGuestAgentInfo, error)
	UserList(name string) (v1.VirtualMachineInstanceGuestOSUserList, error)
	FilesystemList(name string) (v1.VirtualMachineInstanceFileSystemList, error)
}

type VirtualMachineInterface

type VirtualMachineInterface interface {
	Get(name string, options *k8smetav1.GetOptions) (*v1.VirtualMachine, error)
	List(opts *k8smetav1.ListOptions) (*v1.VirtualMachineList, error)
	Create(*v1.VirtualMachine) (*v1.VirtualMachine, error)
	Update(*v1.VirtualMachine) (*v1.VirtualMachine, error)
	Delete(name string, options *k8smetav1.DeleteOptions) error
	Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.VirtualMachine, err error)
	UpdateStatus(*v1.VirtualMachine) (*v1.VirtualMachine, error)
	PatchStatus(name string, pt types.PatchType, data []byte) (result *v1.VirtualMachine, err error)
	Restart(name string) error
	ForceRestart(name string, graceperiod int) error
	Start(name string) error
	Stop(name string) error
	Migrate(name string) error
	Rename(name string, options *v1.RenameOptions) error
}

VirtualMachineInterface provides convenience methods to work with virtual machines inside the cluster

type WebsocketRoundTripper

type WebsocketRoundTripper struct {
	Dialer *websocket.Dialer
	Do     RoundTripCallback
}

func (*WebsocketRoundTripper) RoundTrip

func (d *WebsocketRoundTripper) RoundTrip(r *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL