Skip to content

Commit

Permalink
Attach proxy pod to our podman network
Browse files Browse the repository at this point in the history
  • Loading branch information
aaannz committed Mar 27, 2024
1 parent e296d24 commit 029b3a7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
15 changes: 8 additions & 7 deletions mgrpxy/shared/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ func GenerateSystemdService(httpdImage string, saltBrokerImage string, squidImag
Ports: ports,
HttpProxyFile: httpProxyConfig,
Args: strings.Join(podmanArgs, " "),
Network: podman.UyuniNetwork,
}
if err := generateSystemdFile(dataPod, "pod"); err != nil {
return fmt.Errorf("cannot generated systemd file: %s", err)
return err
}

// Httpd
Expand All @@ -48,7 +49,7 @@ func GenerateSystemdService(httpdImage string, saltBrokerImage string, squidImag
Image: httpdImage,
}
if err := generateSystemdFile(dataHttpd, "httpd"); err != nil {
return fmt.Errorf("cannot generated systemd file: %s", err)
return fmt.Errorf("cannot generate systemd file: %s", err)
}

// Salt broker
Expand All @@ -57,7 +58,7 @@ func GenerateSystemdService(httpdImage string, saltBrokerImage string, squidImag
Image: saltBrokerImage,
}
if err := generateSystemdFile(dataSaltBroker, "salt-broker"); err != nil {
return fmt.Errorf("cannot generated systemd file: %s", err)
return err
}

// Squid
Expand All @@ -67,7 +68,7 @@ func GenerateSystemdService(httpdImage string, saltBrokerImage string, squidImag
Image: squidImage,
}
if err := generateSystemdFile(dataSquid, "squid"); err != nil {
return fmt.Errorf("cannot generated systemd file: %s", err)
return err
}

// SSH
Expand All @@ -76,7 +77,7 @@ func GenerateSystemdService(httpdImage string, saltBrokerImage string, squidImag
Image: sshImage,
}
if err := generateSystemdFile(dataSSH, "ssh"); err != nil {
return fmt.Errorf("cannot generated systemd file: %s", err)
return err
}

// Tftpd
Expand All @@ -86,7 +87,7 @@ func GenerateSystemdService(httpdImage string, saltBrokerImage string, squidImag
Image: tftpdImage,
}
if err := generateSystemdFile(dataTftpd, "tftpd"); err != nil {
return fmt.Errorf("cannot generated systemd file: %s", err)
return err
}

return podman.ReloadDaemon(false)
Expand All @@ -98,7 +99,7 @@ func generateSystemdFile(template utils.Template, service string) error {
const systemdPath = "/etc/systemd/system"
path := path.Join(systemdPath, name)
if err := utils.WriteTemplateToFile(template, path, 0644, true); err != nil {
return fmt.Errorf("failed to generate %s", path)
return fmt.Errorf("failed to generate '%s', error '%s'", path, err)
}
return nil
}
Expand Down
2 changes: 2 additions & 0 deletions mgrpxy/shared/templates/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ ExecStartPre=/bin/rm -f %t/uyuni-proxy-pod.pid %t/uyuni-proxy-pod.pod-id
ExecStartPre=/usr/bin/podman pod create --infra-conmon-pidfile %t/uyuni-proxy-pod.pid \
--pod-id-file %t/uyuni-proxy-pod.pod-id --name uyuni-proxy-pod \
--network {{ .Network }} \
{{- range .Ports }}
-p {{ .Exposed }}:{{ .Port }}{{ if .Protocol }}/{{ .Protocol }}{{ end }} \
{{- end }}
Expand All @@ -52,6 +53,7 @@ type PodTemplateData struct {
Ports []types.PortMap
HttpProxyFile string
Args string
Network string
}

// Render will create the systemd configuration file.
Expand Down
7 changes: 3 additions & 4 deletions shared/utils/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
package utils

import (
"fmt"
"io"
"os"

"github.com/rs/zerolog/log"
)

// Template is an interface for implementing Render function.
Expand All @@ -21,14 +20,14 @@ func WriteTemplateToFile(template Template, path string, perm os.FileMode, overw
// Check if the file is existing
if !overwrite {
if FileExists(path) {
log.Fatal().Msgf("%s file already present, not overwriting", path)
return fmt.Errorf("file '%s' already present, not overwriting", path)
}
}

// Write the configuration
file, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, perm)
if err != nil {
log.Fatal().Err(err).Msgf("Failed to open %s for writing", path)
return fmt.Errorf("failed to open '%s' for writing: %s", path, err)
}
defer file.Close()

Expand Down
1 change: 1 addition & 0 deletions uyuni-tools.changes.oholecek.setup_proxy_pod_correct_net
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Attach proxy pod to our podman network

0 comments on commit 029b3a7

Please sign in to comment.