@@ -119,6 +119,16 @@ func SetSDK(
119119 out := "\n "
120120 indent := strings .Repeat ("\t " , indentLevel )
121121
122+ // The owning resource variable, used so secret fields can pass it to the
123+ // runtime's SecretValueFromReference (which sets the cross-namespace
124+ // deprecation ACK.Advisory condition on it). It is the leading token of
125+ // the source variable path (e.g. "r" from "r.ko"); the generated
126+ // *resource type implements acktypes.ConditionManager.
127+ resourceVarName := sourceVarName
128+ if dot := strings .IndexByte (resourceVarName , '.' ); dot != - 1 {
129+ resourceVarName = resourceVarName [:dot ]
130+ }
131+
122132 // Check if there's an input wrapper field path configured. If so, we need
123133 // to create a wrapper struct and populate its fields from the CRD spec,
124134 // then assign the wrapper to the input shape's wrapper field.
@@ -402,6 +412,7 @@ func SetSDK(
402412 )
403413 containerOut , err := setSDKForContainer (
404414 cfg , r ,
415+ resourceVarName ,
405416 memberName ,
406417 memberVarName ,
407418 sourceFieldPath ,
@@ -430,6 +441,7 @@ func SetSDK(
430441 if r .IsSecretField (memberName ) {
431442 out += setSDKForSecret (
432443 cfg , r ,
444+ resourceVarName ,
433445 memberName ,
434446 targetVarName ,
435447 sourceAdaptedVarName ,
@@ -1005,6 +1017,10 @@ func setSDKReadMany(
10051017func setSDKForContainer (
10061018 cfg * ackgenconfig.Config ,
10071019 r * model.CRD ,
1020+ // The name of the variable holding the owning resource (a *resource,
1021+ // which implements acktypes.ConditionManager). Threaded down so secret
1022+ // fields nested in collections can pass it to SecretValueFromReference.
1023+ resourceVarName string ,
10081024 // The name of the SDK Input shape member we're outputting for
10091025 targetFieldName string ,
10101026 // The variable name that we want to set a value to
@@ -1023,6 +1039,7 @@ func setSDKForContainer(
10231039 case "structure" :
10241040 return SetSDKForStruct (
10251041 cfg , r ,
1042+ resourceVarName ,
10261043 targetFieldName ,
10271044 targetVarName ,
10281045 targetShapeRef ,
@@ -1034,6 +1051,7 @@ func setSDKForContainer(
10341051 case "list" :
10351052 return setSDKForSlice (
10361053 cfg , r ,
1054+ resourceVarName ,
10371055 targetFieldName ,
10381056 targetVarName ,
10391057 targetShapeRef ,
@@ -1045,6 +1063,7 @@ func setSDKForContainer(
10451063 case "map" :
10461064 return setSDKForMap (
10471065 cfg , r ,
1066+ resourceVarName ,
10481067 targetFieldName ,
10491068 targetVarName ,
10501069 targetShapeRef ,
@@ -1056,6 +1075,7 @@ func setSDKForContainer(
10561075 case "union" :
10571076 return setSDKForUnion (
10581077 cfg , r ,
1078+ resourceVarName ,
10591079 targetFieldName ,
10601080 targetVarName ,
10611081 targetShapeRef ,
@@ -1074,6 +1094,7 @@ func setSDKForContainer(
10741094 )
10751095 out += setSDKForSecret (
10761096 cfg , r ,
1097+ resourceVarName ,
10771098 "" ,
10781099 targetVarName ,
10791100 sourceVarName ,
@@ -1101,14 +1122,17 @@ func setSDKForContainer(
11011122// the value of a Secret when the type of the source variable is a
11021123// SecretKeyReference.
11031124//
1104- // Cross-namespace validation (and the Phase 1 deprecation warning) is
1105- // performed inside the runtime's SecretValueFromReference, so it is not
1106- // emitted here. This ensures every caller is covered, including custom
1107- // update functions and hooks that call SecretValueFromReference directly.
1125+ // Cross-namespace validation (and the Phase 1 deprecation notice) is performed
1126+ // inside the runtime's SecretValueFromReference, so it is not emitted here.
1127+ // This ensures every caller is covered, including custom update functions and
1128+ // hooks that call SecretValueFromReference directly. The owning resource is
1129+ // passed as the second argument so the runtime can set the cross-namespace
1130+ // deprecation ACK.Advisory condition on it; it is derived from the source
1131+ // variable (e.g. "r" from "r.ko.Spec.MasterUserPassword").
11081132//
11091133// The Go code output from this function looks like this:
11101134//
1111- // tmpSecret, err := rm.rr.SecretValueFromReference(ctx, ko.Spec.MasterUserPassword)
1135+ // tmpSecret, err := rm.rr.SecretValueFromReference(ctx, r, r. ko.Spec.MasterUserPassword)
11121136// if err != nil {
11131137// return nil, ackrequeue.Needed(err)
11141138// }
@@ -1122,6 +1146,11 @@ func setSDKForContainer(
11221146func setSDKForSecret (
11231147 cfg * ackgenconfig.Config ,
11241148 r * model.CRD ,
1149+ // The name of the variable holding the owning resource (a
1150+ // *resource, which implements acktypes.ConditionManager). It is passed to
1151+ // SecretValueFromReference so the runtime can set the cross-namespace
1152+ // deprecation ACK.Advisory condition on it. Typically "r" or "desired".
1153+ resourceVarName string ,
11251154 // The name of the SDK Shape field we're setting
11261155 targetFieldName string ,
11271156 // The variable name that we want to set a value on
@@ -1138,12 +1167,14 @@ func setSDKForSecret(
11381167 // Cross-namespace validation for the secret reference is performed inside
11391168 // the runtime's SecretValueFromReference, so that every call site is
11401169 // covered (including custom update functions and hooks). No per-call
1141- // validation is generated here.
1170+ // validation is generated here. The owning resource is passed so the
1171+ // runtime can set the cross-namespace deprecation ACK.Advisory condition
1172+ // on it.
11421173
1143- // tmpSecret, err := rm.rr.SecretValueFromReference(ctx, ko.Spec.MasterUserPassword)
1174+ // tmpSecret, err := rm.rr.SecretValueFromReference(ctx, r, r. ko.Spec.MasterUserPassword)
11441175 out += fmt .Sprintf (
1145- "%s\t %s, err := rm.rr.SecretValueFromReference(ctx, %s)\n " ,
1146- indent , secVar , sourceVarName ,
1176+ "%s\t %s, err := rm.rr.SecretValueFromReference(ctx, %s, %s )\n " ,
1177+ indent , secVar , resourceVarName , sourceVarName ,
11471178 )
11481179 // if err != nil {
11491180 // return nil, ackrequeue.Needed(err)
@@ -1175,6 +1206,12 @@ func setSDKForSecret(
11751206func SetSDKForStruct (
11761207 cfg * ackgenconfig.Config ,
11771208 r * model.CRD ,
1209+ // The name of the variable holding the owning resource (a *resource,
1210+ // which implements acktypes.ConditionManager). Threaded down so secret
1211+ // fields nested in this struct can pass it to SecretValueFromReference.
1212+ // When this is the entry point (e.g. the GoCodeSetSDKForStruct template
1213+ // helper), it is derived from the leading token of sourceVarName.
1214+ resourceVarName string ,
11781215 // The name of the CR field we're outputting for
11791216 targetFieldName string ,
11801217 // The variable name that we want to set a value to
@@ -1191,6 +1228,16 @@ func SetSDKForStruct(
11911228 out := ""
11921229 indent := strings .Repeat ("\t " , indentLevel )
11931230 targetShape := targetShapeRef .Shape
1231+ // When SetSDKForStruct is invoked as a top-level entry point (rather than
1232+ // recursively via setSDKForContainer), resourceVarName is not supplied by
1233+ // the caller. Fall back to the leading token of the source variable path
1234+ // (e.g. "r" from "r.ko.Spec.Foo"), which names the owning *resource.
1235+ if resourceVarName == "" {
1236+ resourceVarName = sourceVarName
1237+ if dot := strings .IndexByte (resourceVarName , '.' ); dot != - 1 {
1238+ resourceVarName = resourceVarName [:dot ]
1239+ }
1240+ }
11941241
11951242 for memberIndex , memberName := range targetShape .MemberNames () {
11961243 memberShapeRef := targetShape .MemberRefs [memberName ]
@@ -1248,6 +1295,7 @@ func SetSDKForStruct(
12481295 )
12491296 containerOut , err := setSDKForContainer (
12501297 cfg , r ,
1298+ resourceVarName ,
12511299 memberName ,
12521300 memberVarName ,
12531301 memberFieldPath ,
@@ -1276,6 +1324,7 @@ func SetSDKForStruct(
12761324 if r .IsSecretField (memberFieldPath ) {
12771325 out += setSDKForSecret (
12781326 cfg , r ,
1327+ resourceVarName ,
12791328 memberName ,
12801329 targetVarName ,
12811330 sourceAdaptedVarName ,
@@ -1310,6 +1359,10 @@ func SetSDKForStruct(
13101359func setSDKForSlice (
13111360 cfg * ackgenconfig.Config ,
13121361 r * model.CRD ,
1362+ // The name of the variable holding the owning resource (a *resource,
1363+ // which implements acktypes.ConditionManager). Threaded down so secret
1364+ // fields nested in this slice can pass it to SecretValueFromReference.
1365+ resourceVarName string ,
13131366 // The name of the CR field we're outputting for
13141367 targetFieldName string ,
13151368 // The variable name that we want to set a value to
@@ -1382,6 +1435,7 @@ func setSDKForSlice(
13821435 } else {
13831436 containerOut , err := setSDKForContainer (
13841437 cfg , r ,
1438+ resourceVarName ,
13851439 containerFieldName ,
13861440 elemVarName ,
13871441 sourceFieldPath ,
@@ -1414,6 +1468,10 @@ func setSDKForSlice(
14141468func setSDKForMap (
14151469 cfg * ackgenconfig.Config ,
14161470 r * model.CRD ,
1471+ // The name of the variable holding the owning resource (a *resource,
1472+ // which implements acktypes.ConditionManager). Threaded down so secret
1473+ // fields nested in this map can pass it to SecretValueFromReference.
1474+ resourceVarName string ,
14171475 // The name of the CR field we're outputting for
14181476 targetFieldName string ,
14191477 // The variable name that we want to set a value to
@@ -1481,6 +1539,7 @@ func setSDKForMap(
14811539 } else {
14821540 containerOut , err := setSDKForContainer (
14831541 cfg , r ,
1542+ resourceVarName ,
14841543 containerFieldName ,
14851544 valVarName ,
14861545 sourceFieldPath ,
@@ -1844,6 +1903,10 @@ func resolveAWSMapValueType(valueType string) string {
18441903func setSDKForUnion (
18451904 cfg * ackgenconfig.Config ,
18461905 r * model.CRD ,
1906+ // The name of the variable holding the owning resource (a *resource,
1907+ // which implements acktypes.ConditionManager). Threaded down so secret
1908+ // fields nested in this union can pass it to SecretValueFromReference.
1909+ resourceVarName string ,
18471910 // The name of the CR field we're outputting for
18481911 targetFieldName string ,
18491912 // The variable name that we want to set a value to
@@ -1929,6 +1992,7 @@ func setSDKForUnion(
19291992 )
19301993 containerOut , err := setSDKForContainer (
19311994 cfg , r ,
1995+ resourceVarName ,
19321996 memberName ,
19331997 indexedVarName ,
19341998 memberFieldPath ,
0 commit comments