From 8278a8637da3f4572c2310ecf1e137f802bcdbc4 Mon Sep 17 00:00:00 2001
From: CooperLi <a710905118@163.com>
Date: Tue, 31 Aug 2021 20:51:09 +0800
Subject: [PATCH] rpminstaller:add support for openEuler

keadm will install epel-release when edge node want to join cluster,
openEuler does not provide epel-release, it's better to support keadm
join on openEuler ^.^

openEuler is an innovative platform nurtured by community collaboration.
It aims to build a unified and open OS that supports multiple processor architectures,
and to advance the hardware/software application ecosystem.

Signed-off-by: CooperLi <a710905118@163.com>
---
 keadm/cmd/keadm/app/cmd/util/rpminstaller.go | 32 ++++++++++++++++++--
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/keadm/cmd/keadm/app/cmd/util/rpminstaller.go b/keadm/cmd/keadm/app/cmd/util/rpminstaller.go
index 24a55042..0e8fa4b8 100644
--- a/keadm/cmd/keadm/app/cmd/util/rpminstaller.go
+++ b/keadm/cmd/keadm/app/cmd/util/rpminstaller.go
@@ -18,12 +18,17 @@ package util
 
 import (
 	"fmt"
+	"strings"
 
 	"github.com/blang/semver"
 
 	types "github.com/kubeedge/kubeedge/keadm/cmd/keadm/app/cmd/common"
 )
 
+const (
+	openEulerVendorName = "openEuler"
+)
+
 // RpmOS struct objects shall have information of the tools version to be installed
 // on Hosts having RpmOS OS.
 // It implements OSTypeInstaller interface
@@ -51,13 +56,24 @@ func (r *RpmOS) InstallMQTT() error {
 		return nil
 	}
 
-	// install MQTT
-	for _, command := range []string{
+	commands := []string{
 		"yum -y install epel-release",
 		"yum -y install mosquitto",
 		"systemctl start mosquitto",
 		"systemctl enable mosquitto",
-	} {
+	}
+
+	vendorName, err := getOSVendorName()
+	if err != nil {
+		fmt.Printf("Get OS vendor name failed: %v\n", err)
+	}
+	// epel-release package does not included in openEuler
+	if vendorName == openEulerVendorName {
+		commands = commands[1:]
+	}
+
+	// install MQTT
+	for _, command := range commands {
 		cmd := NewCommand(command)
 		if err := cmd.Exec(); err != nil {
 			return err
@@ -116,3 +132,13 @@ func (r *RpmOS) IsKubeEdgeProcessRunning(proc string) (bool, error) {
 func (r *RpmOS) IsProcessRunning(proc string) (bool, error) {
 	return isKubeEdgeProcessRunning(proc)
 }
+
+func getOSVendorName() (string, error) {
+	cmd := NewCommand("cat /etc/os-release | grep -E \"^NAME=\" | awk -F'=' '{print $2}'")
+	if err := cmd.Exec(); err != nil {
+		return "", err
+	}
+	vendor := strings.Trim(cmd.GetStdOut(), "\"")
+
+	return vendor, nil
+}
-- 
2.27.0

