Skip to content

Code-generator fails to set payload for unions #2651

@knottnt

Description

@knottnt

Describe the bug
When generating code setting the API payload for a field marked as a "union" in the AWS API model the code-generator fails to both properly set Spec field values in API payload. Additionally, the isInterfaceSet variable isn't set to true preventing validation that only one member type of the union is set in the payload. An example of this can be seen in the pipes-controller.

if r.ko.Spec.SourceParameters.ManagedStreamingKafkaParameters.Credentials != nil {
	var f7f4f2 svcsdktypes.MSKAccessCredentials
	isInterfaceSet := false
	if r.ko.Spec.SourceParameters.ManagedStreamingKafkaParameters.Credentials.ClientCertificateTLSAuth != nil {
		if isInterfaceSet {
			return nil, ackerr.NewTerminalError(fmt.Errorf("can only set one of the members for ClientCertificateTlsAuth"))
		}
		f7f4f2f0Parent := &svcsdktypes.MSKAccessCredentialsMemberClientCertificateTlsAuth{}
		f7f4f2f0Parent.Value = *r.ko.Spec.SourceParameters.ManagedStreamingKafkaParameters.Credentials.ClientCertificateTLSAuth
	}
	if r.ko.Spec.SourceParameters.ManagedStreamingKafkaParameters.Credentials.SASLSCRAM512Auth != nil {
		if isInterfaceSet {
			return nil, ackerr.NewTerminalError(fmt.Errorf("can only set one of the members for SaslScram512Auth"))
		}
		f7f4f2f1Parent := &svcsdktypes.MSKAccessCredentialsMemberSaslScram512Auth{}
		f7f4f2f1Parent.Value = *r.ko.Spec.SourceParameters.ManagedStreamingKafkaParameters.Credentials.SASLSCRAM512Auth
	}
	f7f4.Credentials = f7f4f2
}

Steps to reproduce

  1. Open terminal in the code-generator directory
  2. Run make build-controller SERVICE=pipes to trigger build of controller with a union member
  3. Examine generated output for newCreateRequestPayload func in the pipes-controller/pkg/resource/pipe/sdk.go

Expected outcome
Generated code should set configured union member to relevant field in the API payload. If multiple union members are set isInterfaceSet should trigger an ACK.Terminal condition.

Environment
N/A

  • Kubernetes version
  • Using EKS (yes/no), if so version?
  • AWS service targeted (S3, RDS, etc.)

Metadata

Metadata

Assignees

Labels

area/code-generationIssues or PRs as related to controllers or docs code generationkind/bugCategorizes issue or PR as related to a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions