- 
                Notifications
    
You must be signed in to change notification settings  - Fork 60
 
Keep specific homeserver from blueprint #454
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -124,16 +124,16 @@ func (d *Builder) removeImages() error { | |
| d.log("Not cleaning up image with tags: %v", img.RepoTags) | ||
| continue | ||
| } | ||
| bprintName := img.Labels["complement_blueprint"] | ||
| contextStr := img.Labels[complementLabel] | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re-using the   | 
||
| keep := false | ||
| for _, keepBprint := range d.Config.KeepBlueprints { | ||
| if bprintName == keepBprint { | ||
| if contextStr == keepBprint { | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could add in some regex pattern matching here to support keeping all of the homeservers in a blueprint,  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a breaking backwards incompatible change as you're modfiying the behaviour of  Furthermore, you shouldn't be using  I would change this to be  
  | 
||
| keep = true | ||
| break | ||
| } | ||
| } | ||
| if keep { | ||
| d.log("Keeping image created from blueprint %s", bprintName) | ||
| d.log("Keeping image created from blueprint %s", contextStr) | ||
| continue | ||
| } | ||
| _, err = d.Docker.ImageRemove(context.Background(), img.ID, types.ImageRemoveOptions{ | ||
| 
          
            
          
           | 
    @@ -180,17 +180,32 @@ func (d *Builder) ConstructBlueprintIfNotExist(bprint b.Blueprint) error { | |
| if err != nil { | ||
| return fmt.Errorf("ConstructBlueprintIfNotExist(%s): failed to ImageList: %w", bprint.Name, err) | ||
| } | ||
| if len(images) == 0 { | ||
| err = d.ConstructBlueprint(bprint) | ||
| var missingHomeservers []b.Homeserver | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are many ways to tackle this sort of behavior. What's the most idiomatic Complement way to accomplish this? Different argument name? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know what you mean. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This other comment is perfect, #454 (comment) Just looking for a way forward as I know the the quick and dirty way here wasn't good enough to merge.  | 
||
| for _, homeserver := range bprint.Homeservers { | ||
| found := false | ||
| for _, image := range images { | ||
| if image.Labels["complement_hs_name"] == homeserver.Name { | ||
| found = true | ||
| break | ||
| } | ||
| } | ||
| 
     | 
||
| if !found { | ||
| missingHomeservers = append(missingHomeservers, homeserver) | ||
| } | ||
| } | ||
| 
     | 
||
| if len(images) < len(bprint.Homeservers) { | ||
| err = d.ConstructBlueprint(bprint, missingHomeservers) | ||
| if err != nil { | ||
| return fmt.Errorf("ConstructBlueprintIfNotExist(%s): failed to ConstructBlueprint: %w", bprint.Name, err) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
| 
     | 
||
| func (d *Builder) ConstructBlueprint(bprint b.Blueprint) error { | ||
| errs := d.construct(bprint) | ||
| func (d *Builder) ConstructBlueprint(bprint b.Blueprint, homeserversToConstruct []b.Homeserver) error { | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's a bit sad you need to specify the homeservers here in addition to the blueprint. It would be nicer if this built all servers if   | 
||
| errs := d.construct(bprint, homeserversToConstruct) | ||
| if len(errs) > 0 { | ||
| for _, err := range errs { | ||
| d.log("could not construct blueprint: %s", err) | ||
| 
          
            
          
           | 
    @@ -237,7 +252,7 @@ func (d *Builder) ConstructBlueprint(bprint b.Blueprint) error { | |
| } | ||
| 
     | 
||
| // construct all Homeservers sequentially then commits them | ||
| func (d *Builder) construct(bprint b.Blueprint) (errs []error) { | ||
| func (d *Builder) construct(bprint b.Blueprint, homeserversToConstruct []b.Homeserver) (errs []error) { | ||
| d.log("Constructing blueprint '%s'", bprint.Name) | ||
| 
     | 
||
| networkID, err := createNetworkIfNotExists(d.Docker, d.Config.PackageNamespace, bprint.Name) | ||
| 
        
          
        
         | 
    @@ -246,8 +261,8 @@ func (d *Builder) construct(bprint b.Blueprint) (errs []error) { | |
| } | ||
| 
     | 
||
| runner := instruction.NewRunner(bprint.Name, d.Config.BestEffort, d.Config.DebugLoggingEnabled) | ||
| results := make([]result, len(bprint.Homeservers)) | ||
| for i, hs := range bprint.Homeservers { | ||
| results := make([]result, len(homeserversToConstruct)) | ||
| for i, hs := range homeserversToConstruct { | ||
| res := d.constructHomeserver(bprint.Name, runner, hs, networkID) | ||
| if res.err != nil { | ||
| errs = append(errs, res.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.
Keeping this as a TODO to update until we settle on a way to accomplish this.