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

Fix for systemd instantiated services when enabled via ignition #934

Merged
merged 1 commit into from
Mar 20, 2020

Conversation

sohankunkerkar
Copy link
Member

Fixes #586

@coreosbot
Copy link
Contributor

Can one of the admins verify this patch?

internal/exec/util/unit.go Outdated Show resolved Hide resolved
@dustymabe
Copy link
Member

Since we need to combine all instantiated units of a given service into one line (i.e. enable [email protected] bar0 bar1 bar2) would it make sense to just collect what units we want to enable in createUnits() from units.go and then aggregate the information before writing out the file?

@sohankunkerkar sohankunkerkar force-pushed the systemd-preset branch 2 times, most recently from 388f6a1 to d5c274b Compare March 12, 2020 17:42
@sohankunkerkar sohankunkerkar changed the title [WIP] Fix for systemd instatiated services when enabled via ignition [WIP] Fix for systemd instantiated services when enabled via ignition Mar 12, 2020
Copy link
Contributor

@arithx arithx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, overarching question: why use strings.Builder over a list of strings? It seems like you're treating them at as space-delimited lists anyways.

internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
@jamescassell
Copy link

Seems like it would be a heck of a lot easier to update systemd to accept the [email protected] syntax, rather than the strange syntax it actually requires... but I guess if this lands fastest, I can't complain about "it's done"

Thanks for working on this!

@sohankunkerkar sohankunkerkar force-pushed the systemd-preset branch 4 times, most recently from 8c7f536 to d0c5135 Compare March 13, 2020 20:04
@sohankunkerkar sohankunkerkar changed the title [WIP] Fix for systemd instantiated services when enabled via ignition Fix for systemd instantiated services when enabled via ignition Mar 13, 2020
Copy link
Member

@dustymabe dustymabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments inline in the code. In general I think we can collapse a lot of logic if we structure our data differently. We could build up a presets map using a new Preset type and hold all the information we need I think. Something like the following map/Type:

package main
import "fmt"

type Preset struct {
    unit string
    enabled bool
    instantiateable bool
    instances []string
}
func main() {
    presets := make(map[string]*Preset)
    presets["sshd.service"] = &Preset{"sshd.service", true, false, []string{}}
    presets["chronyd.service"] = &Preset{"chronyd.service", false, false, []string{}}
    presets["[email protected]"] = &Preset{"[email protected]", true, true, []string{"foo"}}
    presets["[email protected]"].instances = append(presets["[email protected]"].instances, "bar")
    for _, value := range presets {
        fmt.Println()
        fmt.Println("unit:", value.unit)
        fmt.Println("enabled:", value.enabled)
        fmt.Println("instantiateable:", value.instantiateable)
        if value.instantiateable {
            fmt.Println("instances:", value.instances)
        }
    }
}

internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
Copy link
Member

@dustymabe dustymabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work.. Some new comments

internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
internal/exec/util/unit.go Outdated Show resolved Hide resolved
@sohankunkerkar sohankunkerkar force-pushed the systemd-preset branch 3 times, most recently from 965dd1e to 5e1ccd2 Compare March 16, 2020 19:20
Copy link
Member

@dustymabe dustymabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new comments

internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
@sohankunkerkar sohankunkerkar force-pushed the systemd-preset branch 4 times, most recently from 9fef655 to d064bdf Compare March 18, 2020 20:27
Copy link
Contributor

@bgilbert bgilbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks pretty good. Just some nits.

In your commit message:

Code to fix the systemd instatiated services when enabled/disabled via ignition

Code to is obvious, as is via ignition. What about Fix enabling systemd instantiated services, with a link to the original issue?

internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
config/shared/errors/errors.go Outdated Show resolved Hide resolved
internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
internal/exec/stages/files/units.go Show resolved Hide resolved
internal/exec/stages/files/units.go Show resolved Hide resolved
internal/exec/stages/files/units.go Outdated Show resolved Hide resolved
internal/exec/stages/files/units_test.go Show resolved Hide resolved
internal/exec/stages/files/units_test.go Outdated Show resolved Hide resolved
@sohankunkerkar sohankunkerkar force-pushed the systemd-preset branch 6 times, most recently from 29493ff to cb3f64f Compare March 19, 2020 13:57
@sohankunkerkar sohankunkerkar force-pushed the systemd-preset branch 2 times, most recently from 26f83c1 to 9c5eaf6 Compare March 19, 2020 17:21
internal/systemd/systemd.go Outdated Show resolved Hide resolved
internal/exec/stages/files/units_test.go Show resolved Hide resolved
Copy link
Member

@dustymabe dustymabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Code LGTM - Nice work @sohankunkerkar

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.

systemd instantiated services are not started when enabled via ignition
8 participants