kubecli

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2023 License: Apache-2.0 Imports: 55 Imported by: 0

Documentation

Index

Constants

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

Variables

View Source
var (
	SchemeBuilder  runtime.SchemeBuilder
	Scheme         *runtime.Scheme
	Codecs         serializer.CodecFactory
	ParameterCodec runtime.ParameterCodec
)
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 deprecated

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

Deprecated: Use GetKubevirtClientConfig instead

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 NewWebsocketStreamer

func NewWebsocketStreamer(conn *websocket.Conn, done chan struct{}) *wsStreamer

func RegisterRestConfigHook

func RegisterRestConfigHook(fn RestConfigHookFunc)

func RequestFromConfig

func RequestFromConfig(config *rest.Config, resource, name, namespace, subresource string, queryParams url.Values) (*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 ClusterProfiler

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

func (*ClusterProfiler) Dump

Dump returns at most cpRequest.PageSize profiler results. To fetch results from all kubevirt pods Dump should be called with Continue fields set to Continue field value from the response to a previous request. This should be repeated until Continue or ComponentsResult field in ClusterProfilerResponse is empty.

func (*ClusterProfiler) Start

func (v *ClusterProfiler) Start() error

func (*ClusterProfiler) Stop

func (v *ClusterProfiler) Stop() error

type ExpandSpecInterface

type ExpandSpecInterface interface {
	ForVirtualMachine(vm *v1.VirtualMachine) (*v1.VirtualMachine, error)
}

type GuestfsInfo

type GuestfsInfo struct {
	Registry    string `json:"registry"`
	Tag         string `json:"tag"`
	Digest      string `json:"digest"`
	ImagePrefix string `json:"imagePrefix"`
	GsImage     string `json:"gsImage"`
}

type GuestfsVersion

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

func (*GuestfsVersion) Get

func (v *GuestfsVersion) Get() (*GuestfsInfo, error)

type KubeVirtInterface

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

type KubevirtClient

type KubevirtClient interface {
	VirtualMachineInstance(namespace string) VirtualMachineInstanceInterface
	VirtualMachineInstanceMigration(namespace string) VirtualMachineInstanceMigrationInterface
	ReplicaSet(namespace string) ReplicaSetInterface
	VirtualMachinePool(namespace string) poolv1.VirtualMachinePoolInterface
	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
	VirtualMachineExport(namespace string) vmexportv1alpha1.VirtualMachineExportInterface
	VirtualMachineInstancetype(namespace string) instancetypev1beta1.VirtualMachineInstancetypeInterface
	VirtualMachineClusterInstancetype() instancetypev1beta1.VirtualMachineClusterInstancetypeInterface
	VirtualMachinePreference(namespace string) instancetypev1beta1.VirtualMachinePreferenceInterface
	VirtualMachineClusterPreference() instancetypev1beta1.VirtualMachineClusterPreferenceInterface
	MigrationPolicy() migrationsv1.MigrationPolicyInterface
	ExpandSpec(namespace string) ExpandSpecInterface
	ServerVersion() ServerVersionInterface
	VirtualMachineClone(namespace string) clonev1alpha1.VirtualMachineCloneInterface
	ClusterProfiler() *ClusterProfiler
	GuestfsVersion() *GuestfsVersion
	RestClient() *rest.RESTClient
	GeneratedKubeVirtClient() generatedclient.Interface
	CdiClient() cdiclient.Interface
	NetworkClient() networkclient.Interface
	ExtensionsClient() extclient.Interface
	SecClient() secv1.SecurityV1Interface
	RouteClient() routev1.RouteV1Interface
	DiscoveryClient() discovery.DiscoveryInterface
	PrometheusClient() promclient.Interface
	KubernetesSnapshotClient() k8ssnapshotclient.Interface
	DynamicClient() dynamic.Interface
	MigrationPolicyClient() *migrationsv1.MigrationsV1alpha1Client
	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 RestConfigHookFunc

type RestConfigHookFunc func(*rest.Config)

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 ServerVersionInterface

type ServerVersionInterface interface {
	Get() (*version.Info, error)
}

type StreamInterface

type StreamInterface interface {
	Stream(options StreamOptions) error
	AsConn() net.Conn
}

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(virtCli KubevirtClient, httpCli *http.Client) VirtHandlerClient

type VirtHandlerConn

type VirtHandlerConn interface {
	ConnectionDetails() (ip string, port int, err error)
	ConsoleURI(vmi *virtv1.VirtualMachineInstance) (string, error)
	USBRedirURI(vmi *virtv1.VirtualMachineInstance) (string, error)
	VNCURI(vmi *virtv1.VirtualMachineInstance) (string, error)
	VSOCKURI(vmi *virtv1.VirtualMachineInstance, port string, tls string) (string, error)
	PauseURI(vmi *virtv1.VirtualMachineInstance) (string, error)
	UnpauseURI(vmi *virtv1.VirtualMachineInstance) (string, error)
	FreezeURI(vmi *virtv1.VirtualMachineInstance) (string, error)
	UnfreezeURI(vmi *virtv1.VirtualMachineInstance) (string, error)
	SoftRebootURI(vmi *virtv1.VirtualMachineInstance) (string, error)
	SEVFetchCertChainURI(vmi *virtv1.VirtualMachineInstance) (string, error)
	SEVQueryLaunchMeasurementURI(vmi *virtv1.VirtualMachineInstance) (string, error)
	SEVInjectLaunchSecretURI(vmi *virtv1.VirtualMachineInstance) (string, error)
	Pod() (pod *v1.Pod, err error)
	Put(url string, body io.ReadCloser) error
	Get(url string) (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(ctx context.Context, name string, options *metav1.GetOptions) (*v1.VirtualMachineInstance, error)
	List(ctx context.Context, opts *metav1.ListOptions) (*v1.VirtualMachineInstanceList, error)
	Create(ctx context.Context, instance *v1.VirtualMachineInstance) (*v1.VirtualMachineInstance, error)
	Update(ctx context.Context, instance *v1.VirtualMachineInstance) (*v1.VirtualMachineInstance, error)
	Delete(ctx context.Context, name string, options *metav1.DeleteOptions) error
	Patch(ctx context.Context, name string, pt types.PatchType, data []byte, patchOptions *metav1.PatchOptions, subresources ...string) (result *v1.VirtualMachineInstance, err error)
	Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error)
	SerialConsole(name string, options *SerialConsoleOptions) (StreamInterface, error)
	USBRedir(vmiName string) (StreamInterface, error)
	VNC(name string) (StreamInterface, error)
	Screenshot(ctx context.Context, name string, options *v1.ScreenshotOptions) ([]byte, error)
	PortForward(name string, port int, protocol string) (StreamInterface, error)
	Pause(ctx context.Context, name string, pauseOptions *v1.PauseOptions) error
	Unpause(ctx context.Context, name string, unpauseOptions *v1.UnpauseOptions) error
	Freeze(ctx context.Context, name string, unfreezeTimeout time.Duration) error
	Unfreeze(ctx context.Context, name string) error
	SoftReboot(ctx context.Context, name string) error
	GuestOsInfo(ctx context.Context, name string) (v1.VirtualMachineInstanceGuestAgentInfo, error)
	UserList(ctx context.Context, name string) (v1.VirtualMachineInstanceGuestOSUserList, error)
	FilesystemList(ctx context.Context, name string) (v1.VirtualMachineInstanceFileSystemList, error)
	AddVolume(ctx context.Context, name string, addVolumeOptions *v1.AddVolumeOptions) error
	RemoveVolume(ctx context.Context, name string, removeVolumeOptions *v1.RemoveVolumeOptions) error
	VSOCK(name string, options *v1.VSOCKOptions) (StreamInterface, error)
	SEVFetchCertChain(name string) (v1.SEVPlatformInfo, error)
	SEVQueryLaunchMeasurement(name string) (v1.SEVMeasurementInfo, error)
	SEVSetupSession(name string, sevSessionOptions *v1.SEVSessionOptions) error
	SEVInjectLaunchSecret(name string, sevSecretOptions *v1.SEVSecretOptions) error
}

type VirtualMachineInterface

type VirtualMachineInterface interface {
	Get(ctx context.Context, name string, options *metav1.GetOptions) (*v1.VirtualMachine, error)
	GetWithExpandedSpec(ctx context.Context, name string) (*v1.VirtualMachine, error)
	List(ctx context.Context, opts *metav1.ListOptions) (*v1.VirtualMachineList, error)
	Create(ctx context.Context, vm *v1.VirtualMachine) (*v1.VirtualMachine, error)
	Update(ctx context.Context, vm *v1.VirtualMachine) (*v1.VirtualMachine, error)
	Delete(ctx context.Context, name string, options *metav1.DeleteOptions) error
	Patch(ctx context.Context, name string, pt types.PatchType, data []byte, patchOptions *metav1.PatchOptions, subresources ...string) (result *v1.VirtualMachine, err error)
	UpdateStatus(ctx context.Context, vm *v1.VirtualMachine) (*v1.VirtualMachine, error)
	PatchStatus(ctx context.Context, name string, pt types.PatchType, data []byte, patchOptions *metav1.PatchOptions) (result *v1.VirtualMachine, err error)
	Restart(ctx context.Context, name string, restartOptions *v1.RestartOptions) error
	ForceRestart(ctx context.Context, name string, restartOptions *v1.RestartOptions) error
	Start(ctx context.Context, name string, startOptions *v1.StartOptions) error
	Stop(ctx context.Context, name string, stopOptions *v1.StopOptions) error
	ForceStop(ctx context.Context, name string, stopOptions *v1.StopOptions) error
	Migrate(ctx context.Context, name string, migrateOptions *v1.MigrateOptions) error
	AddVolume(ctx context.Context, name string, addVolumeOptions *v1.AddVolumeOptions) error
	RemoveVolume(ctx context.Context, name string, removeVolumeOptions *v1.RemoveVolumeOptions) error
	PortForward(name string, port int, protocol string) (StreamInterface, error)
	MemoryDump(ctx context.Context, name string, memoryDumpRequest *v1.VirtualMachineMemoryDumpRequest) error
	RemoveMemoryDump(ctx context.Context, name string) 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