Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor servicecatalog provisioned product resource #3

Conversation

teeverr
Copy link

@teeverr teeverr commented Sep 26, 2023

Description of your changes

Fixes #

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

@teeverr
Copy link
Author

teeverr commented Sep 26, 2023

It is a draft version, when it will pass pre review I will add changes to setup.go

@@ -192,3 +155,25 @@ func (c *custom) preDelete(_ context.Context, cr *svcapitypes.ProvisionedProduct
obj.ProvisionedProductName = aws.String(meta.GetExternalName(cr))
return false, nil
}

func setConditions(describeRecordOutput *svcsdk.DescribeRecordOutput, resp *svcsdk.DescribeProvisionedProductOutput, cr *svcapitypes.ProvisionedProduct) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This func still can't pass the linter, I will fix it tomorrow

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function looks ok, it is well defined and, yes, it has many cases, but it is consistent in what it does.
So I suggest to not break it or condensate too much the code just for the sake of cyclomatic complexity (it is 11 ...) because the readability will be worst in the end.

)

func provisioningParamsAreChanged(cfStackParams []cfsdkv2types.Parameter, currentParams []*svcapitypes.ProvisioningParameter) bool {
if len(cfStackParams) != len(currentParams) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check will be produce false positive isUpToDate check If we okay with that it is not necessary to specify every parameter

Copy link
Author

@teeverr teeverr Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that idk how to detect removed parameters. Providers doesn't contain info about previous params, ofc we can cache them but it's not persistant.
Thats why ExistingParameterHasBeenRemoved unit tests fails for now

@@ -105,23 +114,158 @@ func TestIsUpToDate(t *testing.T) {
args
want
}{
"ArtifactIdHasChanged": {
Copy link
Author

@teeverr teeverr Sep 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added tests for all major casses with Artifact and Product params

@@ -192,3 +155,25 @@ func (c *custom) preDelete(_ context.Context, cr *svcapitypes.ProvisionedProduct
obj.ProvisionedProductName = aws.String(meta.GetExternalName(cr))
return false, nil
}

func setConditions(describeRecordOutput *svcsdk.DescribeRecordOutput, resp *svcsdk.DescribeProvisionedProductOutput, cr *svcapitypes.ProvisionedProduct) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function looks ok, it is well defined and, yes, it has many cases, but it is consistent in what it does.
So I suggest to not break it or condensate too much the code just for the sake of cyclomatic complexity (it is 11 ...) because the readability will be worst in the end.

pkg/controller/servicecatalog/provisionedproduct/utils.go Outdated Show resolved Hide resolved
}
func (c *custom) getArtifactID(ds *svcapitypes.ProvisionedProductParameters) (string, error) {
input := svcsdk.DescribeProductInput{
Id: ds.ProductID,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can both ds.ProductID and ds.ProductName be nil?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No

pkg/controller/servicecatalog/provisionedproduct/utils.go Outdated Show resolved Hide resolved
…Status.AtProvider.LastProvisioningParameters
}
func (c *custom) getArtifactID(ds *svcapitypes.ProvisionedProductParameters) (string, error) {
input := svcsdk.DescribeProductInput{
Id: ds.ProductID,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No

pkg/controller/servicecatalog/provisionedproduct/utils.go Outdated Show resolved Hide resolved
pkg/controller/servicecatalog/provisionedproduct/utils.go Outdated Show resolved Hide resolved
return nil
}

func (c *custom) postCreate(_ context.Context, cr *svcapitypes.ProvisionedProduct, obj *svcsdk.ProvisionProductOutput, cre managed.ExternalCreation, err error) (managed.ExternalCreation, error) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This func will be redundant if we remove spec.forProvider.name

return obs, nil
}

func preCreate(_ context.Context, cr *svcapitypes.ProvisionedProduct, obj *svcsdk.ProvisionProductInput) error {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This func will be redundant if we remove spec.forProvider.name

}
meta.SetExternalName(cr, *cr.Spec.ForProvider.Name)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line will be redundant if we remove spec.forProvider.name

@@ -77,6 +77,10 @@ resources:
from:
operation: DescribeProvisionedProduct
path: ProvisionedProductDetail.ProvisioningArtifactId
LastProvisioningParameters:
is_read_only: true
custom_field:
Copy link
Author

@teeverr teeverr Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it's not necessary to expose all params as is, for comparison is enough to know the length of array.
But idk how to generate custom field with type int in the status.

"type: int" works only if "is_read_only" is false

…tus.atProvider.ProvisioningParameters.LastProvisioningParameters(previous ones)
@mleahu
Copy link
Collaborator

mleahu commented Oct 2, 2023

Version v0.0.0-swisscom3.2 at tag beda9b5 was successfully tested in TDE3-2202 .

Please fix the tests and merge this PR.

Thank you!

@mleahu
Copy link
Collaborator

mleahu commented Oct 2, 2023

The new development branch contains the changes from branch "refactor-servicecatalog-provisioned-product-resource"

@mleahu mleahu closed this Oct 2, 2023
teeverr pushed a commit that referenced this pull request Mar 21, 2024
teeverr pushed a commit that referenced this pull request May 31, 2024
teeverr pushed a commit that referenced this pull request Jun 3, 2024
@teeverr teeverr deleted the refactor-servicecatalog-provisioned-product-resource branch October 3, 2024 15:06
teeverr pushed a commit that referenced this pull request Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants