-
Notifications
You must be signed in to change notification settings - Fork 20
/
ingresses.go
111 lines (97 loc) · 3.19 KB
/
ingresses.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// Package ingresses provides implementation of Ingress resources for Kubernetes
//
// Deprecated: Use the resources package instead.
package ingresses
import (
"context"
"errors"
k8sTypes "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
)
// New creates a new instance backed by the provided client
//
// Deprecated: No longer used.
func New(ctx context.Context, client kubernetes.Interface, metaOptions metav1.ListOptions) *Ingresses {
return &Ingresses{
client,
metaOptions,
ctx,
}
}
// Ingresses provides API for manipulating Ingress resources within a Kubernetes cluster
//
// Deprecated: No longer used in favor of generic resources.
type Ingresses struct {
client kubernetes.Interface
metaOptions metav1.ListOptions
ctx context.Context
}
// Apply creates the Kubernetes resource given the supplied YAML configuration
//
// Deprecated: Use resources.Apply instead.
func (obj *Ingresses) Apply(yaml string, namespace string) (k8sTypes.Ingress, error) {
decode := scheme.Codecs.UniversalDeserializer().Decode
yamlobj, _, err := decode([]byte(yaml), nil, nil)
ingress := k8sTypes.Ingress{}
if err != nil {
return ingress, err
}
if ing, ok := yamlobj.(*k8sTypes.Ingress); ok {
ingress = *ing
} else {
return ingress, errors.New("YAML was not an Ingress")
}
ing, err := obj.client.NetworkingV1().Ingresses(namespace).Create(obj.ctx, &ingress, metav1.CreateOptions{})
if err != nil {
return k8sTypes.Ingress{}, err
}
return *ing, nil
}
// Create creates the Kubernetes resource given the supplied object
//
// Deprecated: Use resources.Create instead.
func (obj *Ingresses) Create(
ingress k8sTypes.Ingress,
namespace string,
opts metav1.CreateOptions,
) (k8sTypes.Ingress, error) {
ing, err := obj.client.NetworkingV1().Ingresses(namespace).Create(obj.ctx, &ingress, opts)
if err != nil {
return k8sTypes.Ingress{}, err
}
return *ing, nil
}
// List returns a collection of Ingresses available within the namespace
//
// Deprecated: Use resources.List instead.
func (obj *Ingresses) List(namespace string) ([]k8sTypes.Ingress, error) {
ings, err := obj.client.NetworkingV1().Ingresses(namespace).List(obj.ctx, obj.metaOptions)
if err != nil {
return []k8sTypes.Ingress{}, err
}
return ings.Items, nil
}
// Delete removes the named Ingress from the namespace
//
// Deprecated: Use resources.Delete instead.
func (obj *Ingresses) Delete(name, namespace string, opts metav1.DeleteOptions) error {
return obj.client.NetworkingV1().Ingresses(namespace).Delete(obj.ctx, name, opts)
}
// Kill removes the named Ingress from the namespace
//
// Deprecated: Use resources.Delete instead.
func (obj *Ingresses) Kill(name, namespace string, opts metav1.DeleteOptions) error {
return obj.Delete(name, namespace, opts)
}
// Get returns the named Ingresses instance within the namespace if available
//
// Deprecated: Use resources.Get instead.
func (obj *Ingresses) Get(name, namespace string, opts metav1.GetOptions) (k8sTypes.Ingress, error) {
ing, err := obj.client.NetworkingV1().Ingresses(namespace).Get(obj.ctx, name, opts)
if err != nil {
return k8sTypes.Ingress{}, err
}
return *ing, nil
}