Skip to content

Commit f19653e

Browse files
authored
Revision Tag Support (openshift-service-mesh#413)
* IstioRevisionTag implementation I also added a bunch of integration tests. Documentation is still to come. There are more scenarios that might need testing, we'll need to figure that out as we go. Signed-off-by: Daniel Grimm <[email protected]> * Change func name to isRevisionReferenced Signed-off-by: Daniel Grimm <[email protected]> * Remove premature optimization Signed-off-by: Daniel Grimm <[email protected]> * Rename to TransientError Signed-off-by: Daniel Grimm <[email protected]> * Stop watching Istio resources in IstioRevision controller Signed-off-by: Daniel Grimm <[email protected]> --------- Signed-off-by: Daniel Grimm <[email protected]>
1 parent cea83cc commit f19653e

File tree

62 files changed

+7807
-71
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+7807
-71
lines changed

PROJECT

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ resources:
2727
kind: IstioRevision
2828
path: github.com/istio-ecosystem/sail-operator/api/v1alpha1
2929
version: v1alpha1
30+
- api:
31+
crdVersion: v1
32+
namespaced: false
33+
controller: true
34+
domain: sailoperator.io
35+
kind: IstioRevisionTag
36+
path: github.com/istio-ecosystem/sail-operator/api/v1alpha1
37+
version: v1alpha1
3038
- api:
3139
crdVersion: v1
3240
namespaced: false
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
// Copyright Istio Authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package v1alpha1
16+
17+
import (
18+
"time"
19+
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
const (
24+
IstioRevisionTagKind = "IstioRevisionTag"
25+
DefaultRevisionTag = "default"
26+
)
27+
28+
// IstioRevisionTagSpec defines the desired state of IstioRevisionTag
29+
type IstioRevisionTagSpec struct {
30+
// +kubebuilder:validation:Required
31+
TargetRef IstioRevisionTagTargetReference `json:"targetRef"`
32+
}
33+
34+
// IstioRevisionTagTargetReference can reference either Istio or IstioRevision objects in the cluster.
35+
type IstioRevisionTagTargetReference struct {
36+
// Kind is the kind of the target resource.
37+
//
38+
// +kubebuilder:validation:MinLength=1
39+
// +kubebuilder:validation:MaxLength=253
40+
// +kubebuilder:validation:Required
41+
Kind string `json:"kind"`
42+
43+
// Name is the name of the target resource.
44+
//
45+
// +kubebuilder:validation:MinLength=1
46+
// +kubebuilder:validation:MaxLength=253
47+
// +kubebuilder:validation:Required
48+
Name string `json:"name"`
49+
}
50+
51+
// IstioRevisionStatus defines the observed state of IstioRevision
52+
type IstioRevisionTagStatus struct {
53+
// ObservedGeneration is the most recent generation observed for this
54+
// IstioRevisionTag object. It corresponds to the object's generation, which is
55+
// updated on mutation by the API Server. The information in the status
56+
// pertains to this particular generation of the object.
57+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
58+
59+
// Represents the latest available observations of the object's current state.
60+
Conditions []IstioRevisionTagCondition `json:"conditions,omitempty"`
61+
62+
// Reports the current state of the object.
63+
State IstioRevisionTagConditionReason `json:"state,omitempty"`
64+
65+
// IstiodNamespace stores the namespace of the corresponding Istiod instance
66+
IstiodNamespace string `json:"istiodNamespace"`
67+
68+
// IstioRevision stores the name of the referenced IstioRevision
69+
IstioRevision string `json:"istioRevision"`
70+
}
71+
72+
// GetCondition returns the condition of the specified type
73+
func (s *IstioRevisionTagStatus) GetCondition(conditionType IstioRevisionTagConditionType) IstioRevisionTagCondition {
74+
if s != nil {
75+
for i := range s.Conditions {
76+
if s.Conditions[i].Type == conditionType {
77+
return s.Conditions[i]
78+
}
79+
}
80+
}
81+
return IstioRevisionTagCondition{Type: conditionType, Status: metav1.ConditionUnknown}
82+
}
83+
84+
// SetCondition sets a specific condition in the list of conditions
85+
func (s *IstioRevisionTagStatus) SetCondition(condition IstioRevisionTagCondition) {
86+
var now time.Time
87+
if testTime == nil {
88+
now = time.Now()
89+
} else {
90+
now = *testTime
91+
}
92+
93+
// The lastTransitionTime only gets serialized out to the second. This can
94+
// break update skipping, as the time in the resource returned from the client
95+
// may not match the time in our cached status during a reconcile. We truncate
96+
// here to save any problems down the line.
97+
lastTransitionTime := metav1.NewTime(now.Truncate(time.Second))
98+
99+
for i, prevCondition := range s.Conditions {
100+
if prevCondition.Type == condition.Type {
101+
if prevCondition.Status != condition.Status {
102+
condition.LastTransitionTime = lastTransitionTime
103+
} else {
104+
condition.LastTransitionTime = prevCondition.LastTransitionTime
105+
}
106+
s.Conditions[i] = condition
107+
return
108+
}
109+
}
110+
111+
// If the condition does not exist, initialize the lastTransitionTime
112+
condition.LastTransitionTime = lastTransitionTime
113+
s.Conditions = append(s.Conditions, condition)
114+
}
115+
116+
// IstioRevisionCondition represents a specific observation of the IstioRevision object's state.
117+
type IstioRevisionTagCondition struct {
118+
// The type of this condition.
119+
Type IstioRevisionTagConditionType `json:"type,omitempty"`
120+
121+
// The status of this condition. Can be True, False or Unknown.
122+
Status metav1.ConditionStatus `json:"status,omitempty"`
123+
124+
// Unique, single-word, CamelCase reason for the condition's last transition.
125+
Reason IstioRevisionTagConditionReason `json:"reason,omitempty"`
126+
127+
// Human-readable message indicating details about the last transition.
128+
Message string `json:"message,omitempty"`
129+
130+
// Last time the condition transitioned from one status to another.
131+
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
132+
}
133+
134+
// IstioRevisionConditionType represents the type of the condition. Condition stages are:
135+
// Installed, Reconciled, Ready
136+
type IstioRevisionTagConditionType string
137+
138+
// IstioRevisionConditionReason represents a short message indicating how the condition came
139+
// to be in its present state.
140+
type IstioRevisionTagConditionReason string
141+
142+
const (
143+
// IstioRevisionConditionReconciled signifies whether the controller has
144+
// successfully reconciled the resources defined through the CR.
145+
IstioRevisionTagConditionReconciled IstioRevisionTagConditionType = "Reconciled"
146+
147+
// IstioRevisionTagNameAlreadyExists indicates that the a revision with the same name as the IstioRevisionTag already exists.
148+
IstioRevisionTagReasonNameAlreadyExists IstioRevisionTagConditionReason = "NameAlreadyExists"
149+
150+
// IstioRevisionTagReasonReferenceNotFound indicates that the resource referenced by the tag's TargetRef was not found
151+
IstioRevisionTagReasonReferenceNotFound IstioRevisionTagConditionReason = "RefNotFound"
152+
153+
// IstioRevisionReasonReconcileError indicates that the reconciliation of the resource has failed, but will be retried.
154+
IstioRevisionTagReasonReconcileError IstioRevisionTagConditionReason = "ReconcileError"
155+
)
156+
157+
const (
158+
// IstioRevisionConditionInUse signifies whether any workload is configured to use the revision.
159+
IstioRevisionTagConditionInUse IstioRevisionTagConditionType = "InUse"
160+
161+
// IstioRevisionReasonReferencedByWorkloads indicates that the revision is referenced by at least one pod or namespace.
162+
IstioRevisionTagReasonReferencedByWorkloads IstioRevisionTagConditionReason = "ReferencedByWorkloads"
163+
164+
// IstioRevisionReasonNotReferenced indicates that the revision is not referenced by any pod or namespace.
165+
IstioRevisionTagReasonNotReferenced IstioRevisionTagConditionReason = "NotReferencedByAnything"
166+
167+
// IstioRevisionReasonUsageCheckFailed indicates that the operator could not check whether any workloads use the revision.
168+
IstioRevisionTagReasonUsageCheckFailed IstioRevisionTagConditionReason = "UsageCheckFailed"
169+
)
170+
171+
const (
172+
// IstioRevisionTagReasonHealthy indicates that the revision tag has been successfully reconciled and is in use.
173+
IstioRevisionTagReasonHealthy IstioRevisionTagConditionReason = "Healthy"
174+
)
175+
176+
// +kubebuilder:object:root=true
177+
// +kubebuilder:resource:scope=Cluster,shortName=istiorevtag,categories=istio-io
178+
// +kubebuilder:subresource:status
179+
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.state",description="The current state of this object."
180+
// +kubebuilder:printcolumn:name="In use",type="string",JSONPath=".status.conditions[?(@.type==\"InUse\")].status",description="Whether the tag is being used by workloads."
181+
// +kubebuilder:printcolumn:name="Revision",type="string",JSONPath=".status.istioRevision",description="The IstioRevision this object is referencing."
182+
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="The age of the object"
183+
184+
// IstioRevisionTag references a Istio or IstioRevision object and serves as an alias for sidecar injection.
185+
type IstioRevisionTag struct {
186+
metav1.TypeMeta `json:",inline"`
187+
metav1.ObjectMeta `json:"metadata,omitempty"`
188+
189+
Spec IstioRevisionTagSpec `json:"spec,omitempty"`
190+
Status IstioRevisionTagStatus `json:"status,omitempty"`
191+
}
192+
193+
// +kubebuilder:object:root=true
194+
195+
// IstioRevisionList contains a list of IstioRevision
196+
type IstioRevisionTagList struct {
197+
metav1.TypeMeta `json:",inline"`
198+
metav1.ListMeta `json:"metadata,omitempty"`
199+
Items []IstioRevisionTag `json:"items"`
200+
}
201+
202+
func init() {
203+
SchemeBuilder.Register(&IstioRevisionTag{}, &IstioRevisionTagList{})
204+
}

api/v1alpha1/values_types.gen.go

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 128 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)