custom namespace

This commit is contained in:
fanyangyang 2020-05-15 20:31:34 +08:00
parent e93fbb5b53
commit 3b89b46674
10 changed files with 72 additions and 20 deletions

View File

@ -74,6 +74,7 @@ type Response struct {
//Request build input
type Request struct {
RbdNamespace string
GRDataPVCName string
CachePVCName string
CacheSource string

View File

@ -271,7 +271,7 @@ func (s *slugBuild) runBuildJob(re *Request) error {
os.Remove(sourceTarFileName)
}()
name := fmt.Sprintf("%s-%s", re.ServiceID, re.DeployVersion)
namespace := "rbd-system"
namespace := re.RbdNamespace
envs := []corev1.EnvVar{
{Name: "SLUG_VERSION", Value: re.DeployVersion},
{Name: "SERVICE_ID", Value: re.ServiceID},
@ -363,6 +363,7 @@ func (s *slugBuild) runBuildJob(re *Request) error {
reChan := channels.NewRingChannel(10)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
logrus.Debugf("create job[name: %s; namespace: %s]", job.Name, job.Namespace)
err = jobc.GetJobController().ExecJob(ctx, &job, writer, reChan)
if err != nil {
logrus.Errorf("create new job:%s failed: %s", name, err.Error())

View File

@ -236,6 +236,7 @@ func (i *SourceCodeBuildItem) codeBuild() (*build.Response, error) {
return nil, err
}
buildReq := &build.Request{
RbdNamespace: i.RbdNamespace,
SourceDir: i.RepoInfo.GetCodeBuildAbsPath(),
CacheDir: i.CacheDir,
TGZDir: i.TGZDir,

View File

@ -105,7 +105,7 @@ func NewManager(conf option.Config, mqc mqclient.MQClient) (Manager, error) {
maxConcurrentTask = conf.MaxTasks
}
stop := make(chan struct{})
if err := job.InitJobController(stop, kubeClient); err != nil {
if err := job.InitJobController(conf.RbdNamespace, stop, kubeClient); err != nil {
cancel()
return nil, err
}

View File

@ -56,11 +56,12 @@ type controller struct {
var jobController *controller
//InitJobController init job controller
func InitJobController(stop chan struct{}, kubeClient kubernetes.Interface) error {
func InitJobController(rbdNamespace string, stop chan struct{}, kubeClient kubernetes.Interface) error {
jobController = &controller{
KubeClient: kubeClient,
namespace: "rbd-system",
namespace: rbdNamespace,
}
logrus.Infof("watch namespace[%s] job ", rbdNamespace)
eventHandler := cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
job, _ := obj.(*corev1.Pod)

View File

@ -68,8 +68,18 @@ func NewSourceBuildCmd() cli.Command {
cli.Command{
Name: "list",
Usage: "Lists the building tasks pod currently being performed",
Flags: []cli.Flag{
cli.StringFlag{
Name: "namespace,ns",
Usage: "rainbond build job namespace",
},
},
Action: func(ctx *cli.Context) {
cmd := exec.Command("kubectl", "get", "pod", "-l", "job=codebuild", "-o", "wide", "-n", "rbd-system")
namespace := ctx.Args().First()
if namespace == "" {
namespace = "rbd-system"
}
cmd := exec.Command("kubectl", "get", "pod", "-l", "job=codebuild", "-o", "wide", "-n", namespace)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()
@ -83,7 +93,12 @@ func NewSourceBuildCmd() cli.Command {
if name == "" {
showError("Please specify the task pod name")
}
cmd := exec.Command("kubectl", "logs", "-f", name, "-n", "rbd-system")
namespace := ctx.Args().Get(1)
if namespace == "" {
namespace = "rbd-system"
}
cmd := exec.Command("kubectl", "logs", "-f", name, "-n", namespace)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()

View File

@ -43,12 +43,24 @@ func NewCmdCluster() cli.Command {
cli.Command{
Name: "config",
Usage: "prints the current cluster configuration",
Flags: []cli.Flag{
cli.StringFlag{
Name: "namespace, ns",
Usage: "rainbond build job namespace",
},
},
Action: func(c *cli.Context) error {
Common(c)
return printConfig(c)
},
},
},
Flags: []cli.Flag{
cli.StringFlag{
Name: "namespace,ns",
Usage: "rainbond build job namespace",
},
},
Action: func(c *cli.Context) error {
Common(c)
return getClusterInfo(c)
@ -58,6 +70,10 @@ func NewCmdCluster() cli.Command {
}
func getClusterInfo(c *cli.Context) error {
namespace := c.Args().First()
if namespace == "" {
namespace = "rbd-system"
}
//show cluster resource detail
clusterInfo, err := clients.RegionClient.Cluster().GetClusterInfo()
if err != nil {
@ -100,7 +116,7 @@ func getClusterInfo(c *cli.Context) error {
fmt.Println(table)
//show component health status
printComponentStatus()
printComponentStatus(namespace)
//show node detail
serviceTable := termtables.CreateTable()
serviceTable.AddHeaders("Uid", "IP", "HostName", "NodeRole", "Status")
@ -230,10 +246,10 @@ func clusterStatus(roleList []map[string]string, ReadyList []map[string]string)
return clusterStatus, errMessage
}
func printComponentStatus() {
func printComponentStatus(namespace string) {
fmt.Println("----------------------------------------------------------------------------------")
fmt.Println()
cmd := exec.Command("kubectl", "get", "pod", "-n", "rbd-system", "-o", "wide")
cmd := exec.Command("kubectl", "get", "pod", "-n", namespace, "-o", "wide")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()
@ -241,7 +257,11 @@ func printComponentStatus() {
}
func printConfig(c *cli.Context) error {
config, err := clients.RainbondKubeClient.RainbondV1alpha1().RainbondClusters("rbd-system").Get("rainbondcluster", metav1.GetOptions{})
namespace := c.Args().First()
if namespace == "" {
namespace = "rbd-system"
}
config, err := clients.RainbondKubeClient.RainbondV1alpha1().RainbondClusters(namespace).Get("rainbondcluster", metav1.GetOptions{})
if err != nil {
showError(err.Error())
}

View File

@ -37,11 +37,19 @@ func NewCmdConfig() cli.Command {
Name: "output,o",
Usage: "write region api config to file",
},
cli.StringFlag{
Name: "namespace,ns",
Usage: "rainbond build job namespace",
},
},
Usage: "show region config file",
Action: func(c *cli.Context) {
Common(c)
configMap, err := clients.K8SClient.CoreV1().ConfigMaps("rbd-system").Get("region-config", metav1.GetOptions{})
namespace := c.GlobalString("namespace")
if namespace == "" {
namespace = "rbd-system"
}
configMap, err := clients.K8SClient.CoreV1().ConfigMaps(namespace).Get("region-config", metav1.GetOptions{})
if err != nil {
showError(err.Error())
}

View File

@ -40,18 +40,24 @@ func NewCmdInstall() cli.Command {
Usage: "all gateway ip of this cluster, use it to access the region api",
EnvVar: "GatewayIP",
},
cli.StringFlag{
Name: "namespace,ns",
Usage: "rainbond namespace",
EnvVar: "RBDNamespace",
},
},
Usage: "grctl install",
Action: func(c *cli.Context) error {
fmt.Println("Start install, please waiting!")
CommonWithoutRegion(c)
apiClientSecrit, err := clients.K8SClient.CoreV1().Secrets("rbd-system").Get("rbd-api-client-cert", metav1.GetOptions{})
namespace := c.GlobalString("namespace")
apiClientSecrit, err := clients.K8SClient.CoreV1().Secrets(namespace).Get("rbd-api-client-cert", metav1.GetOptions{})
if err != nil {
showError(fmt.Sprintf("get region api tls secret failure %s", err.Error()))
}
regionAPIIP := c.StringSlice("gateway-ip")
if len(regionAPIIP) == 0 {
cluster, err := clients.RainbondKubeClient.RainbondV1alpha1().RainbondClusters("rbd-system").Get("rainbondcluster", metav1.GetOptions{})
cluster, err := clients.RainbondKubeClient.RainbondV1alpha1().RainbondClusters(namespace).Get("rainbondcluster", metav1.GetOptions{})
if err != nil {
showError(fmt.Sprintf("get rainbond cluster config failure %s", err.Error()))
}

View File

@ -2,6 +2,7 @@ package main
import (
"fmt"
"os"
"github.com/Sirupsen/logrus"
k8sutil "github.com/goodrain/rainbond/util/k8s"
@ -12,12 +13,6 @@ import (
func main() {
option := app.DefaultOptions
option.K8SConfPath = "/root/.kube/config"
ap, err := app.New(&option)
if err != nil {
logrus.Error(err)
return
}
logrus.Info(ap.GetDefaultContainerName("rbd-system", "rainbond-operator-0"))
config, err := k8sutil.NewRestConfig(option.K8SConfPath)
if err != nil {
logrus.Error(err)
@ -28,11 +23,15 @@ func main() {
if err != nil {
logrus.Error(err)
}
namespace := os.Getenv("namespace")
if namespace == "" {
namespace = "rbd-system"
}
commands := []string{"sh"}
req := restClient.Post().
Resource("pods").
Name("rainbond-operator-0").
Namespace("rbd-system").
Namespace(namespace).
SubResource("exec").
Param("container", "operator").
Param("stdin", "true").