Repository navigation
feat(abstractions): resolve kind and apiVersion from the entity type - #1372
Merged
Merged
Conversation
GetKind() and GetApiVersion() return the kind and apiVersion of an object, or those of its type if the object carries none, e.g. a built-in type created with new. The operator logging and the owner reference exceptions use GetKind(), so they no longer show an empty or null kind for such objects (#989).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Built-in types created with
new(e.g.new V1Secret { Metadata = ... }) carry nokindandapiVersion. Theoperator logged
entity.Kinddirectly, so such an entity, e.g. one put intoITimedEntityQueue<V1Secret>by acontroller, showed up as
null/my-secretor/my-secretin logs. This matches #989, which could not be reproducedwith an entity from a watch event, since watch events always carry
kind.KubeOps.Abstractions.Entities.KubernetesExtensions:GetKind()andGetApiVersion()return the value of the object, or the one of its
[KubernetesEntity]attribute if the object carries none. Theywere private helpers for owner and object references since feat(abstractions)!: add controller references and deduplicate owner references #1355.
ToIdentifierString()and theKindfield of the entity logging scope useGetKind().already controlled by,has no namespace,must be cluster-scoped) name the resource withGetKind(); a child resource is usually created withnew.controllers.mdx; the XML docs say "built-in type"consistently.
Relates to #989. Items from
ListAsynccarry both fields since #1371, so this covers the remaining case.Public instead of
internalwithInternalsVisibleTo:KubeOps.Operatoronly requires a minimum version ofKubeOps.Abstractions, so an internal API could break at runtime with mixed package versions, and the repo grantsInternalsVisibleToonly to test projects.Tests
KubernetesExtensions.TypeMeta.Test.cs(new): values of the object, fallback fornulland empty values, group andversion for
V1Deployment.KubernetesExtensions.OwnerReferences.Test.cs: the childConfigMapis created withoutkind/apiVersion, andthe exception messages must contain
ConfigMap resource(5 tests fail withresource.Kind).KubernetesObjectExtensions.Test.csandEntityLoggingScope.Test.cs(new): aV1Secretwithoutkindis loggedas
Secret/my-secret(4 tests fail without the logging change).Checks
/code-review(low): no findings./simplify: switched the three exception messages toGetKind()(altitude), keptnullin the logging scope likethe other fields instead of
"", unified the wording to "built-in type". Not changed: no cache for the attributelookup, as it only runs when the object has no kind.
/security-review: no findings.dotnet build -c Releasewithout warnings,dotnet format --verify-no-changes,npm run buildindocs/, alltests of
KubeOps.Abstractions.Test(338) andKubeOps.Operator.Test(358 per framework) pass on net10.0 andnet11.0, including the integration tests against a local OrbStack cluster. One earlier full run hung in an
integration test; the reruns per framework passed.