Skip to content

Commit e94d1f5

Browse files
committed
Add operation version as resource status condition
Expose version as resource condition "OperatorVersion". Transition time reflects time of last upgrade. Add conditions into status of "remote" resources. Signed-off-by: Konstantin Khlebnikov <[email protected]>
1 parent 9b038f7 commit e94d1f5

File tree

19 files changed

+357
-10
lines changed

19 files changed

+357
-10
lines changed

api/v1/ytsaurus_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,7 @@ const (
858858
// CommonRemoteNodeStatus is a set of fields shared between `Remote*NodesStatus`.
859859
// It is inlined in these specs.
860860
type CommonRemoteNodeStatus struct {
861+
Conditions []metav1.Condition `json:"conditions,omitempty"`
861862
// Reflects resource generation which was used for updating status.
862863
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
863864
ReleaseStatus RemoteNodeReleaseStatus `json:"releaseStatus,omitempty"`

api/v1/zz_generated.deepcopy.go

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

config/crd/bases/cluster.ytsaurus.tech_remotedatanodes.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,6 +1975,53 @@ spec:
19751975
status:
19761976
description: RemoteDataNodesStatus defines the observed state of RemoteDataNodes
19771977
properties:
1978+
conditions:
1979+
items:
1980+
description: Condition contains details for one aspect of the current
1981+
state of this API...
1982+
properties:
1983+
lastTransitionTime:
1984+
description: lastTransitionTime is the last time the condition
1985+
transitioned from one status...
1986+
format: date-time
1987+
type: string
1988+
message:
1989+
description: message is a human readable message indicating
1990+
details about the transition.
1991+
maxLength: 32768
1992+
type: string
1993+
observedGeneration:
1994+
description: observedGeneration represents the .metadata.
1995+
format: int64
1996+
minimum: 0
1997+
type: integer
1998+
reason:
1999+
description: reason contains a programmatic identifier indicating
2000+
the reason for the...
2001+
maxLength: 1024
2002+
minLength: 1
2003+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
2004+
type: string
2005+
status:
2006+
description: status of the condition, one of True, False, Unknown.
2007+
enum:
2008+
- "True"
2009+
- "False"
2010+
- Unknown
2011+
type: string
2012+
type:
2013+
description: type of condition in CamelCase or in foo.example.com/CamelCase.
2014+
maxLength: 316
2015+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
2016+
type: string
2017+
required:
2018+
- lastTransitionTime
2019+
- message
2020+
- reason
2021+
- status
2022+
- type
2023+
type: object
2024+
type: array
19782025
observedGeneration:
19792026
description: Reflects resource generation which was used for updating
19802027
status.

config/crd/bases/cluster.ytsaurus.tech_remoteexecnodes.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,6 +2192,53 @@ spec:
21922192
status:
21932193
description: RemoteExecNodesStatus defines the observed state of RemoteExecNodes
21942194
properties:
2195+
conditions:
2196+
items:
2197+
description: Condition contains details for one aspect of the current
2198+
state of this API...
2199+
properties:
2200+
lastTransitionTime:
2201+
description: lastTransitionTime is the last time the condition
2202+
transitioned from one status...
2203+
format: date-time
2204+
type: string
2205+
message:
2206+
description: message is a human readable message indicating
2207+
details about the transition.
2208+
maxLength: 32768
2209+
type: string
2210+
observedGeneration:
2211+
description: observedGeneration represents the .metadata.
2212+
format: int64
2213+
minimum: 0
2214+
type: integer
2215+
reason:
2216+
description: reason contains a programmatic identifier indicating
2217+
the reason for the...
2218+
maxLength: 1024
2219+
minLength: 1
2220+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
2221+
type: string
2222+
status:
2223+
description: status of the condition, one of True, False, Unknown.
2224+
enum:
2225+
- "True"
2226+
- "False"
2227+
- Unknown
2228+
type: string
2229+
type:
2230+
description: type of condition in CamelCase or in foo.example.com/CamelCase.
2231+
maxLength: 316
2232+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
2233+
type: string
2234+
required:
2235+
- lastTransitionTime
2236+
- message
2237+
- reason
2238+
- status
2239+
- type
2240+
type: object
2241+
type: array
21952242
observedGeneration:
21962243
description: Reflects resource generation which was used for updating
21972244
status.

config/crd/bases/cluster.ytsaurus.tech_remotetabletnodes.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,6 +1975,53 @@ spec:
19751975
status:
19761976
description: RemoteTabletNodesStatus defines the observed state of RemoteTabletNodes
19771977
properties:
1978+
conditions:
1979+
items:
1980+
description: Condition contains details for one aspect of the current
1981+
state of this API...
1982+
properties:
1983+
lastTransitionTime:
1984+
description: lastTransitionTime is the last time the condition
1985+
transitioned from one status...
1986+
format: date-time
1987+
type: string
1988+
message:
1989+
description: message is a human readable message indicating
1990+
details about the transition.
1991+
maxLength: 32768
1992+
type: string
1993+
observedGeneration:
1994+
description: observedGeneration represents the .metadata.
1995+
format: int64
1996+
minimum: 0
1997+
type: integer
1998+
reason:
1999+
description: reason contains a programmatic identifier indicating
2000+
the reason for the...
2001+
maxLength: 1024
2002+
minLength: 1
2003+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
2004+
type: string
2005+
status:
2006+
description: status of the condition, one of True, False, Unknown.
2007+
enum:
2008+
- "True"
2009+
- "False"
2010+
- Unknown
2011+
type: string
2012+
type:
2013+
description: type of condition in CamelCase or in foo.example.com/CamelCase.
2014+
maxLength: 316
2015+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
2016+
type: string
2017+
required:
2018+
- lastTransitionTime
2019+
- message
2020+
- reason
2021+
- status
2022+
- type
2023+
type: object
2024+
type: array
19782025
observedGeneration:
19792026
description: Reflects resource generation which was used for updating
19802027
status.

controllers/remotedatanodes_sync.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func (r *RemoteDataNodesReconciler) Sync(
5050
requeue = false
5151
}
5252
resource.Status.ObservedGeneration = resource.Generation
53+
apiProxy.UpdateOperatorVersion(&resource.Status.Conditions)
5354

5455
logger.Info("Setting status for remote data nodes", "status", resource.Status.ReleaseStatus)
5556
err = r.Client.Status().Update(ctx, resource)

controllers/remoteexecnodes_sync.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func (r *RemoteExecNodesReconciler) Sync(
5050
requeue = false
5151
}
5252
resource.Status.ObservedGeneration = resource.Generation
53+
apiProxy.UpdateOperatorVersion(&resource.Status.Conditions)
5354

5455
logger.Info("Setting status for remote exec nodes", "status", resource.Status.ReleaseStatus)
5556
err = r.Client.Status().Update(ctx, resource)

controllers/remotetabletnodes_sync.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func (r *RemoteTabletNodesReconciler) Sync(
5050
requeue = false
5151
}
5252
resource.Status.ObservedGeneration = resource.Generation
53+
apiProxy.UpdateOperatorVersion(&resource.Status.Conditions)
5354

5455
logger.Info("Setting status for remote tablet nodes", "status", resource.Status.ReleaseStatus)
5556
err = r.Client.Status().Update(ctx, resource)

docs/api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ _Appears in:_
397397

398398
| Field | Description | Default | Validation |
399399
| --- | --- | --- | --- |
400+
| `conditions` _[Condition](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#condition-v1-meta) array_ | | | |
400401
| `observedGeneration` _integer_ | Reflects resource generation which was used for updating status. | | |
401402
| `releaseStatus` _[RemoteNodeReleaseStatus](#remotenodereleasestatus)_ | | | |
402403

@@ -1937,6 +1938,7 @@ _Appears in:_
19371938

19381939
| Field | Description | Default | Validation |
19391940
| --- | --- | --- | --- |
1941+
| `conditions` _[Condition](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#condition-v1-meta) array_ | | | |
19401942
| `observedGeneration` _integer_ | Reflects resource generation which was used for updating status. | | |
19411943
| `releaseStatus` _[RemoteNodeReleaseStatus](#remotenodereleasestatus)_ | | | |
19421944

@@ -2041,6 +2043,7 @@ _Appears in:_
20412043

20422044
| Field | Description | Default | Validation |
20432045
| --- | --- | --- | --- |
2046+
| `conditions` _[Condition](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#condition-v1-meta) array_ | | | |
20442047
| `observedGeneration` _integer_ | Reflects resource generation which was used for updating status. | | |
20452048
| `releaseStatus` _[RemoteNodeReleaseStatus](#remotenodereleasestatus)_ | | | |
20462049

@@ -2179,6 +2182,7 @@ _Appears in:_
21792182

21802183
| Field | Description | Default | Validation |
21812184
| --- | --- | --- | --- |
2185+
| `conditions` _[Condition](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#condition-v1-meta) array_ | | | |
21822186
| `observedGeneration` _integer_ | Reflects resource generation which was used for updating status. | | |
21832187
| `releaseStatus` _[RemoteNodeReleaseStatus](#remotenodereleasestatus)_ | | | |
21842188

pkg/apiproxy/proxy.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ import (
66

77
corev1 "k8s.io/api/core/v1"
88
apierrors "k8s.io/apimachinery/pkg/api/errors"
9+
"k8s.io/apimachinery/pkg/api/meta"
910
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1011
"k8s.io/apimachinery/pkg/runtime"
1112
"k8s.io/apimachinery/pkg/types"
1213
"k8s.io/client-go/tools/record"
1314
ctrl "sigs.k8s.io/controller-runtime"
1415
"sigs.k8s.io/controller-runtime/pkg/client"
1516
"sigs.k8s.io/controller-runtime/pkg/log"
17+
18+
"github.com/ytsaurus/ytsaurus-k8s-operator/pkg/consts"
19+
"github.com/ytsaurus/ytsaurus-k8s-operator/pkg/version"
1620
)
1721

1822
type APIProxy interface {
@@ -25,6 +29,7 @@ type APIProxy interface {
2529
DeleteObject(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error
2630

2731
UpdateStatus(ctx context.Context) error
32+
UpdateOperatorVersion(conditions *[]metav1.Condition) bool
2833
}
2934

3035
type ConditionManager interface {
@@ -180,3 +185,19 @@ func (c *apiProxy) createAndReferenceObject(ctx context.Context, obj client.Obje
180185
func (c *apiProxy) UpdateStatus(ctx context.Context) error {
181186
return c.client.Status().Update(ctx, c.object)
182187
}
188+
189+
func (c *apiProxy) UpdateOperatorVersion(conditions *[]metav1.Condition) bool {
190+
operatorVersion := version.GetVersion()
191+
condition := meta.FindStatusCondition(*conditions, consts.ConditionOperatorVersion)
192+
if condition != nil && condition.Message != operatorVersion {
193+
// Remove condition to update transition time.
194+
meta.RemoveStatusCondition(conditions, consts.ConditionOperatorVersion)
195+
}
196+
return meta.SetStatusCondition(conditions, metav1.Condition{
197+
Type: consts.ConditionOperatorVersion,
198+
Status: metav1.ConditionTrue,
199+
ObservedGeneration: c.object.GetGeneration(),
200+
Reason: "Observed",
201+
Message: operatorVersion,
202+
})
203+
}

0 commit comments

Comments
 (0)