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

Installing/updating configuration files via the containers update agent. #232

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

saurav-madhusoodanan
Copy link

@saurav-madhusoodanan saurav-madhusoodanan commented Apr 25, 2024

[#233] Installing/updating configuration files via the containers update agent.

Copy link
Member

@k-gostev k-gostev left a 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)
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
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)
Copy link
Member

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

@k-gostev k-gostev changed the title Configuration File Installing/updating configuration files via the containers update agent. Apr 30, 2024
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.
Copy link
Member

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.
Copy link
Member

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)
Copy link
Member

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.

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.

Installing/updating configuration files via the containers update agent.
2 participants