-
Notifications
You must be signed in to change notification settings - Fork 198
/
subscription.go
158 lines (130 loc) · 4.76 KB
/
subscription.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
/*
Copyright 2021 The Clusternet 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 v1alpha1
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// Important: Run "make generated" to regenerate code after modifying this file
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope="Namespaced",shortName=sub;subs,categories=clusternet
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// Subscription represents the policy that install a group of resources to one or more clusters.
type Subscription struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec SubscriptionSpec `json:"spec"`
Status SubscriptionStatus `json:"status,omitempty"`
}
// SubscriptionSpec defines the desired state of Subscription
type SubscriptionSpec struct {
// If specified, the Subscription will be handled by specified scheduler.
// If not specified, the Subscription will be handled by default scheduler.
//
// +optional
// +kubebuilder:default=default
SchedulerName string `json:"schedulerName,omitempty"`
// If specified, the Subscription will be handled with specified SchedulingStrategy.
// Otherwise, with generic SchedulingStrategy.
//
// +optional
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Enum=Replication;Balancing
// +kubebuilder:default=Replication
SchedulingStrategy SchedulingStrategyType `json:"schedulingStrategy,omitempty"`
// Subscribers subscribes
//
// +required
// +kubebuilder:validation:Required
Subscribers []Subscriber `json:"subscribers"`
// ClusterTolerations tolerates any matched taints of ManagedCluster.
//
// +optional
ClusterTolerations []corev1.Toleration `json:"clusterTolerations,omitempty"`
// Feeds
//
// +required
// +kubebuilder:validation:Required
Feeds []Feed `json:"feeds"`
}
// SubscriptionStatus defines the observed state of Subscription
type SubscriptionStatus struct {
// Namespaced names of targeted clusters that Subscription binds to.
//
// +optional
BindingClusters []string `json:"bindingClusters,omitempty"`
// SpecHash calculates the hash value of current SubscriptionSpec.
//
// +optional
SpecHash uint64 `json:"specHash,omitempty"`
// Total number of Helm releases desired by this Subscription.
//
// +optional
DesiredReleases int `json:"desiredReleases,omitempty"`
// Total number of completed releases targeted by this Subscription.
//
// +optional
CompletedReleases int `json:"completedReleases,omitempty"`
}
// Subscriber defines
type Subscriber struct {
// ClusterAffinity is a label query over managed clusters by labels.
//
// +required
// +kubebuilder:validation:Required
ClusterAffinity *metav1.LabelSelector `json:"clusterAffinity"`
}
// Feed defines the resource to be selected.
type Feed struct {
// Kind is a string value representing the REST resource this object represents.
// In CamelCase.
//
// +required
// +kubebuilder:validation:Required
// +kubebuilder:validation:Type=string
Kind string `json:"kind"`
// APIVersion defines the versioned schema of this representation of an object.
//
// +required
// +kubebuilder:validation:Required
// +kubebuilder:validation:Type=string
APIVersion string `json:"apiVersion"`
// Namespace of the target resource.
//
// +optional
Namespace string `json:"namespace,omitempty"`
// Name of the target resource.
//
// +required
// +kubebuilder:validation:Required
// +kubebuilder:validation:Type=string
Name string `json:"name"`
}
type SchedulingStrategyType string
const (
// ReplicaSchedulingStrategy places and maintains a copy of this Subscription on each matched clusters.
ReplicaSchedulingStrategy SchedulingStrategyType = "Replication"
// BalancingSchedulingStrategy balances and divides the replicas of a Subscription to several matching clusters.
// TODO
BalancingSchedulingStrategy SchedulingStrategyType = "Balancing"
)
// +kubebuilder:object:root=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// SubscriptionList contains a list of Subscription
type SubscriptionList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Subscription `json:"items"`
}