Compare commits

...

11 Commits
main ... v1.2.3

Author SHA1 Message Date
Sergen Yalçın 8b328b5feb
Merge pull request #374 from crossplane/backport-373-to-release-1.2
[Backport release-1.2] Move license statements to separate files (for tmpl files) to prevent license statement duplication
2024-03-14 14:27:05 +03:00
Sergen Yalçın 3e39bc3691 Remove blank line on top
Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
(cherry picked from commit 2d71c5b36d)
2024-03-14 11:14:34 +00:00
Sergen Yalçın 8ded1c0b01 Move license statements to separate files to prevent license statement duplication
Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
(cherry picked from commit a648048b9d)
2024-03-14 11:14:34 +00:00
Sergen Yalçın f472f48ea8
Merge pull request #366 from crossplane/backport-355-to-release-1.2
[Backport release-1.2] Fix slice type sensitive fieldpath generation
2024-03-06 23:28:28 +03:00
Sergen Yalçın 404ab86cb1 Change cases from string to type of FieldType
Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
(cherry picked from commit b63f33874c)
2024-03-06 16:45:41 +00:00
Sergen Yalçın aa58f1aaad Fix non-primitive type sensitive field generation
Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
(cherry picked from commit 8bf78e8106)
2024-03-06 16:45:41 +00:00
Sergen Yalçın 247b2d2d5f
Merge pull request #364 from crossplane/backport-358-to-release-1.2
[Backport release-1.2] Removing the applying of StateFuncs to parameters
2024-03-06 19:18:02 +03:00
Sergen Yalçın 9e55a83cc9 Remove the unnecessary case and add nolint
Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
(cherry picked from commit 956c7d489b)
2024-03-06 12:23:21 +00:00
Sergen Yalçın 11855fb98a Remove StateFunc calls
Signed-off-by: Sergen Yalçın <yalcinsergen97@gmail.com>
(cherry picked from commit 93af08a988)
2024-03-06 12:23:21 +00:00
Alper Rifat Ulucinar 00389e5c31
Merge pull request #353 from crossplane/backport-350-to-release-1.2
[Backport release-1.2] Check LateInitialize management policy in Plugin Framework external client
2024-02-22 15:01:59 +03:00
Cem Mergenci acb59402d6 Check LateInitialize management policy in Plugin Framework client.
Signed-off-by: Cem Mergenci <cmergenci@gmail.com>
(cherry picked from commit af31423729)
2024-02-21 13:06:54 +00:00
19 changed files with 56 additions and 59 deletions

View File

