mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-11-29 18:27:58 +08:00
custom namespace
This commit is contained in:
parent
e93fbb5b53
commit
3b89b46674
@ -74,6 +74,7 @@ type Response struct {
|
|||||||
|
|
||||||
//Request build input
|
//Request build input
|
||||||
type Request struct {
|
type Request struct {
|
||||||
|
RbdNamespace string
|
||||||
GRDataPVCName string
|
GRDataPVCName string
|
||||||
CachePVCName string
|
CachePVCName string
|
||||||
CacheSource string
|
CacheSource string
|
||||||
|
@ -271,7 +271,7 @@ func (s *slugBuild) runBuildJob(re *Request) error {
|
|||||||
os.Remove(sourceTarFileName)
|
os.Remove(sourceTarFileName)
|
||||||
}()
|
}()
|
||||||
name := fmt.Sprintf("%s-%s", re.ServiceID, re.DeployVersion)
|
name := fmt.Sprintf("%s-%s", re.ServiceID, re.DeployVersion)
|
||||||
namespace := "rbd-system"
|
namespace := re.RbdNamespace
|
||||||
envs := []corev1.EnvVar{
|
envs := []corev1.EnvVar{
|
||||||
{Name: "SLUG_VERSION", Value: re.DeployVersion},
|
{Name: "SLUG_VERSION", Value: re.DeployVersion},
|
||||||
{Name: "SERVICE_ID", Value: re.ServiceID},
|
{Name: "SERVICE_ID", Value: re.ServiceID},
|
||||||
@ -363,6 +363,7 @@ func (s *slugBuild) runBuildJob(re *Request) error {
|
|||||||
reChan := channels.NewRingChannel(10)
|
reChan := channels.NewRingChannel(10)
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
logrus.Debugf("create job[name: %s; namespace: %s]", job.Name, job.Namespace)
|
||||||
err = jobc.GetJobController().ExecJob(ctx, &job, writer, reChan)
|
err = jobc.GetJobController().ExecJob(ctx, &job, writer, reChan)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("create new job:%s failed: %s", name, err.Error())
|
logrus.Errorf("create new job:%s failed: %s", name, err.Error())
|
||||||
|
@ -236,6 +236,7 @@ func (i *SourceCodeBuildItem) codeBuild() (*build.Response, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
buildReq := &build.Request{
|
buildReq := &build.Request{
|
||||||
|
RbdNamespace: i.RbdNamespace,
|
||||||
SourceDir: i.RepoInfo.GetCodeBuildAbsPath(),
|
SourceDir: i.RepoInfo.GetCodeBuildAbsPath(),
|
||||||
CacheDir: i.CacheDir,
|
CacheDir: i.CacheDir,
|
||||||
TGZDir: i.TGZDir,
|
TGZDir: i.TGZDir,
|
||||||
|
@ -105,7 +105,7 @@ func NewManager(conf option.Config, mqc mqclient.MQClient) (Manager, error) {
|
|||||||
maxConcurrentTask = conf.MaxTasks
|
maxConcurrentTask = conf.MaxTasks
|
||||||
}
|
}
|
||||||
stop := make(chan struct{})
|
stop := make(chan struct{})
|
||||||
if err := job.InitJobController(stop, kubeClient); err != nil {
|
if err := job.InitJobController(conf.RbdNamespace, stop, kubeClient); err != nil {
|
||||||
cancel()
|
cancel()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -56,11 +56,12 @@ type controller struct {
|
|||||||
var jobController *controller
|
var jobController *controller
|
||||||
|
|
||||||
//InitJobController init job 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{
|
jobController = &controller{
|
||||||
KubeClient: kubeClient,
|
KubeClient: kubeClient,
|
||||||
namespace: "rbd-system",
|
namespace: rbdNamespace,
|
||||||
}
|
}
|
||||||
|
logrus.Infof("watch namespace[%s] job ", rbdNamespace)
|
||||||
eventHandler := cache.ResourceEventHandlerFuncs{
|
eventHandler := cache.ResourceEventHandlerFuncs{
|
||||||
AddFunc: func(obj interface{}) {
|
AddFunc: func(obj interface{}) {
|
||||||
job, _ := obj.(*corev1.Pod)
|
job, _ := obj.(*corev1.Pod)
|
||||||
|
@ -68,8 +68,18 @@ func NewSourceBuildCmd() cli.Command {
|
|||||||
cli.Command{
|
cli.Command{
|
||||||
Name: "list",
|
Name: "list",
|
||||||
Usage: "Lists the building tasks pod currently being performed",
|
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) {
|
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.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
cmd.Run()
|
cmd.Run()
|
||||||
@ -83,7 +93,12 @@ func NewSourceBuildCmd() cli.Command {
|
|||||||
if name == "" {
|
if name == "" {
|
||||||
showError("Please specify the task pod 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.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
cmd.Run()
|
cmd.Run()
|
||||||
|
@ -43,12 +43,24 @@ func NewCmdCluster() cli.Command {
|
|||||||
cli.Command{
|
cli.Command{
|
||||||
Name: "config",
|
Name: "config",
|
||||||
Usage: "prints the current cluster configuration",
|
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 {
|
Action: func(c *cli.Context) error {
|
||||||
Common(c)
|
Common(c)
|
||||||
return printConfig(c)
|
return printConfig(c)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "namespace,ns",
|
||||||
|
Usage: "rainbond build job namespace",
|
||||||
|
},
|
||||||
|
},
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
Common(c)
|
Common(c)
|
||||||
return getClusterInfo(c)
|
return getClusterInfo(c)
|
||||||
@ -58,6 +70,10 @@ func NewCmdCluster() cli.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getClusterInfo(c *cli.Context) error {
|
func getClusterInfo(c *cli.Context) error {
|
||||||
|
namespace := c.Args().First()
|
||||||
|
if namespace == "" {
|
||||||
|
namespace = "rbd-system"
|
||||||
|
}
|
||||||
//show cluster resource detail
|
//show cluster resource detail
|
||||||
clusterInfo, err := clients.RegionClient.Cluster().GetClusterInfo()
|
clusterInfo, err := clients.RegionClient.Cluster().GetClusterInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -100,7 +116,7 @@ func getClusterInfo(c *cli.Context) error {
|
|||||||
fmt.Println(table)
|
fmt.Println(table)
|
||||||
|
|
||||||
//show component health status
|
//show component health status
|
||||||
printComponentStatus()
|
printComponentStatus(namespace)
|
||||||
//show node detail
|
//show node detail
|
||||||
serviceTable := termtables.CreateTable()
|
serviceTable := termtables.CreateTable()
|
||||||
serviceTable.AddHeaders("Uid", "IP", "HostName", "NodeRole", "Status")
|
serviceTable.AddHeaders("Uid", "IP", "HostName", "NodeRole", "Status")
|
||||||
@ -230,10 +246,10 @@ func clusterStatus(roleList []map[string]string, ReadyList []map[string]string)
|
|||||||
return clusterStatus, errMessage
|
return clusterStatus, errMessage
|
||||||
}
|
}
|
||||||
|
|
||||||
func printComponentStatus() {
|
func printComponentStatus(namespace string) {
|
||||||
fmt.Println("----------------------------------------------------------------------------------")
|
fmt.Println("----------------------------------------------------------------------------------")
|
||||||
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.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
cmd.Run()
|
cmd.Run()
|
||||||
@ -241,7 +257,11 @@ func printComponentStatus() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func printConfig(c *cli.Context) error {
|
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 {
|
if err != nil {
|
||||||
showError(err.Error())
|
showError(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -37,11 +37,19 @@ func NewCmdConfig() cli.Command {
|
|||||||
Name: "output,o",
|
Name: "output,o",
|
||||||
Usage: "write region api config to file",
|
Usage: "write region api config to file",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "namespace,ns",
|
||||||
|
Usage: "rainbond build job namespace",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Usage: "show region config file",
|
Usage: "show region config file",
|
||||||
Action: func(c *cli.Context) {
|
Action: func(c *cli.Context) {
|
||||||
Common(c)
|
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 {
|
if err != nil {
|
||||||
showError(err.Error())
|
showError(err.Error())
|
||||||
}
|
}
|
||||||
|
@ -40,18 +40,24 @@ func NewCmdInstall() cli.Command {
|
|||||||
Usage: "all gateway ip of this cluster, use it to access the region api",
|
Usage: "all gateway ip of this cluster, use it to access the region api",
|
||||||
EnvVar: "GatewayIP",
|
EnvVar: "GatewayIP",
|
||||||
},
|
},
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "namespace,ns",
|
||||||
|
Usage: "rainbond namespace",
|
||||||
|
EnvVar: "RBDNamespace",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Usage: "grctl install",
|
Usage: "grctl install",
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
fmt.Println("Start install, please waiting!")
|
fmt.Println("Start install, please waiting!")
|
||||||
CommonWithoutRegion(c)
|
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 {
|
if err != nil {
|
||||||
showError(fmt.Sprintf("get region api tls secret failure %s", err.Error()))
|
showError(fmt.Sprintf("get region api tls secret failure %s", err.Error()))
|
||||||
}
|
}
|
||||||
regionAPIIP := c.StringSlice("gateway-ip")
|
regionAPIIP := c.StringSlice("gateway-ip")
|
||||||
if len(regionAPIIP) == 0 {
|
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 {
|
if err != nil {
|
||||||
showError(fmt.Sprintf("get rainbond cluster config failure %s", err.Error()))
|
showError(fmt.Sprintf("get rainbond cluster config failure %s", err.Error()))
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
k8sutil "github.com/goodrain/rainbond/util/k8s"
|
k8sutil "github.com/goodrain/rainbond/util/k8s"
|
||||||
@ -12,12 +13,6 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
option := app.DefaultOptions
|
option := app.DefaultOptions
|
||||||
option.K8SConfPath = "/root/.kube/config"
|
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)
|
config, err := k8sutil.NewRestConfig(option.K8SConfPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
@ -28,11 +23,15 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
}
|
}
|
||||||
|
namespace := os.Getenv("namespace")
|
||||||
|
if namespace == "" {
|
||||||
|
namespace = "rbd-system"
|
||||||
|
}
|
||||||
commands := []string{"sh"}
|
commands := []string{"sh"}
|
||||||
req := restClient.Post().
|
req := restClient.Post().
|
||||||
Resource("pods").
|
Resource("pods").
|
||||||
Name("rainbond-operator-0").
|
Name("rainbond-operator-0").
|
||||||
Namespace("rbd-system").
|
Namespace(namespace).
|
||||||
SubResource("exec").
|
SubResource("exec").
|
||||||
Param("container", "operator").
|
Param("container", "operator").
|
||||||
Param("stdin", "true").
|
Param("stdin", "true").
|
||||||
|
Loading…
Reference in New Issue
Block a user