Skip to content

🐙 octavia-cli: apply connections #10881

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

Merged
merged 7 commits into from
Mar 9, 2022

Conversation

alafanechere
Copy link
Contributor

@alafanechere alafanechere commented Mar 5, 2022

What

We want to be able to apply YAML configuration for connections.

How

Create Connection resource inheriting from BaseResource.
The factory will do its magic, no edit should be required in command.py

@alafanechere alafanechere temporarily deployed to more-secrets March 5, 2022 22:43 Inactive
@alafanechere alafanechere temporarily deployed to more-secrets March 5, 2022 22:43 Inactive
@alafanechere alafanechere marked this pull request as ready for review March 5, 2022 22:45
@alafanechere alafanechere requested a review from marcosmarxm March 5, 2022 22:45
@alafanechere alafanechere temporarily deployed to more-secrets March 5, 2022 22:51 Inactive
@alafanechere alafanechere temporarily deployed to more-secrets March 5, 2022 22:51 Inactive
@alafanechere alafanechere added this to the octavia-cli-alpha milestone Mar 5, 2022
Comment on lines 435 to 437
self.source_id,
self.destination_id,
self.status,
Copy link
Member

Choose a reason for hiding this comment

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

minor but add all param names when call the function

namespace_format=self.namespace_format,
prefix=self.prefix,
operations_ids=self.operation_ids,
sync_catalog=self.sync_catalog,
Copy link
Member

Choose a reason for hiding this comment

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

Are you waiting to receive the sync catalog or is it possible to send a dict?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure yet, I'd like to test with a generated config to check if the API client is flexible enough.

Copy link
Member

@marcosmarxm marcosmarxm left a comment

Choose a reason for hiding this comment

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

Overall LGTM if works with the simple call to the API is done, if not need to review again.

@@ -414,13 +494,15 @@ def factory(api_client: airbyte_api_client.ApiClient, workspace_id: str, configu
NotImplementedError: Raised if the definition type found in the YAML is not a supported resource.

Returns:
Union[Source, Destination]: The resource object created from the YAML config.
Union[Source, Destination, Connection]: The resource object created from the YAML config.
"""
with open(configuration_path, "r") as f:
local_configuration = yaml.load(f, yaml.FullLoader)
if local_configuration["definition_type"] == "source":
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if local_configuration["definition_type"] == "source":
if local_configuration["definition_type"] == DEFINITION_TYPE.source:

wdyt creating a enum class for definitions? I think there is other places to be used.
only small suggestion though

Copy link
Contributor Author

@alafanechere alafanechere Mar 8, 2022

Choose a reason for hiding this comment

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

This is a future improvement we could make for this file but also in octavia_cli/generate/definitions.py

@alafanechere alafanechere temporarily deployed to more-secrets March 8, 2022 19:01 Inactive
@alafanechere alafanechere temporarily deployed to more-secrets March 8, 2022 19:01 Inactive
@alafanechere alafanechere requested a review from marcosmarxm March 9, 2022 07:33
Comment on lines 208 to 218
def _get_comparable_configuration(
self,
): # pragma: no cover
if not self.was_created:
raise NonExistingResourceError("Can't find a comparable configuration as the remote resource does not exists.")
else:
return copy.deepcopy(self.remote_resource)

@property
def was_created(self):
return True if self.remote_resource else False
Copy link
Member

Choose a reason for hiding this comment

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

I saw other places where the self.was_created is invoked and throw errors. What do you think doing this directly in the was_created function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean raising the error in was_created? I'd like to use was_created as a boolean to know if the resource was created or not, I don't want it to throw an error if the resource was not created but simply return false. But maybe you meant running copy.deepcopy(self.remote_resource) in was_created? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

No, only the error handling in the was_created because is also invoked in connection generation command too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could maybe implement something like self.remote_resource.raise_if_not_created() ?

@alafanechere alafanechere temporarily deployed to more-secrets March 9, 2022 13:13 Inactive
Comment on lines 117 to 118
CHECK_RETURN_TYPE = True
APPLY_PRIORITY = 0
Copy link
Member

Choose a reason for hiding this comment

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

Could you add comments about what those two variables are used for?

Comment on lines +372 to +379
def _get_comparable_configuration(self):
"""Get the object to which local configuration will be compared to.

Returns:
dict: Remote source configuration.
"""
comparable_configuration = super()._get_comparable_configuration()
return comparable_configuration.connection_configuration
Copy link
Member

Choose a reason for hiding this comment

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

This can't be done in BaseResource and only be overwritten by Connection object?

Copy link
Contributor Author

@alafanechere alafanechere Mar 9, 2022

Choose a reason for hiding this comment

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

I duplicated this on purpose as this is really specific to source and destination and not something common to the other potential resources. I was thinking of adding a parent class for Source and Destination (SourceOrDestination(BaseResource) 🤔 ) but thought it was too much for this PR.

prefix=self.configuration["prefix"],
schedule=self.configuration["schedule"],
resource_requirements=self.configuration["resourceRequirements"],
_check_type=False,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
_check_type=False,
_check_type=self.CHECK_RETURN_TYPE,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

_check_type=False:We disable the validation of type at model instanciation.
_check_return_type=False:We disable the validation of type of the API response.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made a bit of refacto to make it a bit more readable: 6ec2dd4

"""
comparable_configuration = super()._get_comparable_configuration()
comparable_configuration.pop("connectionId")
comparable_configuration.pop("operationIds")
Copy link
Member

Choose a reason for hiding this comment

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

Today octavia-cli can't work with normalization right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Exactly, I remove the operationIds in case the user change the transformation in the UI, so we exclude operationIds from the diff computation.

@alafanechere alafanechere temporarily deployed to more-secrets March 9, 2022 14:10 Inactive
@alafanechere alafanechere temporarily deployed to more-secrets March 9, 2022 14:10 Inactive
@alafanechere alafanechere temporarily deployed to more-secrets March 9, 2022 14:14 Inactive
@alafanechere alafanechere temporarily deployed to more-secrets March 9, 2022 14:14 Inactive
@alafanechere alafanechere merged commit 56bf982 into master Mar 9, 2022
@alafanechere alafanechere deleted the augustin/octavia-cli/apply-connection branch March 9, 2022 16:08
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