-
Notifications
You must be signed in to change notification settings - Fork 67
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
FAAS-7483: Support creating OCIR repos in the non-root compartment. #642
Conversation
6506436
to
cbcdc51
Compare
1247e42
to
0918865
Compare
commands/deploy.go
Outdated
func getRepositoryNamePrefix(registry string) (string, error) { | ||
repositoryNamePrefix := "" | ||
parts := strings.Split(registry, "/") | ||
if len(parts) < 3 { | ||
return "", errors.New("registry must have a dockerhub owner or private registry and repo-name") | ||
} | ||
for i := 2; i < len(parts); i++ { | ||
repositoryNamePrefix += parts[i] + "/" | ||
} | ||
return repositoryNamePrefix[:len(repositoryNamePrefix)-1], nil | ||
} |
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.
Is this the same? Could you add some tests too, to be sure, please?
func getRepositoryNamePrefix(registry string) (string, error) { | |
repositoryNamePrefix := "" | |
parts := strings.Split(registry, "/") | |
if len(parts) < 3 { | |
return "", errors.New("registry must have a dockerhub owner or private registry and repo-name") | |
} | |
for i := 2; i < len(parts); i++ { | |
repositoryNamePrefix += parts[i] + "/" | |
} | |
return repositoryNamePrefix[:len(repositoryNamePrefix)-1], nil | |
} | |
func getRepositoryNamePrefix(registry string) (string, error) { | |
parts := strings.Split(registry, "/") | |
if len(parts) < 3 { | |
return "", errors.New("registry must have a dockerhub owner or private registry and repo-name") | |
} | |
return strings.Join(parts[2:], "/"), nil | |
} |
commands/deploy.go
Outdated
artifactsClient.SetRegion(getRegion(oracleProvider)) | ||
|
||
// Create the repository in ImageCompartmentID | ||
repositoryExists, err := createContainerRepositoryInCompartment(repositoryName, oracleProvider.ImageCompartmentID, artifactsClient) |
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.
I wonder if the logic in this area might be more clear if it was switched around slightly?
What do you think about checking for existence of the container first, with doesRepositoryExistInComparment
. If that's true, then you're done. If false, then proceed to create the repository, and if that fails, you know it's a failure that you can't continue with.
That way the response from createContainerRepositoryInCompartment
doesn't have to distinguish between 409s and other responses.
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.
Nice catch. Updating it that way
commands/deploy.go
Outdated
CompartmentId: &compartmentID, | ||
DisplayName: &repositoryName}) | ||
if err != nil { | ||
return false, fmt.Errorf("failed to lookup Container Repository due to %s", err) |
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.
return false, fmt.Errorf("failed to lookup Container Repository due to %s", err) | |
return false, fmt.Errorf("failed to lookup Container Repository due to %w", err) |
6bdc9b4
to
46dde9d
Compare
} | ||
if !repositoryExists { | ||
createContainerRepositoryInCompartment(repositoryName, oracleProvider.ImageCompartmentID, artifactsClient) | ||
if err != nil { |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
commands/deploy.go
Outdated
if oracleProvider != nil && oracleProvider.ImageCompartmentID != "" { | ||
// If the provider is Oracle and ImageCompartmentID is present, we need to deploy image to the ImageCompartmentID. | ||
|
||
// Check Registry and build the repository name. |
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.
nit: most of these small comments aren't doing a lot for me. e.g., here "check registry and build the repository name" just says exactly what the code is doing. Personally I think it would be better (but not required) to write a small comment at the top describing roughly /why/ things are happening the way they are. e.g., "A repository must have a unique name within the tenancy. If one doesn't exist create it in the compartment; if one exists already check to see if it is in the right compartment. If it's not in the right compartment we can't continue".
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.
Here the comments I am leaving are like steps and the code is what the step does. Its much easier to understand what is happening later on when reading than to see a chunk of code and figure out what it does, especially for someone new. I'll add why we do it at the top and space it so it helps in a similar way.
46dde9d
to
8e30bf9
Compare
client/api.go
Outdated
@@ -26,3 +26,7 @@ import ( | |||
func CurrentProvider() (provider.Provider, error) { | |||
return fn_go.DefaultProviders.ProviderFromConfig(viper.GetString(config.ContextProvider), &config.ViperConfigSource{}, &provider.TerminalPassPhraseSource{}) | |||
} | |||
|
|||
func Registry() string { |
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.
I don't think that Registry
should be added to api.go
.
commands/deploy.go
Outdated
if client.Registry() == "" { | ||
return errors.New("registry name must be set, be sure to configure your context file") | ||
} | ||
res, err := getRepositoryNamePrefix(client.Registry()) |
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.
I think that the existing function getRepositoryName
will do what you want here. Additionally it'll support name
containing a different registry
res, err := getRepositoryNamePrefix(client.Registry()) | |
res, err := getRepositoryName(funcfile) |
commands/deploy.go
Outdated
@@ -697,3 +729,36 @@ func findMissingValues(signingDetails common.SigningDetails) string { | |||
} | |||
return strings.Join(missingValues, ",") | |||
} | |||
|
|||
func getRepositoryNamePrefix(registry string) (string, error) { |
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.
I'm not sure that this fn is needed, if you use getRepositoryName
as suggested elsewhere.
commands/deploy.go
Outdated
CompartmentId: &compartmentID, | ||
DisplayName: &repositoryName}) | ||
if err != nil { | ||
return false, fmt.Errorf("failed to lookup Container Repository due to %w", err) |
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.
return false, fmt.Errorf("failed to lookup Container Repository due to %w", err) | |
return false, fmt.Errorf("failed to lookup container repository due to %w", err) |
if err != nil { | ||
return false, fmt.Errorf("failed to lookup Container Repository due to %w", err) | ||
} | ||
if *response.RepositoryCount == 1 { |
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.
I'm not sure about this suggestion, but it seems that if the count is bigger than one it exists.
if *response.RepositoryCount == 1 { | |
if *response.RepositoryCount >= 1 { |
8e30bf9
to
e1e54c6
Compare
Fn context, oracle.image-compartment-id is used to specify the compartment id to which the function image is to be deployed.
If the the repository already exists and oracle.image-compartment-id is specified, the deployment will fail if the repository is not present the same compartment id as the image-compartment-id.
There are no tests added to the code due to the lack of testing around the deploy path, in order to write a test, we would have needed to mock multiple clients and change some fundamental properties in the providers code. Instead, we have performed manual testing:
oracle.image-compartment-Id
set in fn contextoracle.image-compartment-Id
not set (check in the code early on and skips if not set)oracle.image-compartment-Id
to COMPA with a repository/image in COMPB - code will error telling use the repo already exists in another compartment