-
Notifications
You must be signed in to change notification settings - Fork 9
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
Installing/updating configuration files via the containers update agent. #232
base: main
Are you sure you want to change the base?
Installing/updating configuration files via the containers update agent. #232
Conversation
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 also have some implementation suggestions that I will address later.
if len(mount) < 2 || len(mount) > 3 { | ||
return nil, log.NewErrorf("Incorrect number of parameters of the mount point %s", mp) | ||
if len(mount) < 2 || len(mount) > 4 { | ||
return nil, []byte(""), log.NewErrorf("Incorrect number of parameters of the mount point %s", mp) |
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 nil, []byte(""), log.NewErrorf("Incorrect number of parameters of the mount point %s", mp) | |
return nil, nil, log.NewErrorf("incorrect number of parameters of the mount point %s", mp) |
Errors should not start with a capital letter. Ref: https://go.dev/wiki/CodeReviewComments#error-strings
mountPoint.PropagationMode = types.RPrivatePropagationMode | ||
configInfo, err = base64.StdEncoding.DecodeString(mount[2]) | ||
if err != nil { | ||
log.Fatal("error:", 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.
log.Fatal
should not be used as in the end it calls logger.exit(1)
that will kill the service
err :=os.WriteFile(mountPoint.Source+"/"+component.ID+"_config.json", configInfo, 0755) | ||
if err != nil { | ||
log.WarnErr(err, "Error writing to file.") | ||
//add case where file is not written properly. |
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.
If the file was not written to the file system the update should be rolled back and stopped and failed feedback sent to the end user.
@@ -83,25 +84,42 @@ func ParseMountPoints(mps []string) ([]types.MountPoint, error) { | |||
} | |||
|
|||
// ParseMountPoint converts a single string representation of a container's mount to a structured MountPoint instance. | |||
// Format: source:destination[:propagation_mode]. | |||
// Format: source:destination[:propagation_mode]:encoded_config_file_information. |
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.
This format is difficult to read. IMO it should be changed to a structure, something like:
var mountPoint struct {
source string `json:"string,omitempty"`
destination string `json:"destination,omitempty"`
propagationMode string `json:"propagationMode,omitempty"`
data string `json:"data,omitempty"`
}
mountPoint, err := util.ParseMountPoint(keyValuePair.Value) | ||
mountPoint, configInfo, err := util.ParseMountPoint(keyValuePair.Value) | ||
if len(configInfo) != 0 { | ||
err :=os.WriteFile(mountPoint.Source+"/"+component.ID+"_config.json", configInfo, 0755) |
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.
If you write the file that way you risk to overwrite an existing configuration that is being used by the running container. You need to see what would be the impact of that and figure out a way to mitigate.
[#233] Installing/updating configuration files via the containers update agent.