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

Don't add .service extension if already there #3929

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions nodeup/pkg/model/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (h *HookBuilder) Build(c *fi.ModelBuilderContext) error {
case "":
name = fmt.Sprintf("kops-hook-%d", j)
if isInstanceGroup {
name = fmt.Sprintf("%s-ig", name)
name += "-ig"
}
default:
name = hook.Name
Expand All @@ -72,7 +72,7 @@ func (h *HookBuilder) Build(c *fi.ModelBuilderContext) error {
enabled := false
managed := true
c.AddTask(&nodetasks.Service{
Name: hook.Name,
Name: ensureSystemdSuffix(name),
ManageState: &managed,
Enabled: &enabled,
Running: &enabled,
Expand All @@ -94,6 +94,14 @@ func (h *HookBuilder) Build(c *fi.ModelBuilderContext) error {
return nil
}

// ensureSystemdSuffix makes sure that we have a .service suffix on the name, needed on needed versions of systems
func ensureSystemdSuffix(name string) string {
if !strings.HasSuffix(name, ".service") && !strings.HasSuffix(name, ".timer") {
name += ".service"
}
return name
}

// buildSystemdService is responsible for generating the service
func (h *HookBuilder) buildSystemdService(name string, hook *kops.HookSpec) (*nodetasks.Service, error) {
// perform some basic validation
Expand Down Expand Up @@ -130,7 +138,7 @@ func (h *HookBuilder) buildSystemdService(name string, hook *kops.HookSpec) (*no
}

service := &nodetasks.Service{
Name: name,
Name: ensureSystemdSuffix(name),
Definition: s(unit.Render()),
}

Expand Down