...

Source file src/kubevirt.io/client-go/kubecli/kv.go

Documentation: kubevirt.io/client-go/kubecli

     1  /*
     2   * This file is part of the KubeVirt project
     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   * Copyright 2018 Red Hat, Inc.
    17   *
    18   */
    19  
    20  package kubecli
    21  
    22  import (
    23  	"context"
    24  
    25  	k8smetav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    26  	"k8s.io/apimachinery/pkg/types"
    27  	"k8s.io/client-go/rest"
    28  
    29  	v1 "kubevirt.io/api/core/v1"
    30  	kvcorev1 "kubevirt.io/client-go/generated/kubevirt/clientset/versioned/typed/core/v1"
    31  )
    32  
    33  func (k *kubevirt) KubeVirt(namespace string) KubeVirtInterface {
    34  	return &kv{
    35  		KubeVirtInterface: k.GeneratedKubeVirtClient().KubevirtV1().KubeVirts(namespace),
    36  		restClient:        k.restClient,
    37  		namespace:         namespace,
    38  		resource:          "kubevirts",
    39  	}
    40  }
    41  
    42  type kv struct {
    43  	kvcorev1.KubeVirtInterface
    44  	restClient *rest.RESTClient
    45  	namespace  string
    46  	resource   string
    47  }
    48  
    49  // Create new KubeVirt in the cluster to specified namespace
    50  func (o *kv) Create(ctx context.Context, kv *v1.KubeVirt, opts k8smetav1.CreateOptions) (*v1.KubeVirt, error) {
    51  	newKv, err := o.KubeVirtInterface.Create(ctx, kv, opts)
    52  	newKv.SetGroupVersionKind(v1.KubeVirtGroupVersionKind)
    53  	return newKv, err
    54  }
    55  
    56  // Get the KubeVirt from the cluster by its name and namespace
    57  func (o *kv) Get(ctx context.Context, name string, options k8smetav1.GetOptions) (*v1.KubeVirt, error) {
    58  	newKv, err := o.KubeVirtInterface.Get(ctx, name, options)
    59  	newKv.SetGroupVersionKind(v1.KubeVirtGroupVersionKind)
    60  	return newKv, err
    61  }
    62  
    63  // Update the KubeVirt instance in the cluster in given namespace
    64  func (o *kv) Update(ctx context.Context, kv *v1.KubeVirt, opts k8smetav1.UpdateOptions) (*v1.KubeVirt, error) {
    65  	updatedKv, err := o.KubeVirtInterface.Update(ctx, kv, opts)
    66  	updatedKv.SetGroupVersionKind(v1.KubeVirtGroupVersionKind)
    67  	return updatedKv, err
    68  }
    69  
    70  // Delete the defined KubeVirt in the cluster in defined namespace
    71  func (o *kv) Delete(ctx context.Context, name string, options k8smetav1.DeleteOptions) error {
    72  	return o.KubeVirtInterface.Delete(ctx, name, options)
    73  }
    74  
    75  // List all KubeVirts in given namespace
    76  func (o *kv) List(ctx context.Context, options k8smetav1.ListOptions) (*v1.KubeVirtList, error) {
    77  	newKvList, err := o.KubeVirtInterface.List(ctx, options)
    78  	for i := range newKvList.Items {
    79  		newKvList.Items[i].SetGroupVersionKind(v1.KubeVirtGroupVersionKind)
    80  	}
    81  	return newKvList, err
    82  }
    83  
    84  func (o *kv) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, patchOptions k8smetav1.PatchOptions, subresources ...string) (result *v1.KubeVirt, err error) {
    85  	return o.KubeVirtInterface.Patch(ctx, name, pt, data, patchOptions, subresources...)
    86  }
    87  
    88  func (o *kv) UpdateStatus(ctx context.Context, kv *v1.KubeVirt, opts k8smetav1.UpdateOptions) (result *v1.KubeVirt, err error) {
    89  	result, err = o.KubeVirtInterface.UpdateStatus(ctx, kv, opts)
    90  	result.SetGroupVersionKind(v1.KubeVirtGroupVersionKind)
    91  	return
    92  }
    93  

View as plain text