@ -27,6 +27,7 @@ import (
"github.com/hashicorp/terraform-plugin-go/tftypes"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets"
"sigs.k8s.io/controller-runtime/pkg/client"
"github.com/crossplane/upjet/pkg/config"
@ -270,13 +271,15 @@ func (n *terraformPluginFrameworkExternalClient) getDiffPlanResponse(ctx context
return nil, false, errors.Wrap(err, "cannot compare prior state and plan")
}
// filter diffs that has unknown plan value which corresponds to
// computed values. These cause unnecessary diff detection when only computed
// attribute diffs exist in the raw diff and no actual diff exists in the
// parametrizable attributes
// Filter diffs that have unknown plan values, which correspond to
// computed fields, and null plan values, which correspond to
// not-specified fields. Such cases cause unnecessary diff detection
// when only computed attributes or not-specified argument diffs
// exist in the raw diff and no actual diff exists in the
// parametrizable attributes.
filteredDiff := make([]tftypes.ValueDiff, 0)
for _, diff := range rawDiff {
if diff.Value1.IsKnown() {
if diff.Value1.IsKnown() && !diff.Value1.IsNull() {
filteredDiff = append(filteredDiff, diff)
}
}
@ -348,10 +351,16 @@ func (n *terraformPluginFrameworkExternalClient) Observe(ctx context.Context, mg
if err != nil {
return managed.ExternalObservation{}, errors.Wrap(err, "cannot marshal the attributes of the new state for late-initialization")
}
specUpdateRequired, err = mg.(resource.Terraformed).LateInitialize(buff)
if err != nil {
return managed.ExternalObservation{}, errors.Wrap(err, "cannot late-initialize the managed resource")
policySet := sets.New[xpv1.ManagementAction](mg.(resource.Terraformed).GetManagementPolicies()...)
policyHasLateInit := policySet.HasAny(xpv1.ManagementActionLateInitialize, xpv1.ManagementActionAll)
if policyHasLateInit {
specUpdateRequired, err = mg.(resource.Terraformed).LateInitialize(buff)
if err != nil {
return managed.ExternalObservation{}, errors.Wrap(err, "cannot late-initialize the managed resource")
}
}
err = mg.(resource.Terraformed).SetObservation(stateValueMap)
if err != nil {
return managed.ExternalObservation{}, errors.Errorf("could not set observation: %v", err)

View File

@ -158,13 +158,13 @@ func getExtendedParameters(ctx context.Context, tr resource.Terraformed, externa
return params, nil
}
func (c *TerraformPluginSDKConnector) processParamsWithStateFunc(schemaMap map[string]*schema.Schema, params map[string]any) map[string]any {
func (c *TerraformPluginSDKConnector) processParamsWithHCLParser(schemaMap map[string]*schema.Schema, params map[string]any) map[string]any {
if params == nil {
return params
}
for key, param := range params {
if sc, ok := schemaMap[key]; ok {
params[key] = c.applyStateFuncToParam(sc, param)
params[key] = c.applyHCLParserToParam(sc, param)
} else {
params[key] = param
}
@ -172,11 +172,11 @@ func (c *TerraformPluginSDKConnector) processParamsWithStateFunc(schemaMap map[s
return params
}
func (c *TerraformPluginSDKConnector) applyStateFuncToParam(sc *schema.Schema, param any) any { //nolint:gocyclo
func (c *TerraformPluginSDKConnector) applyHCLParserToParam(sc *schema.Schema, param any) any { //nolint:gocyclo
if param == nil {
return param
}
switch sc.Type {
switch sc.Type { //nolint:exhaustive
case schema.TypeMap:
if sc.Elem == nil {
return param
@ -185,7 +185,7 @@ func (c *TerraformPluginSDKConnector) applyStateFuncToParam(sc *schema.Schema, p
// TypeMap only supports schema in Elem
if mapSchema, ok := sc.Elem.(*schema.Schema); ok && okParam {
for pk, pv := range pmap {
pmap[pk] = c.applyStateFuncToParam(mapSchema, pv)
pmap[pk] = c.applyHCLParserToParam(mapSchema, pv)
}
return pmap
}
@ -196,13 +196,13 @@ func (c *TerraformPluginSDKConnector) applyStateFuncToParam(sc *schema.Schema, p
pArray, okParam := param.([]any)
if setSchema, ok := sc.Elem.(*schema.Schema); ok && okParam {
for i, p := range pArray {
pArray[i] = c.applyStateFuncToParam(setSchema, p)
pArray[i] = c.applyHCLParserToParam(setSchema, p)
}
return pArray
} else if setResource, ok := sc.Elem.(*schema.Resource); ok {
for i, p := range pArray {
if resParam, okRParam := p.(map[string]any); okRParam {
pArray[i] = c.processParamsWithStateFunc(setResource.Schema, resParam)
pArray[i] = c.processParamsWithHCLParser(setResource.Schema, resParam)
}
}
}
@ -216,16 +216,6 @@ func (c *TerraformPluginSDKConnector) applyStateFuncToParam(sc *schema.Schema, p
param = hclProccessedParam
}
}
if sc.StateFunc != nil {
return sc.StateFunc(param)
}
return param
case schema.TypeBool, schema.TypeInt, schema.TypeFloat:
if sc.StateFunc != nil {
return sc.StateFunc(param)
}
return param
case schema.TypeInvalid:
return param
default:
return param
@ -252,7 +242,7 @@ func (c *TerraformPluginSDKConnector) Connect(ctx context.Context, mg xpresource
if err != nil {
return nil, errors.Wrapf(err, "failed to get the extended parameters for resource %q", mg.GetName())
}
params = c.processParamsWithStateFunc(c.config.TerraformResource.Schema, params)
params = c.processParamsWithHCLParser(c.config.TerraformResource.Schema, params)
schemaBlock := c.config.TerraformResource.CoreConfigSchema()
rawConfig, err := schema.JSONMapToStateValue(params, schemaBlock)

View File

@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: 2023 The Crossplane Authors <https://crossplane.io>
//
// SPDX-License-Identifier: Apache-2.0
{{ .Header }}
{{ .GenStatement }}

View File

@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 The Crossplane Authors <https://crossplane.io>
SPDX-License-Identifier: Apache-2.0

View File

@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: 2023 The Crossplane Authors <https://crossplane.io>
//
// SPDX-License-Identifier: Apache-2.0
{{ .Header }}
{{ .GenStatement }}

View File

@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 The Crossplane Authors <https://crossplane.io>
SPDX-License-Identifier: Apache-2.0

View File

@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: 2023 The Crossplane Authors <https://crossplane.io>
//
// SPDX-License-Identifier: Apache-2.0
{{ .Header }}
{{ .GenStatement }}

View File

@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 The Crossplane Authors <https://crossplane.io>
SPDX-License-Identifier: Apache-2.0

View File

@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: 2023 The Crossplane Authors <https://crossplane.io>
//
// SPDX-License-Identifier: Apache-2.0
{{ .Header }}
{{ .GenStatement }}

View File

@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 The Crossplane Authors <https://crossplane.io>
SPDX-License-Identifier: Apache-2.0

View File

@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: 2023 The Crossplane Authors <https://crossplane.io>
//
// SPDX-License-Identifier: Apache-2.0
{{ .Header }}
{{ .GenStatement }}

View File

@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 The Crossplane Authors <https://crossplane.io>
SPDX-License-Identifier: Apache-2.0

View File

@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: 2023 The Crossplane Authors <https://crossplane.io>
//
// SPDX-License-Identifier: Apache-2.0
{{ .Header }}
{{ .GenStatement }}

View File

@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 The Crossplane Authors <https://crossplane.io>
SPDX-License-Identifier: Apache-2.0

View File

@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: 2023 The Crossplane Authors <https://crossplane.io>
//
// SPDX-License-Identifier: Apache-2.0
package controller
import (

View File

@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 The Crossplane Authors <https://crossplane.io>
SPDX-License-Identifier: Apache-2.0

View File

@ -1,7 +1,3 @@
// SPDX-FileCopyrightText: 2023 The Crossplane Authors <https://crossplane.io>
//
// SPDX-License-Identifier: Apache-2.0
{{ .Header }}
{{ .GenStatement }}

View File

@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 The Crossplane Authors <https://crossplane.io>
SPDX-License-Identifier: Apache-2.0

View File

@ -268,7 +268,13 @@ func NewSensitiveField(g *Builder, cfg *config.Resource, r *resource, sch *schem
return nil, true, nil
}
sfx := "SecretRef"
cfg.Sensitive.AddFieldPath(fieldPathWithWildcard(f.TerraformPaths), "spec.forProvider."+fieldPathWithWildcard(f.CRDPaths)+sfx)
switch f.FieldType.(type) {
case *types.Slice:
f.CRDPaths[len(f.CRDPaths)-2] = f.CRDPaths[len(f.CRDPaths)-2] + sfx
cfg.Sensitive.AddFieldPath(fieldPathWithWildcard(f.TerraformPaths), "spec.forProvider."+fieldPathWithWildcard(f.CRDPaths))
default:
cfg.Sensitive.AddFieldPath(fieldPathWithWildcard(f.TerraformPaths), "spec.forProvider."+fieldPathWithWildcard(f.CRDPaths)+sfx)
}
// todo(turkenh): do we need to support other field types as sensitive?
if f.FieldType.String() != "string" && f.FieldType.String() != "*string" && f.FieldType.String() != "[]string" &&
f.FieldType.String() != "[]*string" && f.FieldType.String() != "map[string]string" && f.FieldType.String() != "map[string]*string" {