1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-24 21:08:03 +00:00

Add an attribute observedgeneration (#714)

* Add an attribute observedgeneration

* add unit tests
This commit is contained in:
Sakala Venkata Krishna Rohit
2025-08-07 10:30:06 -07:00
committed by GitHub
parent a020084518
commit 6946ffe8aa
9 changed files with 137 additions and 21 deletions

View File

@@ -77,5 +77,27 @@ func forVersion(group, kind string, version v1.CustomResourceDefinitionVersion,
}
if version.Schema != nil && version.Schema.OpenAPIV3Schema != nil {
schema.Description = version.Schema.OpenAPIV3Schema.Description
if hasObservedGeneration(version.Schema.OpenAPIV3Schema) {
schemas.SetHasObservedGeneration(schema.Schema, true)
}
}
}
func hasObservedGeneration(schema *v1.JSONSchemaProps) bool {
if schema == nil {
return false
}
if schema.Properties == nil {
return false
}
status, ok := schema.Properties["status"]
if !ok {
return false
}
if status.Properties == nil {
return false
}
_, found := status.Properties["observedGeneration"]
return found
}

View File

@@ -306,3 +306,73 @@ func TestAddCustomResources(t *testing.T) {
})
}
}
func TestHasObservedGeneration(t *testing.T) {
tests := []struct {
name string
schema *v1.JSONSchemaProps
expected bool
}{
{
name: "nil schema",
schema: nil,
expected: false,
},
{
name: "nil properties",
schema: &v1.JSONSchemaProps{},
expected: false,
},
{
name: "no status property",
schema: &v1.JSONSchemaProps{
Properties: map[string]v1.JSONSchemaProps{
"foo": {},
},
},
expected: false,
},
{
name: "status property without properties",
schema: &v1.JSONSchemaProps{
Properties: map[string]v1.JSONSchemaProps{
"status": {},
},
},
expected: false,
},
{
name: "status property with properties but no observedGeneration",
schema: &v1.JSONSchemaProps{
Properties: map[string]v1.JSONSchemaProps{
"status": {
Properties: map[string]v1.JSONSchemaProps{
"foo": {},
},
},
},
},
expected: false,
},
{
name: "status property with observedGeneration",
schema: &v1.JSONSchemaProps{
Properties: map[string]v1.JSONSchemaProps{
"status": {
Properties: map[string]v1.JSONSchemaProps{
"observedGeneration": {},
},
},
},
},
expected: true,
},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
result := hasObservedGeneration(tt.schema)
assert.Equal(t, tt.expected, result)
})
}
}