-
Notifications
You must be signed in to change notification settings - Fork 22
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
Add support for selective plugin migration using plugin groups for air-gapped environments #231
Merged
anujc25
merged 6 commits into
vmware-tanzu:main
from
anujc25:airgap-support-with-groups
Apr 27, 2023
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
10d7c97
Selective plugin migration using plugin groups for airgapped environm…
anujc25 8d71033
Address comments part-1
anujc25 6ef3d60
Always store metadata.digest in cache even if image doesn't exists
anujc25 e63dddf
Address comments part-2
anujc25 53cee08
Address comments part-3
anujc25 bafcefc
Update log message
anujc25 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2023 VMware, Inc. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package airgapped | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
dockerparser "github.com/novln/docker-parser" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// GetPluginInventoryMetadataImage returns the plugin inventory metadata | ||
// image based on plugin inventory image. | ||
// E.g. if plugin inventory image is `fake.repo.com/plugin/plugin-inventory:latest` | ||
// it returns metadata image as `fake.repo.com/plugin/plugin-inventory-metadata:latest` | ||
func GetPluginInventoryMetadataImage(pluginInventoryImage string) (string, error) { | ||
ref, err := dockerparser.Parse(pluginInventoryImage) | ||
if err != nil { | ||
return "", errors.Wrapf(err, "invalid image %q", pluginInventoryImage) | ||
} | ||
return fmt.Sprintf("%s-metadata:%s", ref.Repository(), ref.Tag()), nil | ||
} | ||
|
||
// GetImageRelativePath returns the relative path of the image with respect to `basePath` | ||
// E.g. If the image is `fake.repo.com/plugin/database/plugin-inventory:latest` with | ||
// basePath as `fake.repo.com/plugin` it should return | ||
// `database/plugin-inventory:latest` if withTag is true and | ||
// `database/plugin-inventory` if withTag is false | ||
func GetImageRelativePath(image, basePath string, withTag bool) string { | ||
relativePath := strings.TrimPrefix(image, basePath) | ||
if withTag { | ||
return relativePath | ||
} | ||
if idx := strings.LastIndex(relativePath, ":"); idx != -1 { | ||
return relativePath[:idx] | ||
} | ||
return relativePath | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// Copyright 2023 VMware, Inc. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package airgapped | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/tj/assert" | ||
) | ||
|
||
func Test_GetPluginInventoryMetadataImage(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
tests := []struct { | ||
pluginInventoryImage string | ||
expectedMetadataImage string | ||
errString string | ||
}{ | ||
{ | ||
pluginInventoryImage: "fake.repo.com/plugin/plugin-inventory:latest", | ||
expectedMetadataImage: "fake.repo.com/plugin/plugin-inventory-metadata:latest", | ||
errString: "", | ||
}, | ||
{ | ||
pluginInventoryImage: "fake.repo.com/plugin/airgapped:v1.0.0", | ||
expectedMetadataImage: "fake.repo.com/plugin/airgapped-metadata:v1.0.0", | ||
errString: "", | ||
}, | ||
{ | ||
pluginInventoryImage: "fake.repo.com/plugin/metadata", | ||
expectedMetadataImage: "fake.repo.com/plugin/metadata-metadata:latest", | ||
errString: "", | ||
}, | ||
{ | ||
pluginInventoryImage: "invalid-inventory-image$#", | ||
expectedMetadataImage: "", | ||
errString: "invalid image", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.pluginInventoryImage, func(t *testing.T) { | ||
actualMetadataImage, err := GetPluginInventoryMetadataImage(test.pluginInventoryImage) | ||
assert.Equal(actualMetadataImage, test.expectedMetadataImage) | ||
if test.errString == "" { | ||
assert.Nil(err) | ||
} else { | ||
assert.Contains(err.Error(), test.errString) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_GetImageRelativePath(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
tests := []struct { | ||
image string | ||
basePath string | ||
withTag bool | ||
expectedRelativePath string | ||
}{ | ||
{ | ||
image: "fake.repo.com/plugin/plugin-inventory:latest", | ||
basePath: "fake.repo.com/plugin/", | ||
withTag: true, | ||
expectedRelativePath: "plugin-inventory:latest", | ||
}, | ||
{ | ||
image: "fake.repo.com/plugin/plugin-inventory:latest", | ||
basePath: "fake.repo.com/plugin/", | ||
withTag: false, | ||
expectedRelativePath: "plugin-inventory", | ||
}, | ||
{ | ||
image: "fake.repo.com/plugin/airgapped:v1.0.0", | ||
basePath: "fake.repo.com/", | ||
withTag: true, | ||
expectedRelativePath: "plugin/airgapped:v1.0.0", | ||
}, | ||
{ | ||
image: "fake.repo.com/plugin/metadata", | ||
basePath: "fake.repo.com/", | ||
withTag: false, | ||
expectedRelativePath: "plugin/metadata", | ||
}, | ||
{ | ||
image: "fake.repo.com/plugin/metadata:latest", | ||
basePath: "fake.repo.com/plugin/metadata-metadata", | ||
withTag: true, | ||
expectedRelativePath: "fake.repo.com/plugin/metadata:latest", | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.image, func(t *testing.T) { | ||
actualImage := GetImageRelativePath(test.image, test.basePath, test.withTag) | ||
assert.Equal(actualImage, test.expectedRelativePath) | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if
withTag == true
but theimage
does not have a tag? Should we append:latest
?I don't know if this could even happen but I thought about it because the function above does add
:latest
if the tag is not specified.