Skip to content

Commit

Permalink
Merge pull request #334 from feichashao/mount_dir
Browse files Browse the repository at this point in the history
Console use tmp dir for monitor plugin conf
  • Loading branch information
openshift-merge-bot[bot] authored May 28, 2024
2 parents 3ebbc7a + 7842f5f commit c21ada9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
33 changes: 17 additions & 16 deletions cmd/ocm-backplane/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ type containerEngineInterface interface {
containerIsExist(containerName string) (bool, error)
}

type podmanLinux struct{}
type podmanLinux struct {
fileMountDir string
}
type podmanMac struct{}
type dockerLinux struct{}
type dockerMac struct{}
Expand Down Expand Up @@ -361,7 +363,7 @@ func (o *consoleOptions) getContainerEngineImpl() (containerEngineInterface, err

var containerEngineImpl containerEngineInterface
if runtime.GOOS == LINUX && containerEngine == PODMAN {
containerEngineImpl = &podmanLinux{}
containerEngineImpl = &podmanLinux{fileMountDir: filepath.Join(os.TempDir(), "backplane")}
} else if runtime.GOOS == MACOS && containerEngine == PODMAN {
containerEngineImpl = &podmanMac{}
} else if runtime.GOOS == LINUX && containerEngine == DOCKER {
Expand Down Expand Up @@ -593,21 +595,24 @@ func (o *consoleOptions) runMonitorPlugin(ce containerEngineInterface) error {
logger.Debugln("monitoring plugin is not needed, not to run monitoring plugin")
return nil
}
// Setup nginx configurations
config := fmt.Sprintf(info.MonitoringPluginNginxConfigTemplate, o.monitorPluginPort)
if err := ce.putFileToMount(info.MonitoringPluginNginxConfigFilename, []byte(config)); err != nil {
return err
}

clusterID, err := getClusterID()
if err != nil {
return err
}

// Setup nginx configurations
config := fmt.Sprintf(info.MonitoringPluginNginxConfigTemplate, o.monitorPluginPort)
nginxFilename := fmt.Sprintf(info.MonitoringPluginNginxConfigFilename, clusterID)
if err := ce.putFileToMount(nginxFilename, []byte(config)); err != nil {
return err
}

consoleContainerName := fmt.Sprintf("console-%s", clusterID)
pluginContainerName := fmt.Sprintf("monitoring-plugin-%s", clusterID)

pluginArgs := []string{o.monitorPluginImage}
return ce.runMonitorPlugin(pluginContainerName, consoleContainerName, info.MonitoringPluginNginxConfigFilename, pluginArgs)
return ce.runMonitorPlugin(pluginContainerName, consoleContainerName, nginxFilename, pluginArgs)
}

// print the console URL and pop a browser if required
Expand Down Expand Up @@ -1154,11 +1159,7 @@ func (ce *podmanMac) runMonitorPlugin(containerName string, consoleContainerName
}

func (ce *podmanLinux) runMonitorPlugin(containerName string, consoleContainerName string, nginxConf string, pluginArgs []string) error {
configDirectory, err := config.GetConfigDirctory()
if err != nil {
return err
}
nginxConfPath := filepath.Join(configDirectory, nginxConf)
nginxConfPath := filepath.Join(ce.fileMountDir, nginxConf)
return podmanRunMonitorPlugin(containerName, consoleContainerName, nginxConfPath, pluginArgs)
}

Expand Down Expand Up @@ -1213,12 +1214,12 @@ func (ce *dockerMac) runMonitorPlugin(containerName string, consoleContainerName
// put a file in place for container to mount
// filename should be name only, not a path
func (ce *podmanLinux) putFileToMount(filename string, content []byte) error {
// for files in linux, we put them into the user's backplane config directory
configDirectory, err := config.GetConfigDirctory()
// ensure the directory exists
err := os.MkdirAll(ce.fileMountDir, os.ModePerm)
if err != nil {
return err
}
dstFileName := filepath.Join(configDirectory, filename)
dstFileName := filepath.Join(ce.fileMountDir, filename)

// Check if file already exists, if it does remove it
if _, err = os.Stat(dstFileName); !os.IsNotExist(err) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const (
}
`

MonitoringPluginNginxConfigFilename = "monitoring-plugin-nginx.conf"
MonitoringPluginNginxConfigFilename = "monitoring-plugin-nginx-%s.conf"
)

var (
Expand Down

0 comments on commit c21ada9

Please sign in to comment.