forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
daemonset.go
167 lines (136 loc) · 6.14 KB
/
daemonset.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package federatedtypes
import (
"reflect"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
pkgruntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
federationclientset "k8s.io/kubernetes/federation/client/clientset_generated/federation_clientset"
"k8s.io/kubernetes/federation/pkg/federation-controller/util"
"k8s.io/kubernetes/pkg/api/v1"
extensionsv1 "k8s.io/kubernetes/pkg/apis/extensions/v1beta1"
kubeclientset "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
)
const (
DaemonSetKind = "daemonset"
DaemonSetControllerName = "daemonsets"
)
func init() {
RegisterFederatedType(DaemonSetKind, DaemonSetControllerName, []schema.GroupVersionResource{extensionsv1.SchemeGroupVersion.WithResource(DaemonSetControllerName)}, NewDaemonSetAdapter)
}
type DaemonSetAdapter struct {
client federationclientset.Interface
}
func NewDaemonSetAdapter(client federationclientset.Interface) FederatedTypeAdapter {
return &DaemonSetAdapter{client: client}
}
func (a *DaemonSetAdapter) Kind() string {
return DaemonSetKind
}
func (a *DaemonSetAdapter) ObjectType() pkgruntime.Object {
return &extensionsv1.DaemonSet{}
}
func (a *DaemonSetAdapter) IsExpectedType(obj interface{}) bool {
_, ok := obj.(*extensionsv1.DaemonSet)
return ok
}
func (a *DaemonSetAdapter) Copy(obj pkgruntime.Object) pkgruntime.Object {
daemonset := obj.(*extensionsv1.DaemonSet)
return &extensionsv1.DaemonSet{
ObjectMeta: util.DeepCopyRelevantObjectMeta(daemonset.ObjectMeta),
Spec: *(util.DeepCopyApiTypeOrPanic(&daemonset.Spec).(*extensionsv1.DaemonSetSpec)),
}
}
func (a *DaemonSetAdapter) Equivalent(obj1, obj2 pkgruntime.Object) bool {
daemonset1 := obj1.(*extensionsv1.DaemonSet)
daemonset2 := obj2.(*extensionsv1.DaemonSet)
return util.ObjectMetaEquivalent(daemonset1.ObjectMeta, daemonset2.ObjectMeta) && reflect.DeepEqual(daemonset1.Spec, daemonset2.Spec)
}
func (a *DaemonSetAdapter) NamespacedName(obj pkgruntime.Object) types.NamespacedName {
daemonset := obj.(*extensionsv1.DaemonSet)
return types.NamespacedName{Namespace: daemonset.Namespace, Name: daemonset.Name}
}
func (a *DaemonSetAdapter) ObjectMeta(obj pkgruntime.Object) *metav1.ObjectMeta {
return &obj.(*extensionsv1.DaemonSet).ObjectMeta
}
func (a *DaemonSetAdapter) FedCreate(obj pkgruntime.Object) (pkgruntime.Object, error) {
daemonset := obj.(*extensionsv1.DaemonSet)
return a.client.Extensions().DaemonSets(daemonset.Namespace).Create(daemonset)
}
func (a *DaemonSetAdapter) FedDelete(namespacedName types.NamespacedName, options *metav1.DeleteOptions) error {
return a.client.Extensions().DaemonSets(namespacedName.Namespace).Delete(namespacedName.Name, options)
}
func (a *DaemonSetAdapter) FedGet(namespacedName types.NamespacedName) (pkgruntime.Object, error) {
return a.client.Extensions().DaemonSets(namespacedName.Namespace).Get(namespacedName.Name, metav1.GetOptions{})
}
func (a *DaemonSetAdapter) FedList(namespace string, options metav1.ListOptions) (pkgruntime.Object, error) {
return a.client.Extensions().DaemonSets(namespace).List(options)
}
func (a *DaemonSetAdapter) FedUpdate(obj pkgruntime.Object) (pkgruntime.Object, error) {
daemonset := obj.(*extensionsv1.DaemonSet)
return a.client.Extensions().DaemonSets(daemonset.Namespace).Update(daemonset)
}
func (a *DaemonSetAdapter) FedWatch(namespace string, options metav1.ListOptions) (watch.Interface, error) {
return a.client.Extensions().DaemonSets(namespace).Watch(options)
}
func (a *DaemonSetAdapter) ClusterCreate(client kubeclientset.Interface, obj pkgruntime.Object) (pkgruntime.Object, error) {
daemonset := obj.(*extensionsv1.DaemonSet)
return client.Extensions().DaemonSets(daemonset.Namespace).Create(daemonset)
}
func (a *DaemonSetAdapter) ClusterDelete(client kubeclientset.Interface, nsName types.NamespacedName, options *metav1.DeleteOptions) error {
return client.Extensions().DaemonSets(nsName.Namespace).Delete(nsName.Name, options)
}
func (a *DaemonSetAdapter) ClusterGet(client kubeclientset.Interface, namespacedName types.NamespacedName) (pkgruntime.Object, error) {
return client.Extensions().DaemonSets(namespacedName.Namespace).Get(namespacedName.Name, metav1.GetOptions{})
}
func (a *DaemonSetAdapter) ClusterList(client kubeclientset.Interface, namespace string, options metav1.ListOptions) (pkgruntime.Object, error) {
return client.Extensions().DaemonSets(namespace).List(options)
}
func (a *DaemonSetAdapter) ClusterUpdate(client kubeclientset.Interface, obj pkgruntime.Object) (pkgruntime.Object, error) {
daemonset := obj.(*extensionsv1.DaemonSet)
return client.Extensions().DaemonSets(daemonset.Namespace).Update(daemonset)
}
func (a *DaemonSetAdapter) ClusterWatch(client kubeclientset.Interface, namespace string, options metav1.ListOptions) (watch.Interface, error) {
return client.Extensions().DaemonSets(namespace).Watch(options)
}
func (a *DaemonSetAdapter) IsSchedulingAdapter() bool {
return false
}
func (a *DaemonSetAdapter) NewTestObject(namespace string) pkgruntime.Object {
return &extensionsv1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{
GenerateName: "test-daemonset-",
Namespace: namespace,
Labels: map[string]string{"app": "test-daemonset"},
},
Spec: extensionsv1.DaemonSetSpec{
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"name": "test-pod"},
},
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: "test-daemonset",
Image: "images/test-daemonset",
Ports: []v1.ContainerPort{{ContainerPort: 9376}},
},
},
},
},
},
}
}