Skip to content

Commit

Permalink
add tuning param to systmemd configuration file and k3s configmap
Browse files Browse the repository at this point in the history
  • Loading branch information
mbussolotto committed May 22, 2024
1 parent ffd8ab0 commit 0803f57
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 101 deletions.
6 changes: 3 additions & 3 deletions mgradm/cmd/migrate/kubernetes/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ func migrateToKubernetes(
}

// After each command we want to scale to 0
err = shared_kubernetes.ReplicasTo(shared_kubernetes.ServerFilter, 0)
err = shared_kubernetes.ReplicasTo(shared_kubernetes.ServerApp, 0)
if err != nil {
return utils.Errorf(err, L("cannot set replicas to 0"))
}

defer func() {
// if something is running, we don't need to set replicas to 1
if _, err = shared_kubernetes.GetNode("uyuni"); err != nil {
err = shared_kubernetes.ReplicasTo(shared_kubernetes.ServerFilter, 1)
err = shared_kubernetes.ReplicasTo(shared_kubernetes.ServerApp, 1)
}
}()

Expand Down Expand Up @@ -134,7 +134,7 @@ func migrateToKubernetes(
return utils.Errorf(err, L("cannot wait for deployment of %s"), serverImage)
}

err = shared_kubernetes.ReplicasTo(shared_kubernetes.ServerFilter, 0)
err = shared_kubernetes.ReplicasTo(shared_kubernetes.ServerApp, 0)
if err != nil {
return utils.Errorf(err, L("cannot set replicas to 0"))
}
Expand Down
4 changes: 2 additions & 2 deletions mgradm/shared/kubernetes/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ func Upgrade(
return utils.Errorf(err, L("cannot find node running uyuni"))
}

err = kubernetes.ReplicasTo(kubernetes.ServerFilter, 0)
err = kubernetes.ReplicasTo(kubernetes.ServerApp, 0)
if err != nil {
return utils.Errorf(err, L("cannot set replica to 0"))
}

defer func() {
// if something is running, we don't need to set replicas to 1
if _, err = kubernetes.GetNode("uyuni"); err != nil {
err = kubernetes.ReplicasTo(kubernetes.ServerFilter, 1)
err = kubernetes.ReplicasTo(kubernetes.ServerApp, 1)
}
}()
if inspectedValues["image_pg_version"] > inspectedValues["current_pg_version"] {
Expand Down
4 changes: 2 additions & 2 deletions mgradm/shared/templates/attestationServiceTemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Environment=PODMAN_SYSTEMD_UNIT=%n
Restart=on-failure
ExecStartPre=/bin/rm -f %t/uyuni-server-attestation-%i.pid %t/%n.ctr-id
ExecStartPre=/usr/bin/podman rm --ignore --force -t 10 {{ .NamePrefix }}-server-attestation-%i
ExecStart=/usr/bin/podman run \
ExecStart=/bin/sh -c '/usr/bin/podman run \
--conmon-pidfile %t/uyuni-server-attestation-%i.pid \
--cidfile=%t/%n-%i.ctr-id \
--cgroups=no-conmon \
Expand All @@ -34,7 +34,7 @@ ExecStart=/usr/bin/podman run \
--name {{ .NamePrefix }}-server-attestation-%i \
--hostname {{ .NamePrefix }}-server-attestation-%i.mgr.internal \
--network {{ .Network }} \
${UYUNI_IMAGE}
${UYUNI_IMAGE}'
ExecStop=/usr/bin/podman stop --ignore -t 10 --cidfile=%t/%n-%i.ctr-id
ExecStopPost=/usr/bin/podman rm -f --ignore -t 10 --cidfile=%t/%n-%i.ctr-id
PIDFile=%t/uyuni-server-attestation-%i.pid
Expand Down
2 changes: 1 addition & 1 deletion mgrpxy/cmd/start/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ func kubernetesStart(
cmd *cobra.Command,
args []string,
) error {
return kubernetes.Start(kubernetes.ProxyFilter)
return kubernetes.Start(kubernetes.ProxyApp)
}
2 changes: 1 addition & 1 deletion mgrpxy/cmd/stop/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ func kubernetesStop(
cmd *cobra.Command,
args []string,
) error {
return kubernetes.Stop(kubernetes.ProxyFilter)
return kubernetes.Stop(kubernetes.ProxyApp)
}
2 changes: 1 addition & 1 deletion mgrpxy/cmd/support/ptf/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ NOTE: installing on a remote cluster is not supported yet!
},
}

