Repository navigation
refactor the FromProto methods to return structs - #63
Merged
Merged
Conversation
zainawaisn
reviewed
Nov 4, 2026
zainawaisn
reviewed
Nov 4, 2026
zainawaisn
reviewed
Nov 4, 2026
zainawaisn
reviewed
Nov 4, 2026
Refactors the `FromProto` methods on the Namespace-related structs in
some important ways:
1. Use a value receiver and return a struct or pointer to a struct
created by reading the supplied proto message. This gets rid of a
bunch of nil checks and repetitive code, changing things from this:
```go
// FromProto sets the spec from the supplied Temporal Cloud NamespaceSpec.
// Project and tags are not part of the Temporal Cloud NamespaceSpec, so they
// are left unchanged; [Namespace.FromProto] sets them.
func (s *NamespaceSpec) FromProto(in *tcloudnamespacev1.NamespaceSpec) {
s.Replicas = ReplicasFromProto(in.GetReplicas())
s.RetentionDays = in.GetRetentionDays()
if in.GetMtlsAuth() == nil {
s.MTLSAuth = nil
} else {
s.MTLSAuth = &MTLSAuthSpec{}
s.MTLSAuth.FromProto(in.GetMtlsAuth())
}
if in.GetApiKeyAuth() == nil {
s.APIKeyAuth = nil
} else {
s.APIKeyAuth = &APIKeyAuthSpec{}
s.APIKeyAuth.FromProto(in.GetApiKeyAuth())
}
s.SearchAttributes = SearchAttributesFromProto(in.GetSearchAttributes())
if in.GetCodecServer() == nil {
s.CodecServer = nil
} else {
s.CodecServer = &CodecServerSpec{}
s.CodecServer.FromProto(in.GetCodecServer())
}
s.Lifecycle = LifecycleFromProto(in.GetLifecycle())
if in.GetHighAvailability() == nil {
s.HighAvailability = nil
} else {
s.HighAvailability = &HighAvailabilitySpec{}
s.HighAvailability.FromProto(in.GetHighAvailability())
}
s.ConnectivityRuleIDs = slices.Clone(in.GetConnectivityRuleIds())
// A capacity spec with no mode set carries nothing the CR can represent, so
// it is treated as unset.
if c := in.GetCapacitySpec(); c.GetOnDemand() == nil && c.GetProvisioned() == nil {
s.Capacity = nil
} else {
s.Capacity = &CapacitySpec{}
s.Capacity.FromProto(c)
}
if in.GetFairness() == nil {
s.Fairness = nil
} else {
s.Fairness = &FairnessSpec{}
s.Fairness.FromProto(in.GetFairness())
}
if in.GetEncryptionValidation() == nil {
s.EncryptionValidation = nil
} else {
s.EncryptionValidation = &EncryptionValidationSpec{}
s.EncryptionValidation.FromProto(in.GetEncryptionValidation())
}
s.Description = in.GetDescription()
}
```
to this:
```go
// FromProto returns a NamespaceSpec constructed from the supplied Temporal
// Cloud NamespaceSpec.
func (s NamespaceSpec) FromProto(in *tcloudnamespacev1.NamespaceSpec) NamespaceSpec {
if in == nil {
return NamespaceSpec{}
}
out := NamespaceSpec{
Description: in.GetDescription(),
Replicas: ReplicasFromProto(in.GetReplicas()),
RetentionDays: in.GetRetentionDays(),
SearchAttributes: SearchAttributesFromProto(in.GetSearchAttributes()),
Lifecycle: LifecycleFromProto(in.GetLifecycle()),
ConnectivityRuleIDs: slices.Clone(in.GetConnectivityRuleIds()),
}
var mtlsAuthSpec MTLSAuthSpec
out.MTLSAuth = mtlsAuthSpec.FromProto(in.GetMtlsAuth())
var apiKeyAuthSpec APIKeyAuthSpec
out.APIKeyAuth = apiKeyAuthSpec.FromProto(in.GetApiKeyAuth())
var codecSpec CodecServerSpec
out.CodecServer = codecSpec.FromProto(in.GetCodecServer())
var haSpec HighAvailabilitySpec
out.HighAvailability = haSpec.FromProto(in.GetHighAvailability())
var capSpec CapacitySpec
out.Capacity = capSpec.FromProto(in.GetCapacitySpec())
var fairSpec FairnessSpec
out.Fairness = fairSpec.FromProto(in.GetFairness())
var encValSpec EncryptionValidationSpec
out.EncryptionValidation = encValSpec.FromProto(in.GetEncryptionValidation())
return out
}
```
2. Updates the `Reconciler.ResourceSetLatest` method to construct the
`latest` CR from only the returned results from the call to Temporal
Cloud Ops `GetNamespace` API method.
I'm considering changing the calling interface for `ResourceSetLatest`
to *not* mutate the supplied `latest` parameter but rather return an
updated CR with the latest read information from the external API call.
This will make the `types.Reconciler` interface methods that work with
`types.Resource` parameters consistent: none will ever mutate parameters
but will instead return a copy of the parameter updated with whatever
the method changed about the CR's representation.
Signed-off-by: Jay Pipes <jay.pipes@temporal.io>
jaypipes
force-pushed
the
to-from-proto
branch
from
November 4, 2026 19:52
aeab615 to
5ce1615
Compare
zainawaisn
approved these changes
Nov 4, 2026
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.
Refactors the
FromProtomethods on the Namespace-related structs in some important ways:to this:
Reconciler.ResourceSetLatestmethod to construct thelatestCR from only the returned results from the call to Temporal Cloud OpsGetNamespaceAPI method.I'm considering changing
the calling interface for
ResourceSetLatestto not mutate the suppliedlatestparameter but rather return an updated CR with the latest read information from the external API call. This will make thetypes.Reconcilerinterface methods that work withtypes.Resourceparameters consistent: none will ever mutate parameters but will instead return a copy of the parameter updated with whatever the method changed about the CR's representation.