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

Fix: export_published_chart correctly detects and exports tar file #2052

Merged
merged 4 commits into from
Jul 9, 2024

Conversation

svteb
Copy link
Collaborator

@svteb svteb commented May 23, 2024

Description

Removed file globbing as it caused errors and added a new function that will detect a specific tgz file to be untared. Removed the line: FileUtils.rm_rf(tgz_name) as it did not work previously and now that globbing has been fixed it would cause undesired behavior (honestly I was not able to figure out why it is there at all).

Issues:

Refs: #1947

How has this been tested:

  • Covered by existing integration testing
  • Added integration testing to cover
  • Verified all A/C passes
    • develop
    • master
    • tag/other branch
  • Test environment
    • Shared Packet K8s cluster
    • New Packet K8s cluster
    • Kind cluster
    • Minikube cluster
  • Have not tested

Types of changes:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update

Checklist:

Documentation

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • No updates required.

Code Review

  • Does the test handle fatal exceptions, ie. rescue block

Issue

  • Tasks in issue are checked off

Refs: lfn-cnti#1947
- Fixes the issue where multiple tar files caused the Tar module to fail due to globbing,
by selecting a single tgz file.
- There was a line that was supposed to delete the tgz file (no idea why): FileUtils.rm_rf(tgz_name), which
did not actually work due to the previously mentioned globbing, it was removed because it would
now cause the program to fail.

Signed-off-by: svteb <slavo.valko@tietoevry.com>
Refs: lfn-cnti#1947
- Backtracked on removal of: FileUtils.rm_rf(tgz_name), made it functional
through Dir.glob("#{Helm.chart_name(helm_chart)}-*.tgz").
Through this addition a state where multiple tgz archives are present is not
possible.
- Also added an exception in case a prior helm failure happens and no archive
is pulled (not sure whether this state can be reached).

Signed-off-by: svteb <slavo.valko@tietoevry.com>
@svteb
Copy link
Collaborator Author

svteb commented May 28, 2024

Comments from @martin-mat were correct in pointing out some unhandled cases/lack of information provided. I've come to understand the intentions behind FileUtils.rm_rf(tgz_name) and decided to bring it back:

unless input_file && !input_file.empty?
      files_to_delete = Dir.glob("#{Helm.chart_name(helm_chart)}-*.tgz") ~> addition
      files_to_delete.each do |file|
        FileUtils.rm(file)
        puts "Deleted: #{file}"
      end ~> end of addition

      helm_info = Helm.pull(helm_chart) 
      unless helm_info[:status].success?
        puts "Helm pull error".colorize(:red)
        raise "Helm pull error"
      end
end

It was necessary to do it like this because FileUtils.rm_rf does not work with file globbing which was originally present. This addition also removed the necessity of checking for state where multiple versions of some helm archive were present (as they get deleted and the newest one gets pulled subsequentially).

Another mistake from the previous commit, that was undiscovered, was the necessity of moving this entire block before the block where tgz archive is being discovered, as the Helm.pull(helm_chart) command is what downloads the tgz archive. This also makes the sequence of steps somewhat more logical:

helm_pull -> discover_tgz -> extract_tgz whereas the previous sequence was discover_tgz -> helm_pull -> extract_tgz.

Furthermore I added an exception that prints better information in case no tgz file is discovered.

- Dir.glob functionality for getting tgz files in the working directory abstracted
into a function
- get_tgz_name function made more generic
- outputs made more explicit

Signed-off-by: svteb <slavo.valko@tietoevry.com>
Copy link
Collaborator

@martin-mat martin-mat left a comment

Choose a reason for hiding this comment

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

lgtm, good refactoring!

Copy link
Collaborator

@kosstennbl kosstennbl left a comment

Choose a reason for hiding this comment

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

Other than mentioned problem - looks nice: fixes the Tar problem and refactors the code

@svteb svteb force-pushed the export_published_chart branch 2 times, most recently from cdcf9b1 to 4746e73 Compare July 3, 2024 08:32
Signed-off-by: svteb <slavo.valko@tietoevry.com>
@svteb svteb force-pushed the export_published_chart branch from 4746e73 to c764af9 Compare July 3, 2024 08:34
@martin-mat martin-mat requested a review from kosstennbl July 3, 2024 20:47
Copy link
Collaborator

@kosstennbl kosstennbl left a comment

Choose a reason for hiding this comment

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

lgtm

@martin-mat martin-mat requested a review from collivier July 8, 2024 08:29
@martin-mat martin-mat merged commit c4eb30f into lfn-cnti:main Jul 9, 2024
87 checks passed
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.

4 participants