pxy_utils.AddImageUpgradeFlags(kubernetesCmd)
pxy_utils.AddImageFlags(kubernetesCmd)

kubernetes.AddHelmFlags(kubernetesCmd)

Expand Down
20 changes: 18 additions & 2 deletions mgrpxy/shared/kubernetes/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ func Deploy(imageFlags *utils.ProxyImageFlags, helmFlags *HelmFlags, configDir s
}
helmParams = append(helmParams, "-f", path.Join(configDir, "config.yaml"))

if len(imageFlags.Tuning.Httpd) > 0 {
absPath, err := filepath.Abs(imageFlags.Tuning.Httpd)
if err != nil {
return err
}
helmParams = append(helmParams, "--set-file", "apache_tuning="+absPath)
}

if len(imageFlags.Tuning.Squid) > 0 {
absPath, err := filepath.Abs(imageFlags.Tuning.Squid)
if err != nil {
return err
}
helmParams = append(helmParams, "--set-file", "squid_tuning="+absPath)
}

helmParams = append(helmParams,
"--set", "images.proxy-httpd="+imageFlags.GetContainerImage("httpd"),
"--set", "images.proxy-salt-broker="+imageFlags.GetContainerImage("salt-broker"),
Expand Down Expand Up @@ -150,15 +166,15 @@ func Upgrade(flags *KubernetesProxyUpgradeFlags, cmd *cobra.Command, args []stri
return err
}

err = kubernetes.ReplicasTo(kubernetes.ProxyFilter, 0)
err = kubernetes.ReplicasTo(kubernetes.ProxyApp, 0)
if err != nil {
return err
}

defer func() {
// if something is running, we don't need to set replicas to 1
if _, err = kubernetes.GetNode("uyuni"); err != nil {
err = kubernetes.ReplicasTo(kubernetes.ProxyFilter, 1)
err = kubernetes.ReplicasTo(kubernetes.ProxyApp, 1)
}
}()

Expand Down
118 changes: 52 additions & 66 deletions mgrpxy/shared/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,89 +49,75 @@ func GenerateSystemdService(httpdImage string, saltBrokerImage string, squidImag
HttpProxyFile: httpProxyConfig,
Network: podman.UyuniNetwork,
}
podEnv := fmt.Sprintf(`Environment="PODMAN_EXTRA_ARGS=%s"`, strings.Join(podmanArgs, " "))
podEnv := fmt.Sprintf(`Environment="PODMAN_EXTRA_ARGS=%s"`, strings.Join(flags.Podman.Args, " "))
if err := generateSystemdFile(dataPod, "pod", "", podEnv); err != nil {
return err
}

httpdVolumes := shared_utils.PROXY_HTTPD_VOLUMES
if flags.ProxyImageFlags.TuningHttpd != "" {
absPath, err := filepath.Abs(flags.ProxyImageFlags.TuningHttpd)
if err != nil {
return err
// Httpd
{
dataHttpd := templates.HttpdTemplateData{
Volumes: shared_utils.PROXY_HTTPD_VOLUMES,
HttpProxyFile: httpProxyConfig,
}
if !shared_utils.FileExists(absPath) {
return fmt.Errorf(L("%s does not exists"), absPath)
additionHttpdTuningSettings := ""
if flags.ProxyImageFlags.Tuning.Httpd != "" {
absPath, err := filepath.Abs(flags.ProxyImageFlags.Tuning.Httpd)
if err != nil {
return err
}
additionHttpdTuningSettings = fmt.Sprintf(`Environment=HTTPD_ADDITIONAL_SETTINGS=-v%s:/etc/apache2/conf.d/apache_tuning.conf:ro`, absPath)
}
httpdVolumes = append(httpdVolumes,
types.VolumeMount{MountPath: "/etc/apache2/conf.d/apache_tuning.conf", Name: absPath})
}
// Httpd
dataHttpd := templates.HttpdTemplateData{
Volumes: httpdVolumes,
HttpProxyFile: httpProxyConfig,
}
if err := generateSystemdFile(dataHttpd, "httpd", httpdImage, ""); err != nil {
return err
}
if flags.ProxyImageFlags.TuningHttpd != "" {
absPath, err := filepath.Abs(flags.ProxyImageFlags.TuningHttpd)
if err != nil {
if err := generateSystemdFile(dataHttpd, "httpd", httpdImage, additionHttpdTuningSettings); err != nil {
return err
}
additionPodmanSettings := fmt.Sprintf(`Environment=HTTPD_ADDITIONAL_SETTINGS=-v%s:/etc/apache2/conf.d/apache_tuning.conf:ro`, absPath)
if err := podman.GenerateSystemdConfFile("uyuni-proxy-httpd", "Service", additionPodmanSettings); err != nil {
return shared_utils.Errorf(err, L("cannot generate systemd conf file"))
}
}

// Salt broker
dataSaltBroker := templates.SaltBrokerTemplateData{
HttpProxyFile: httpProxyConfig,
}
if err := generateSystemdFile(dataSaltBroker, "salt-broker", saltBrokerImage, ""); err != nil {
return err
}

squidVolumes := shared_utils.PROXY_SQUID_VOLUMES

if flags.ProxyImageFlags.TuningSquid != "" {
absPath, err := filepath.Abs(flags.ProxyImageFlags.TuningSquid)
if err != nil {
return err
{
dataSaltBroker := templates.SaltBrokerTemplateData{
HttpProxyFile: httpProxyConfig,
}
additionPodmanSettings := fmt.Sprintf(`Environment=SQUID_ADDITIONAL_SETTINGS=-v%s:/etc/squid/conf.d/squid_tuning.conf:ro`, absPath)
if err := podman.GenerateSystemdConfFile("uyuni-proxy-squid", "Service", additionPodmanSettings); err != nil {
return shared_utils.Errorf(err, L("cannot generate systemd conf file"))
if err := generateSystemdFile(dataSaltBroker, "salt-broker", saltBrokerImage, ""); err != nil {
return err
}
}

// Squid
dataSquid := templates.SquidTemplateData{
Volumes: squidVolumes,
HttpProxyFile: httpProxyConfig,
}
if err := generateSystemdFile(dataSquid, "squid", squidImage, ""); err != nil {
return err
{
dataSquid := templates.SquidTemplateData{
Volumes: shared_utils.PROXY_SQUID_VOLUMES,
HttpProxyFile: httpProxyConfig,
}
additionSquidTuningSettings := ""
if flags.ProxyImageFlags.Tuning.Squid != "" {
absPath, err := filepath.Abs(flags.ProxyImageFlags.Tuning.Squid)
if err != nil {
return err
}
additionSquidTuningSettings = fmt.Sprintf(`Environment=SQUID_ADDITIONAL_SETTINGS=-v%s:/etc/squid/conf.d/squid_tuning.conf:ro`, absPath)
}
if err := generateSystemdFile(dataSquid, "squid", squidImage, additionSquidTuningSettings); err != nil {
return err
}
}

// SSH
dataSSH := templates.SSHTemplateData{
HttpProxyFile: httpProxyConfig,
}
if err := generateSystemdFile(dataSSH, "ssh", sshImage, ""); err != nil {
return err
{
dataSSH := templates.SSHTemplateData{
HttpProxyFile: httpProxyConfig,
}
if err := generateSystemdFile(dataSSH, "ssh", sshImage, ""); err != nil {
return err
}
}

// Tftpd
dataTftpd := templates.TFTPDTemplateData{
Volumes: shared_utils.PROXY_TFTPD_VOLUMES,
HttpProxyFile: httpProxyConfig,
}
if err := generateSystemdFile(dataTftpd, "tftpd", tftpdImage, ""); err != nil {
return err
{
dataTftpd := templates.TFTPDTemplateData{
Volumes: shared_utils.PROXY_TFTPD_VOLUMES,
HttpProxyFile: httpProxyConfig,
}
if err := generateSystemdFile(dataTftpd, "tftpd", tftpdImage, ""); err != nil {
return err
}
}

return podman.ReloadDaemon(false)
}

Expand Down Expand Up @@ -167,7 +153,7 @@ func getHttpProxyConfig() string {
// GetContainerImage returns a proxy image URL.
func GetContainerImage(flags *utils.ProxyImageFlags, name string) (string, error) {
image := flags.GetContainerImage(name)
inspectedHostValues, err := shared_utils.InspectHost(true)
inspectedHostValues, err := shared_utils.InspectHost(false)
if err != nil {
return "", shared_utils.Errorf(err, L("cannot inspect host values"))
}
Expand Down Expand Up @@ -238,7 +224,7 @@ func Upgrade(globalFlags *types.GlobalFlags, flags *PodmanProxyFlags, cmd *cobra

func getContainerImage(flags *utils.ProxyImageFlags, name string) (string, error) {
image := flags.GetContainerImage(name)
inspectedHostValues, err := shared_utils.InspectHost(true)
inspectedHostValues, err := shared_utils.InspectHost(false)
if err != nil {
return "", shared_utils.Errorf(err, L("cannot inspect host values"))
}
Expand Down
2 changes: 1 addition & 1 deletion mgrpxy/shared/templates/httpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ExecStart=/bin/sh -c '/usr/bin/podman run \
{{- range .Volumes }}
-v {{ .Name }}:{{ .MountPath }} \
{{- end }}
--name uyuni-proxy-httpd \
${HTTPD_ADDITIONAL_SETTINGS} --name uyuni-proxy-httpd \
${UYUNI_IMAGE}'
ExecStop=/usr/bin/podman stop --ignore --cidfile %t/uyuni-proxy-httpd.ctr-id -t 10
Expand Down
2 changes: 1 addition & 1 deletion mgrpxy/shared/templates/squid.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ ExecStart=/bin/sh -c '/usr/bin/podman run \
{{- range .Volumes }}
-v {{ .Name }}:{{ .MountPath }} \
{{- end }}
--name uyuni-proxy-squid \
${SQUID_ADDITIONAL_SETTINGS} --name uyuni-proxy-squid \
${UYUNI_IMAGE}'
ExecStop=/usr/bin/podman stop --ignore --cidfile %t/uyuni-proxy-squid.ctr-id -t 10
Expand Down
13 changes: 9 additions & 4 deletions mgrpxy/shared/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ type ProxyImageFlags struct {
Squid types.ImageFlags `mapstructure:"squid"`
Ssh types.ImageFlags `mapstructure:"ssh"`
Tftpd types.ImageFlags `mapstructure:"tftpd"`
TuningHttpd string `mapstructure:"tuningHttpd"`
TuningSquid string `mapstructure:"tuningSquid"`
Tuning Tuning `mapstructure:"tuning"`
}

// Tuning are the custom configuration file provide by users.
type Tuning struct {
Httpd string `mapstructure:"httpd"`
Squid string `mapstructure:"squid"`
}

// Get the full container image name and tag for a container name.
Expand Down Expand Up @@ -79,8 +84,8 @@ func AddImageFlags(cmd *cobra.Command) {
addContainerImageFlags(cmd, "ssh")
addContainerImageFlags(cmd, "tftpd")

cmd.Flags().String("tuningHttpd", "", L("HTTPD tuning configuration file"))
cmd.Flags().String("tuningSquid", "", L("Squid tuning configuration file"))
cmd.Flags().String("tuning-httpd", "", L("HTTPD tuning configuration file"))
cmd.Flags().String("tuning-squid", "", L("Squid tuning configuration file"))
}

func addContainerImageFlags(cmd *cobra.Command, container string) {
Expand Down
18 changes: 9 additions & 9 deletions shared/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,26 @@ func guessIngress() (string, error) {
}

// Restart restarts the pod.
func Restart(filter string) error {
if err := Stop(filter); err != nil {
return utils.Errorf(err, L("cannot stop %s"), filter)
func Restart(app string) error {
if err := Stop(app); err != nil {
return utils.Errorf(err, L("cannot stop %s"), app)
}
return Start(filter)
return Start(app)
}

// Start starts the pod.
func Start(filter string) error {
func Start(app string) error {
// if something is running, we don't need to set replicas to 1
if _, err := GetNode(filter); err != nil {
return ReplicasTo(filter, 1)
if _, err := GetNode(app); err != nil {
return ReplicasTo(app, 1)
}
log.Debug().Msgf("Already running")
return nil
}

// Stop stop the pod.
func Stop(filter string) error {
return ReplicasTo(filter, 0)
func Stop(app string) error {
return ReplicasTo(app, 0)
}

func get(component string, componentName string, args ...string) ([]byte, error) {
Expand Down
Loading

0 comments on commit 0803f57

Please sign in to comment.