Merge branch 'master' into container-log

This commit is contained in:
黄润豪 2021-08-04 18:46:18 +08:00 committed by GitHub
commit b2f4afc7ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
46 changed files with 520 additions and 384 deletions

View File

@ -24,4 +24,4 @@ jobs:
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
DOMESTIC_DOCKER_PASSWORD: ${{ secrets.DOMESTIC_DOCKER_PASSWORD }}
DOMESTIC_DOCKER_USERNAME: ${{ secrets.DOMESTIC_DOCKER_USERNAME }}
run: VERSION=v5.3.2-beta ./release.sh all push
run: VERSION=v5.3.3-release ./release.sh all push

View File

@ -68,9 +68,11 @@ func (t *TenantStruct) StartService(w http.ResponseWriter, r *http.Request) {
tenant := r.Context().Value(ctxutil.ContextKey("tenant")).(*dbmodel.Tenants)
service := r.Context().Value(ctxutil.ContextKey("service")).(*dbmodel.TenantServices)
sEvent := r.Context().Value(ctxutil.ContextKey("event")).(*dbmodel.ServiceEvent)
if err := handler.CheckTenantResource(r.Context(), tenant, service.Replicas*service.ContainerMemory); err != nil {
httputil.ReturnResNotEnough(r, w, sEvent.EventID, err.Error())
return
if service.Kind != "third_party" {
if err := handler.CheckTenantResource(r.Context(), tenant, service.Replicas*service.ContainerMemory); err != nil {
httputil.ReturnResNotEnough(r, w, sEvent.EventID, err.Error())
return
}
}
startStopStruct := &api_model.StartStopStruct{
@ -84,7 +86,6 @@ func (t *TenantStruct) StartService(w http.ResponseWriter, r *http.Request) {
return
}
httputil.ReturnSuccess(r, w, sEvent)
return
}
//StopService StopService
@ -177,7 +178,6 @@ func (t *TenantStruct) RestartService(w http.ResponseWriter, r *http.Request) {
return
}
httputil.ReturnSuccess(r, w, sEvent)
return
}
//VerticalService VerticalService
@ -213,23 +213,23 @@ func (t *TenantStruct) VerticalService(w http.ResponseWriter, r *http.Request) {
tenantID := r.Context().Value(ctxutil.ContextKey("tenant_id")).(string)
serviceID := r.Context().Value(ctxutil.ContextKey("service_id")).(string)
sEvent := r.Context().Value(ctxutil.ContextKey("event")).(*dbmodel.ServiceEvent)
var cpu_set, gpu_set, memory_set *int
var cpuSet, gpuSet, memorySet *int
if cpu, ok := data["container_cpu"].(float64); ok {
cpu_int := int(cpu)
cpu_set = &cpu_int
cpuInt := int(cpu)
cpuSet = &cpuInt
}
if memory, ok := data["container_memory"].(float64); ok {
memory_int := int(memory)
memory_set = &memory_int
memoryInt := int(memory)
memorySet = &memoryInt
}
if gpu, ok := data["container_gpu"].(float64); ok {
gpu_int := int(gpu)
gpu_set = &gpu_int
gpuInt := int(gpu)
gpuSet = &gpuInt
}
tenant := r.Context().Value(ctxutil.ContextKey("tenant")).(*dbmodel.Tenants)
service := r.Context().Value(ctxutil.ContextKey("service")).(*dbmodel.TenantServices)
if memory_set != nil {
if err := handler.CheckTenantResource(r.Context(), tenant, service.Replicas*(*memory_set)); err != nil {
if memorySet != nil {
if err := handler.CheckTenantResource(r.Context(), tenant, service.Replicas*(*memorySet)); err != nil {
httputil.ReturnResNotEnough(r, w, sEvent.EventID, err.Error())
return
}
@ -238,9 +238,9 @@ func (t *TenantStruct) VerticalService(w http.ResponseWriter, r *http.Request) {
TenantID: tenantID,
ServiceID: serviceID,
EventID: sEvent.EventID,
ContainerCPU: cpu_set,
ContainerMemory: memory_set,
ContainerGPU: gpu_set,
ContainerCPU: cpuSet,
ContainerMemory: memorySet,
ContainerGPU: gpuSet,
}
if err := handler.GetServiceManager().ServiceVertical(r.Context(), verticalTask); err != nil {
httputil.ReturnError(r, w, 500, fmt.Sprintf("service vertical error. %v", err))
@ -475,7 +475,7 @@ func (t *TenantStruct) GetDeployVersion(w http.ResponseWriter, r *http.Request)
return
}
if err == gorm.ErrRecordNotFound {
httputil.ReturnError(r, w, 404, fmt.Sprintf("build version do not exist"))
httputil.ReturnError(r, w, 404, "build version do not exist")
return
}
httputil.ReturnSuccess(r, w, version)
@ -492,7 +492,7 @@ func (t *TenantStruct) GetManyDeployVersion(w http.ResponseWriter, r *http.Reque
}
serviceIDs, ok := data["service_ids"].([]interface{})
if !ok {
httputil.ReturnError(r, w, 400, fmt.Sprintf("service ids must be a array"))
httputil.ReturnError(r, w, 400, "service ids must be a array")
return
}
var list []string
@ -501,7 +501,7 @@ func (t *TenantStruct) GetManyDeployVersion(w http.ResponseWriter, r *http.Reque
}
services, err := db.GetManager().TenantServiceDao().GetServiceByIDs(list)
if err != nil {
httputil.ReturnError(r, w, 500, fmt.Sprintf(err.Error()))
httputil.ReturnError(r, w, 500, err.Error())
return
}
var versionList []*dbmodel.VersionInfo
@ -656,7 +656,6 @@ func (t *TenantStruct) RollBack(w http.ResponseWriter, r *http.Request) {
re := handler.GetOperationHandler().RollBack(rollbackRequest)
httputil.ReturnSuccess(r, w, re)
return
}
type limitMemory struct {

View File

@ -359,7 +359,7 @@ func (t *TenantAction) GetTenantsResources(ctx context.Context, tr *api_model.Te
disk = int(mv.Sample.Value() / 1024)
}
if tenantID != "" {
result[tenantID]["disk"] = disk / 1024
result[tenantID]["disk"] = disk
}
}
return result, nil

View File

@ -25,6 +25,7 @@ import (
"github.com/goodrain/rainbond/builder"
"github.com/goodrain/rainbond/builder/parser/code"
"github.com/goodrain/rainbond/builder/sources"
"github.com/goodrain/rainbond/event"
"k8s.io/client-go/kubernetes"
@ -43,6 +44,7 @@ func init() {
buildcreaters[code.Python] = slugBuilder
buildcreaters[code.Nodejs] = slugBuilder
buildcreaters[code.Golang] = slugBuilder
buildcreaters[code.OSS] = slugBuilder
}
var buildcreaters map[code.Lang]CreaterBuild
@ -82,6 +84,7 @@ type Request struct {
CacheDir string
TGZDir string
RepositoryURL string
CodeSouceInfo sources.CodeSourceInfo
Branch string
ServiceAlias string
ServiceID string

View File

@ -19,11 +19,9 @@
package build
import (
"bufio"
"context"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
@ -33,14 +31,11 @@ import (
"github.com/docker/docker/api/types"
"github.com/eapache/channels"
"github.com/fsnotify/fsnotify"
"github.com/goodrain/rainbond/builder"
jobc "github.com/goodrain/rainbond/builder/job"
"github.com/goodrain/rainbond/builder/parser/code"
"github.com/goodrain/rainbond/builder/sources"
"github.com/goodrain/rainbond/event"
"github.com/goodrain/rainbond/util"
"github.com/pquerna/ffjson/ffjson"
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -53,7 +48,6 @@ func slugBuilder() (Build, error) {
type slugBuild struct {
tgzDir string
buildCacheDir string
sourceDir string
re *Request
}
@ -107,8 +101,14 @@ func (s *slugBuild) Build(re *Request) (*Response, error) {
func (s *slugBuild) writeRunDockerfile(sourceDir, packageName string, envs map[string]string) error {
runDockerfile := `
FROM %s
ARG CODE_COMMIT_HASH
ARG CODE_COMMIT_USER
ARG CODE_COMMIT_MESSAGE
COPY %s /tmp/slug/slug.tgz
RUN chown rain:rain /tmp/slug/slug.tgz
ENV CODE_COMMIT_HASH=${CODE_COMMIT_HASH}
ENV CODE_COMMIT_USER=${CODE_COMMIT_USER}
ENV CODE_COMMIT_MESSAGE=${CODE_COMMIT_MESSAGE}
ENV VERSION=%s
`
result := util.ParseVariable(fmt.Sprintf(runDockerfile, builder.RUNNERIMAGENAME, packageName, s.re.DeployVersion), envs)
@ -138,6 +138,11 @@ func (s *slugBuild) buildRunnerImage(slugPackage string) (string, error) {
}
//build runtime image
runbuildOptions := types.ImageBuildOptions{
BuildArgs: map[string]*string{
"CODE_COMMIT_HASH": &s.re.Commit.Hash,
"CODE_COMMIT_USER": &s.re.Commit.User,
"CODE_COMMIT_MESSAGE": &s.re.Commit.Message,
},
Tags: []string{imageName},
Remove: true,
}
@ -178,56 +183,6 @@ func (s *slugBuild) buildRunnerImage(slugPackage string) (string, error) {
return imageName, nil
}
func (s *slugBuild) readLogFile(logfile string, logger event.Logger, closed chan struct{}) {
file, _ := os.Open(logfile)
watcher, _ := fsnotify.NewWatcher()
defer watcher.Close()
_ = watcher.Add(logfile)
readerr := bufio.NewReader(file)
for {
line, _, err := readerr.ReadLine()
if err != nil {
if err != io.EOF {
logrus.Errorf("Read build container log error:%s", err.Error())
return
}
wait := func() error {
for {
select {
case <-closed:
return nil
case evt := <-watcher.Events:
if evt.Op&fsnotify.Write == fsnotify.Write {
return nil
}
case err := <-watcher.Errors:
return err
}
}
}
if err := wait(); err != nil {
logrus.Errorf("Read build container log error:%s", err.Error())
return
}
}
if logger != nil {
var message = make(map[string]string)
if err := ffjson.Unmarshal(line, &message); err == nil {
if m, ok := message["log"]; ok {
logger.Info(m, map[string]string{"step": "build-exector"})
}
} else {
fmt.Println(err.Error())
}
}
select {
case <-closed:
return
default:
}
}
}
func (s *slugBuild) getSourceCodeTarFile(re *Request) (string, error) {
var cmd []string
sourceTarFile := fmt.Sprintf("%s/%s-%s.tar", util.GetParentDirectory(re.SourceDir), re.ServiceID, re.DeployVersion)
@ -253,7 +208,7 @@ func (s *slugBuild) stopPreBuildJob(re *Request) error {
if err != nil {
logrus.Errorf("get pre build job for service %s failure ,%s", re.ServiceID, err.Error())
}
if jobList != nil && len(jobList) > 0 {
if len(jobList) > 0 {
for _, job := range jobList {
jobc.GetJobController().DeleteJob(job.Name)
}
@ -263,6 +218,7 @@ func (s *slugBuild) stopPreBuildJob(re *Request) error {
func (s *slugBuild) createVolumeAndMount(re *Request, sourceTarFileName string) (volumes []corev1.Volume, volumeMounts []corev1.VolumeMount) {
slugSubPath := strings.TrimPrefix(re.TGZDir, "/grdata/")
lazyloading := sourceTarFileName == ""
sourceTarPath := strings.TrimPrefix(sourceTarFileName, "/cache/")
cacheSubPath := strings.TrimPrefix(re.CacheDir, "/cache/")
@ -279,10 +235,12 @@ func (s *slugBuild) createVolumeAndMount(re *Request, sourceTarFileName string)
MountPath: "/tmp/slug",
SubPath: slugSubPath,
},
{
}
if !lazyloading {
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: "source-file",
MountPath: "/tmp/app-source.tar",
},
})
}
volumes = []corev1.Volume{
{
@ -302,7 +260,9 @@ func (s *slugBuild) createVolumeAndMount(re *Request, sourceTarFileName string)
},
},
},
{
}
if !lazyloading {
volumes = append(volumes, corev1.Volume{
Name: "source-file",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
@ -311,7 +271,7 @@ func (s *slugBuild) createVolumeAndMount(re *Request, sourceTarFileName string)
Type: &unset,
},
},
},
})
}
} else {
volumes = []corev1.Volume{
@ -343,11 +303,13 @@ func (s *slugBuild) createVolumeAndMount(re *Request, sourceTarFileName string)
MountPath: "/tmp/slug",
SubPath: slugSubPath,
},
{
}
if !lazyloading {
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: "app",
MountPath: "/tmp/app-source.tar",
SubPath: sourceTarPath,
},
})
}
}
return volumes, volumeMounts
@ -357,16 +319,21 @@ func (s *slugBuild) runBuildJob(re *Request) error {
//prepare build code dir
re.Logger.Info(util.Translation("Start make code package"), map[string]string{"step": "build-exector"})
start := time.Now()
sourceTarFileName, err := s.getSourceCodeTarFile(re)
if err != nil {
return fmt.Errorf("create source code tar file error:%s", err.Error())
var sourceTarFileName string
if re.ServerType != "oss" {
var err error
sourceTarFileName, err = s.getSourceCodeTarFile(re)
if err != nil {
return fmt.Errorf("create source code tar file error:%s", err.Error())
}
// remove source cache tar file
defer func() {
os.Remove(sourceTarFileName)
}()
}
re.Logger.Info(util.Translation("make code package success"), map[string]string{"step": "build-exector"})
logrus.Infof("package code for building service %s version %s successful, take time %s", re.ServiceID, re.DeployVersion, time.Now().Sub(start))
// remove source cache tar file
defer func() {
os.Remove(sourceTarFileName)
}()
name := fmt.Sprintf("%s-%s", re.ServiceID, re.DeployVersion)
namespace := re.RbdNamespace
job := corev1.Pod{
@ -383,8 +350,16 @@ func (s *slugBuild) runBuildJob(re *Request) error {
{Name: "SLUG_VERSION", Value: re.DeployVersion},
{Name: "SERVICE_ID", Value: re.ServiceID},
{Name: "TENANT_ID", Value: re.TenantID},
{Name: "CODE_COMMIT_HASH", Value: re.Commit.Hash},
{Name: "CODE_COMMIT_USER", Value: re.Commit.User},
{Name: "CODE_COMMIT_MESSAGE", Value: re.Commit.Message},
{Name: "LANGUAGE", Value: re.Lang.String()},
}
if re.ServerType == "oss" {
envs = append(envs, corev1.EnvVar{Name: "PACKAGE_DOWNLOAD_URL", Value: re.RepositoryURL})
envs = append(envs, corev1.EnvVar{Name: "PACKAGE_DOWNLOAD_USER", Value: re.CodeSouceInfo.User})
envs = append(envs, corev1.EnvVar{Name: "PACKAGE_DOWNLOAD_PASS", Value: re.CodeSouceInfo.Password})
}
var mavenSettingName string
for k, v := range re.BuildEnvs {
if k == "MAVEN_SETTING_NAME" {
@ -489,7 +464,7 @@ func (s *slugBuild) runBuildJob(re *Request) error {
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)
err := jobc.GetJobController().ExecJob(ctx, &job, writer, reChan)
if err != nil {
logrus.Errorf("create new job:%s failed: %s", name, err.Error())
return err

View File

@ -11,12 +11,13 @@ import (
"testing"
"time"
"github.com/goodrain/rainbond/builder/parser/code"
"github.com/goodrain/rainbond/cmd/builder/option"
"github.com/goodrain/rainbond/event"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
jobc "github.com/goodrain/rainbond/builder/job"
"github.com/goodrain/rainbond/builder/parser/code"
"github.com/goodrain/rainbond/builder/sources"
"github.com/goodrain/rainbond/cmd/builder/option"
"github.com/goodrain/rainbond/event"
etcdutil "github.com/goodrain/rainbond/util/etcd"
k8sutil "github.com/goodrain/rainbond/util/k8s"
@ -126,3 +127,46 @@ func TestDockerClient(t *testing.T) {
// t.Log("image is : ", image.ID)
// }
}
func TestBuildFromOSS(t *testing.T) {
restConfig, err := k8sutil.NewRestConfig("/Users/barnett/.kube/config")
if err != nil {
t.Fatal(err)
}
os.Setenv("IMAGE_PULL_SECRET", "rbd-hub-credentials")
clientset, err := kubernetes.NewForConfig(restConfig)
if err != nil {
t.Fatal(err)
}
stop := make(chan struct{})
if err := jobc.InitJobController("rbd-system", stop, clientset); err != nil {
t.Fatal(err)
}
logger := event.GetTestLogger()
req := &Request{
ServerType: "oss",
RepositoryURL: "http://8081.gr021644.64q1jlfb.17f4cc.grapps.cn/artifactory/dev/java-war-demo-master.zip",
CodeSouceInfo: sources.CodeSourceInfo{
User: "demo",
Password: "gr123465!",
},
KubeClient: clientset,
Ctx: context.Background(),
ServiceID: "d9b8d718510dc53118af1e1219e36d3a",
DeployVersion: "123asdadsadsasdasd1",
TenantID: "7c89455140284fd7b263038b44dc65bc",
Lang: code.OSS,
Logger: logger,
GRDataPVCName: "rbd-cpt-grdata",
CachePVCName: "rbd-chaos-cache",
}
build, err := GetBuild(code.OSS)
if err != nil {
t.Fatal(err)
}
res, err := build.Build(req)
if err != nil {
t.Fatal(err)
}
t.Log(res.MediumPath)
}

View File

@ -40,9 +40,8 @@ import (
"github.com/goodrain/rainbond/util"
"github.com/pquerna/ffjson/ffjson"
"github.com/sirupsen/logrus"
"github.com/tidwall/gjson" //"github.com/docker/docker/api/types"
"github.com/tidwall/gjson"
"k8s.io/client-go/kubernetes"
//"github.com/docker/docker/client"
)
//SourceCodeBuildItem SouceCodeBuildItem
@ -59,8 +58,7 @@ type SourceCodeBuildItem struct {
Logger event.Logger `json:"logger"`
EventID string `json:"event_id"`
CacheDir string `json:"cache_dir"`
//SourceDir string `json:"source_dir"`
TGZDir string `json:"tgz_dir"`
TGZDir string `json:"tgz_dir"`
DockerClient *client.Client
KubeClient kubernetes.Interface
RbdNamespace string
@ -139,7 +137,7 @@ func (i *SourceCodeBuildItem) Run(timeout time.Duration) error {
i.RepoInfo = rbi
if err := i.prepare(); err != nil {
logrus.Errorf("prepare build code error: %s", err.Error())
i.Logger.Error(fmt.Sprintf("准备源码构建失败"), map[string]string{"step": "builder-exector", "status": "failure"})
i.Logger.Error("准备源码构建失败", map[string]string{"step": "builder-exector", "status": "failure"})
return err
}
i.CodeSouceInfo.RepositoryURL = rbi.RepostoryURL
@ -163,19 +161,21 @@ func (i *SourceCodeBuildItem) Run(timeout time.Duration) error {
Message: rs.Logs.CommitEntrys[0].Msg,
Author: rs.Logs.CommitEntrys[0].Author,
}
case "oss":
i.commit = Commit{}
default:
//default git
rs, err := sources.GitCloneOrPull(i.CodeSouceInfo, rbi.GetCodeHome(), i.Logger, 5)
if err != nil {
logrus.Errorf("pull git code error: %s", err.Error())
i.Logger.Error(fmt.Sprintf("拉取代码失败,请确保代码可以被正常下载"), map[string]string{"step": "builder-exector", "status": "failure"})
i.Logger.Error("拉取代码失败,请确保代码可以被正常下载", map[string]string{"step": "builder-exector", "status": "failure"})
return err
}
//get last commit
commit, err := sources.GetLastCommit(rs)
if err != nil || commit == nil {
logrus.Errorf("get code commit info error: %s", err.Error())
i.Logger.Error(fmt.Sprintf("读取代码版本信息失败"), map[string]string{"step": "builder-exector", "status": "failure"})
i.Logger.Error("读取代码版本信息失败", map[string]string{"step": "builder-exector", "status": "failure"})
return err
}
i.commit = Commit{
@ -241,6 +241,7 @@ func (i *SourceCodeBuildItem) codeBuild() (*build.Response, error) {
CacheDir: i.CacheDir,
TGZDir: i.TGZDir,
RepositoryURL: i.RepoInfo.RepostoryURL,
CodeSouceInfo: i.CodeSouceInfo,
ServiceAlias: i.ServiceAlias,
ServiceID: i.ServiceID,
TenantID: i.TenantID,
@ -265,21 +266,6 @@ func (i *SourceCodeBuildItem) codeBuild() (*build.Response, error) {
return res, err
}
func (i *SourceCodeBuildItem) getExtraHosts() (extraHosts []string, err error) {
endpoints, err := i.KubeClient.CoreV1().Endpoints(i.RbdNamespace).Get(context.Background(), i.RbdRepoName, metav1.GetOptions{})
if err != nil {
logrus.Errorf("do not found ep by name: %s in namespace: %s", i.RbdRepoName, i.Namespace)
return nil, err
}
for _, subset := range endpoints.Subsets {
for _, addr := range subset.Addresses {
extraHosts = append(extraHosts, fmt.Sprintf("maven.goodrain.me:%s", addr.IP))
extraHosts = append(extraHosts, fmt.Sprintf("lang.goodrain.me:%s", addr.IP))
}
}
return
}
func (i *SourceCodeBuildItem) getHostAlias() (hostAliasList []build.HostAlias, err error) {
endpoints, err := i.KubeClient.CoreV1().Endpoints(i.RbdNamespace).Get(context.Background(), i.RbdRepoName, metav1.GetOptions{})
if err != nil {

View File

@ -287,7 +287,7 @@ func (e *exectorManager) buildFromImage(task *pb.TaskMessage) {
}()
start := time.Now()
defer func() {
logrus.Debugf("complete build from source code, consuming time %s", time.Now().Sub(start).String())
logrus.Debugf("complete build from source code, consuming time %s", time.Since(start).String())
}()
for n := 0; n < 2; n++ {
err := i.Run(time.Minute * 30)

View File

@ -125,14 +125,12 @@ func (e *exectorManager) serviceCheck(task *pb.TaskMessage) {
return
}
errList := pr.Parse()
if errList != nil {
for i, err := range errList {
if err.SolveAdvice == "" && input.SourceType != "sourcecode" {
errList[i].SolveAdvice = fmt.Sprintf("解析器认为镜像名为:%s,请确认是否正确或镜像是否存在", pr.GetImage())
}
if err.SolveAdvice == "" && input.SourceType == "sourcecode" {
errList[i].SolveAdvice = fmt.Sprintf("源码智能解析失败,请联系客服")
}
for i, err := range errList {
if err.SolveAdvice == "" && input.SourceType != "sourcecode" {
errList[i].SolveAdvice = fmt.Sprintf("解析器认为镜像名为:%s,请确认是否正确或镜像是否存在", pr.GetImage())
}
if err.SolveAdvice == "" && input.SourceType == "sourcecode" {
errList[i].SolveAdvice = "源码智能解析失败"
}
}
serviceInfos := pr.GetServiceInfo()

View File

@ -115,6 +115,9 @@ var Grails Lang = "Grails"
//NetCore Lang
var NetCore Lang = ".NetCore"
//OSS Lang
var OSS Lang = "OSS"
//GetLangType check code lang
func GetLangType(homepath string) (Lang, error) {
if ok, _ := util.FileExists(homepath); !ok {

View File

@ -50,7 +50,10 @@ func init() {
}
//CheckCodeSpecification 检查语言规范
func CheckCodeSpecification(buildPath string, lang Lang) Specification {
func CheckCodeSpecification(buildPath string, lang Lang, serverType string) Specification {
if serverType == "oss" && lang == JavaJar {
return common()
}
if check, ok := specification[lang]; ok {
return check(buildPath)
}

View File

@ -19,13 +19,15 @@
package parser
import (
"context"
"encoding/base64"
"fmt"
"os"
"path"
"runtime"
"strconv"
"strings"
"github.com/docker/docker/client"
"github.com/goodrain/rainbond/builder"
"github.com/goodrain/rainbond/builder/parser/code"
multi "github.com/goodrain/rainbond/builder/parser/code/multisvc"
@ -34,6 +36,7 @@ import (
"github.com/goodrain/rainbond/db/model"
"github.com/goodrain/rainbond/event"
"github.com/goodrain/rainbond/util"
"github.com/melbahja/got"
"github.com/pquerna/ffjson/ffjson"
"github.com/sirupsen/logrus"
"gopkg.in/src-d/go-git.v4/plumbing"
@ -42,18 +45,17 @@ import (
//SourceCodeParse docker run 命令解析或直接镜像名解析
type SourceCodeParse struct {
ports map[int]*types.Port
volumes map[string]*types.Volume
envs map[string]*types.Env
source string
memory int
image Image
args []string
branchs []string
errors []ParseError
dockerclient *client.Client
logger event.Logger
Lang code.Lang
ports map[int]*types.Port
volumes map[string]*types.Volume
envs map[string]*types.Env
source string
memory int
image Image
args []string
branchs []string
errors []ParseError
logger event.Logger
Lang code.Lang
Runtime bool `json:"runtime"`
Dependencies bool `json:"dependencies"`
@ -83,6 +85,7 @@ func (d *SourceCodeParse) Parse() ParseErrorList {
d.errappend(Errorf(FatalError, "source can not be empty"))
return d.errors
}
logrus.Debugf("component source check info: %s", d.source)
var csi sources.CodeSourceInfo
err := ffjson.Unmarshal([]byte(d.source), &csi)
if err != nil {
@ -105,6 +108,14 @@ func (d *SourceCodeParse) Parse() ParseErrorList {
d.errappend(ErrorAndSolve(FatalError, "Git项目仓库地址格式错误", SolveAdvice("modify_url", "请确认并修改仓库地址")))
return d.errors
}
// The source code is useless after the test is completed, and needs to be deleted.
defer func() {
if sources.CheckFileExist(buildInfo.GetCodeHome()) {
if err := sources.RemoveDir(buildInfo.GetCodeHome()); err != nil {
logrus.Warningf("remove source code: %v", err)
}
}
}()
gitFunc := func() ParseErrorList {
//get code
if !util.DirIsEmpty(buildInfo.GetCodeHome()) {
@ -131,26 +142,26 @@ func (d *SourceCodeParse) Parse() ParseErrorList {
}
if err == transport.ErrRepositoryNotFound {
solve := SolveAdvice("modify_repo", "请确认仓库地址是否正确")
d.errappend(ErrorAndSolve(FatalError, fmt.Sprintf("Git项目仓库不存在"), solve))
d.errappend(ErrorAndSolve(FatalError, "Git项目仓库不存在", solve))
return d.errors
}
if err == transport.ErrEmptyRemoteRepository {
solve := SolveAdvice("open_repo", "请确认已提交代码")
d.errappend(ErrorAndSolve(FatalError, fmt.Sprintf("Git项目仓库无有效文件"), solve))
d.errappend(ErrorAndSolve(FatalError, "Git项目仓库无有效文件", solve))
return d.errors
}
if strings.Contains(err.Error(), "ssh: unable to authenticate") {
solve := SolveAdvice("get_publickey", "请获取授权Key配置到你的仓库项目试试")
d.errappend(ErrorAndSolve(FatalError, fmt.Sprintf("远程仓库SSH验证错误"), solve))
d.errappend(ErrorAndSolve(FatalError, "远程仓库SSH验证错误", solve))
return d.errors
}
if strings.Contains(err.Error(), "context deadline exceeded") {
solve := "请确认源码仓库能否正常访问"
d.errappend(ErrorAndSolve(FatalError, fmt.Sprintf("获取代码超时"), solve))
d.errappend(ErrorAndSolve(FatalError, "获取代码超时", solve))
return d.errors
}
logrus.Errorf("git clone error,%s", err.Error())
d.errappend(ErrorAndSolve(FatalError, fmt.Sprintf("获取代码失败"), "请确认仓库能否正常访问,或联系客服咨询"))
d.errappend(ErrorAndSolve(FatalError, "获取代码失败"+err.Error(), "请确认仓库能否正常访问。"))
return d.errors
}
//获取分支
@ -172,7 +183,6 @@ func (d *SourceCodeParse) Parse() ParseErrorList {
svnFunc := func() ParseErrorList {
if sources.CheckFileExist(buildInfo.GetCodeHome()) {
if err := sources.RemoveDir(buildInfo.GetCodeHome()); err != nil {
//d.errappend(ErrorAndSolve(err, "清理cache dir错误", "请提交代码到仓库"))
return d.errors
}
}
@ -186,14 +196,56 @@ func (d *SourceCodeParse) Parse() ParseErrorList {
return d.errors
}
logrus.Errorf("svn checkout or update error,%s", err.Error())
d.errappend(ErrorAndSolve(FatalError, fmt.Sprintf("获取代码失败"), "请确认仓库能否正常访问,或查看社区文档"))
d.errappend(ErrorAndSolve(FatalError, "获取代码失败"+err.Error(), "请确认仓库能否正常访问,或查看社区文档"))
return d.errors
}
//get branchs
d.branchs = rs.Branchs
return nil
}
logrus.Debugf("start get service code by %s server type", csi.ServerType)
ossFunc := func() ParseErrorList {
g := got.NewWithContext(context.Background())
util.CheckAndCreateDir(buildInfo.GetCodeHome())
fileName := path.Join(buildInfo.GetCodeHome(), path.Base(csi.RepositoryURL))
if err := g.Do(&got.Download{
URL: csi.RepositoryURL,
Dest: fileName,
Header: []got.GotHeader{
{Key: "Authorization", Value: "Basic " + basicAuth(csi.User, csi.Password)},
},
}); err != nil {
logrus.Errorf("download package file from oss failure %s", err.Error())
d.errappend(ErrorAndSolve(FatalError, "文件下载失败:"+err.Error(), "请确认该文件可以被正常下载"))
return d.errors
}
fi, err := os.Stat(fileName)
if err != nil {
d.errappend(ErrorAndSolve(FatalError, "文件下载失败:"+err.Error(), "请确认该文件可以被正常下载"))
return d.errors
}
logrus.Infof("download package file success, size %d MB", fi.Size()/1024/1024)
ext := path.Ext(csi.RepositoryURL)
switch ext {
case ".tar":
if err := util.UnTar(fileName, buildInfo.GetCodeHome(), false); err != nil {
logrus.Errorf("untar package file failure %s", err.Error())
d.errappend(ErrorAndSolve(FatalError, "文件解压失败", "请确认该文件是否为tar规范文件"))
}
case ".tgz", ".tar.gz":
if err := util.UnTar(fileName, buildInfo.GetCodeHome(), true); err != nil {
logrus.Errorf("untar package file failure %s", err.Error())
d.errappend(ErrorAndSolve(FatalError, "文件解压失败", "请确认该文件是否为tgz规范文件"))
}
case ".zip":
if err := util.Unzip(fileName, buildInfo.GetCodeHome()); err != nil {
logrus.Errorf("untar package file failure %s", err.Error())
d.errappend(ErrorAndSolve(FatalError, "文件解压失败", "请确认该文件是否为zip规范文件"))
}
}
logrus.Infof("unpack package file success")
return d.errors
}
logrus.Debugf("start get service %s code by %s server type", csi.ServiceID, csi.ServerType)
//获取代码仓库
switch csi.ServerType {
case "git":
@ -204,6 +256,10 @@ func (d *SourceCodeParse) Parse() ParseErrorList {
if err := svnFunc(); err != nil && err.IsFatalError() {
return err
}
case "oss":
if err := ossFunc(); err != nil && err.IsFatalError() {
return err
}
default:
//default git
logrus.Warningf("do not get void server type,default use git")
@ -211,14 +267,6 @@ func (d *SourceCodeParse) Parse() ParseErrorList {
return err
}
}
// The source code is useless after the test is completed, and needs to be deleted.
defer func() {
if sources.CheckFileExist(buildInfo.GetCodeHome()) {
if err := sources.RemoveDir(buildInfo.GetCodeHome()); err != nil {
logrus.Warningf("remove source code: %v", err)
}
}
}()
//read rainbondfile
rbdfileConfig, err := code.ReadRainbondFile(buildInfo.GetCodeBuildAbsPath())
@ -252,7 +300,7 @@ func (d *SourceCodeParse) Parse() ParseErrorList {
return d.errors
}
//check code Specification
spec := code.CheckCodeSpecification(buildPath, lang)
spec := code.CheckCodeSpecification(buildPath, lang, csi.ServerType)
if spec.Advice != nil {
for k, v := range spec.Advice {
d.errappend(ErrorAndSolve(NegligibleError, k, v))
@ -303,7 +351,7 @@ func (d *SourceCodeParse) Parse() ParseErrorList {
d.errappend(ErrorAndSolve(FatalError, fmt.Sprintf("error listing modules: %v", err), "check source code for multi-modules"))
return d.errors
}
if services != nil && len(services) > 1 {
if len(services) > 1 {
d.isMulti = true
d.services = services
}
@ -579,3 +627,8 @@ func (d *SourceCodeParse) parseDockerfileInfo(dockerfile string) bool {
d.args = []string{}
return true
}
func basicAuth(username, password string) string {
auth := username + ":" + password
return base64.StdEncoding.EncodeToString([]byte(auth))
}

View File

@ -70,3 +70,25 @@ func TestSourceCode(t *testing.T) {
body, _ := json.Marshal(re)
fmt.Printf("%s \n", string(body))
}
func TestOSSCheck(t *testing.T) {
sc := sources.CodeSourceInfo{
ServerType: "oss",
RepositoryURL: "http://8081.gr021644.64q1jlfb.17f4cc.grapps.cn/artifactory/dev/java-war-demo-master.tar",
User: "demo",
Password: "gr123465!",
}
b, _ := json.Marshal(sc)
p := CreateSourceCodeParse(string(b), nil)
err := p.Parse()
if err != nil && err.IsFatalError() {
t.Fatal(err)
}
re := ServiceCheckResult{
CheckStatus: "Success",
ErrorInfos: err,
ServiceInfo: p.GetServiceInfo(),
}
body, _ := json.Marshal(re)
fmt.Printf("%s \n", string(body))
}

View File

@ -32,7 +32,7 @@ import (
"github.com/goodrain/rainbond/util/ingress-nginx/ingress/errors"
"github.com/imdario/mergo"
"github.com/sirupsen/logrus"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
@ -74,7 +74,7 @@ func NewAnnotationExtractor(cfg resolver.Resolver) Extractor {
}
// Extract extracts the annotations from an Ingress
func (e Extractor) Extract(ing *extensions.Ingress) *Ingress {
func (e Extractor) Extract(ing *networkingv1.Ingress) *Ingress {
pia := &Ingress{
ObjectMeta: ing.ObjectMeta,
}

View File

@ -21,10 +21,11 @@ package cookie
import (
"github.com/goodrain/rainbond/gateway/annotations/parser"
"github.com/goodrain/rainbond/gateway/annotations/resolver"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
"strings"
)
// Config -
type Config struct {
Cookie map[string]string `json:"cookie"`
}
@ -33,11 +34,12 @@ type cookie struct {
r resolver.Resolver
}
// NewParser -
func NewParser(r resolver.Resolver) parser.IngressAnnotation {
return cookie{r}
}
func (c cookie) Parse(ing *extensions.Ingress) (interface{}, error) {
func (c cookie) Parse(ing *networkingv1.Ingress) (interface{}, error) {
co, err := parser.GetStringAnnotation("cookie", ing)
if err != nil {
return nil, err

View File

@ -20,18 +20,18 @@ package cookie
import (
api "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
func buildIngress() *extensions.Ingress {
func buildIngress() *networkingv1.Ingress {
defaultBackend := extensions.IngressBackend{
ServiceName: "default-backend",
ServicePort: intstr.FromInt(80),
}
return &extensions.Ingress{
return &networkingv1.Ingress{
ObjectMeta: meta_v1.ObjectMeta{
Name: "foo",
Namespace: api.NamespaceDefault,

View File

@ -21,10 +21,11 @@ package header
import (
"github.com/goodrain/rainbond/gateway/annotations/parser"
"github.com/goodrain/rainbond/gateway/annotations/resolver"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
"strings"
)
// Config -
type Config struct {
Header map[string]string `json:"header"`
}
@ -33,11 +34,12 @@ type header struct {
r resolver.Resolver
}
// NewParser -
func NewParser(r resolver.Resolver) parser.IngressAnnotation {
return header{r}
}
func (h header) Parse(ing *extensions.Ingress) (interface{}, error) {
func (h header) Parse(ing *networkingv1.Ingress) (interface{}, error) {
hr, err := parser.GetStringAnnotation("header", ing)
if err != nil {
return nil, err

View File

@ -20,18 +20,18 @@ package header
import (
api "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
func buildIngress() *extensions.Ingress {
func buildIngress() *networkingv1.Ingress {
defaultBackend := extensions.IngressBackend{
ServiceName: "default-backend",
ServicePort: intstr.FromInt(80),
}
return &extensions.Ingress{
return &networkingv1.Ingress{
ObjectMeta: meta_v1.ObjectMeta{
Name: "foo",
Namespace: api.NamespaceDefault,

View File

@ -22,9 +22,10 @@ import (
"fmt"
"github.com/goodrain/rainbond/gateway/annotations/parser"
"github.com/goodrain/rainbond/gateway/annotations/resolver"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
)
// Config -
type Config struct {
L4Enable bool
L4Host string
@ -35,11 +36,12 @@ type l4 struct {
r resolver.Resolver
}
// NewParser -
func NewParser(r resolver.Resolver) parser.IngressAnnotation {
return l4{r}
}
func (l l4) Parse(ing *extensions.Ingress) (interface{}, error) {
func (l l4) Parse(ing *networkingv1.Ingress) (interface{}, error) {
l4Enable, _ := parser.GetBoolAnnotation("l4-enable", ing)
l4Host, _ := parser.GetStringAnnotation("l4-host", ing)
if l4Host == "" {

View File

@ -20,18 +20,18 @@ package l4
import (
api "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
func buildIngress() *extensions.Ingress {
func buildIngress() *networkingv1.Ingress {
defaultBackend := extensions.IngressBackend{
ServiceName: "default-backend",
ServicePort: intstr.FromInt(80),
}
return &extensions.Ingress{
return &networkingv1.Ingress{
ObjectMeta: meta_v1.ObjectMeta{
Name: "foo",
Namespace: api.NamespaceDefault,

View File

@ -21,7 +21,7 @@ package lbtype
import (
"github.com/goodrain/rainbond/gateway/annotations/parser"
"github.com/goodrain/rainbond/gateway/annotations/resolver"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
)
type lbtype struct {
@ -36,6 +36,6 @@ func NewParser(r resolver.Resolver) parser.IngressAnnotation {
// Parse parses the annotations contained in the ingress rule
// used to indicate if the location/s contains a fragment of
// configuration to be included inside the paths of the rules
func (a lbtype) Parse(ing *extensions.Ingress) (interface{}, error) {
func (a lbtype) Parse(ing *networkingv1.Ingress) (interface{}, error) {
return parser.GetStringAnnotation("lb-type", ing)
}

View File

@ -22,8 +22,7 @@ import (
"strings"
"github.com/goodrain/rainbond/util/ingress-nginx/ingress/errors"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
)
var (
@ -33,7 +32,7 @@ var (
// IngressAnnotation has a method to parse annotations located in Ingress
type IngressAnnotation interface {
Parse(ing *extensions.Ingress) (interface{}, error)
Parse(ing *networkingv1.Ingress) (interface{}, error)
}
type ingAnnotations map[string]string
@ -70,7 +69,7 @@ func (a ingAnnotations) parseInt(name string) (int, error) {
return 0, errors.ErrMissingAnnotations
}
func checkAnnotation(name string, ing *extensions.Ingress) error {
func checkAnnotation(name string, ing *networkingv1.Ingress) error {
if ing == nil || len(ing.GetAnnotations()) == 0 {
return errors.ErrMissingAnnotations
}
@ -82,7 +81,7 @@ func checkAnnotation(name string, ing *extensions.Ingress) error {
}
// GetBoolAnnotation extracts a boolean from an Ingress annotation
func GetBoolAnnotation(name string, ing *extensions.Ingress) (bool, error) {
func GetBoolAnnotation(name string, ing *networkingv1.Ingress) (bool, error) {
v := GetAnnotationWithPrefix(name)
err := checkAnnotation(v, ing)
if err != nil {
@ -92,7 +91,7 @@ func GetBoolAnnotation(name string, ing *extensions.Ingress) (bool, error) {
}
// GetStringAnnotation extracts a string from an Ingress annotation
func GetStringAnnotation(name string, ing *extensions.Ingress) (string, error) {
func GetStringAnnotation(name string, ing *networkingv1.Ingress) (string, error) {
v := GetAnnotationWithPrefix(name)
err := checkAnnotation(v, ing)
if err != nil {
@ -102,7 +101,7 @@ func GetStringAnnotation(name string, ing *extensions.Ingress) (string, error) {
}
// GetIntAnnotation extracts an int from an Ingress annotation
func GetIntAnnotation(name string, ing *extensions.Ingress) (int, error) {
func GetIntAnnotation(name string, ing *networkingv1.Ingress) (int, error) {
v := GetAnnotationWithPrefix(name)
err := checkAnnotation(v, ing)
if err != nil {
@ -113,7 +112,7 @@ func GetIntAnnotation(name string, ing *extensions.Ingress) (int, error) {
// GetStringAnnotationWithPrefix extracts an string from an Ingress annotation
// based on the annotation prefix
func GetStringAnnotationWithPrefix(prefix string, ing *extensions.Ingress) (map[string]string, error) {
func GetStringAnnotationWithPrefix(prefix string, ing *networkingv1.Ingress) (map[string]string, error) {
v := GetAnnotationWithPrefix(prefix)
err := checkAnnotation(v, ing)
if err != nil {

View File

@ -20,12 +20,12 @@ import (
"testing"
api "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func buildIngress() *extensions.Ingress {
return &extensions.Ingress{
func buildIngress() *networkingv1.Ingress {
return &networkingv1.Ingress{
ObjectMeta: meta_v1.ObjectMeta{
Name: "foo",
Namespace: api.NamespaceDefault,

View File

@ -26,7 +26,7 @@ import (
"github.com/goodrain/rainbond/gateway/controller/config"
"github.com/sirupsen/logrus"
"golang.org/x/net/http/httpguts"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
)
// Config returns the proxy timeout to use in the upstream server/s
@ -191,7 +191,7 @@ func NewParser(r resolver.Resolver) parser.IngressAnnotation {
// ParseAnnotations parses the annotations contained in the ingress
// rule used to configure upstream check parameters
func (a proxy) Parse(ing *extensions.Ingress) (interface{}, error) {
func (a proxy) Parse(ing *networkingv1.Ingress) (interface{}, error) {
defBackend := a.r.GetDefaultBackend()
config := &Config{}

View File

@ -20,7 +20,7 @@ import (
"testing"
api "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
@ -29,13 +29,13 @@ import (
"github.com/goodrain/rainbond/gateway/defaults"
)
func buildIngress() *extensions.Ingress {
func buildIngress() *networkingv1.Ingress {
defaultBackend := extensions.IngressBackend{
ServiceName: "default-backend",
ServicePort: intstr.FromInt(80),
}
return &extensions.Ingress{
return &networkingv1.Ingress{
ObjectMeta: meta_v1.ObjectMeta{
Name: "foo",
Namespace: api.NamespaceDefault,

View File

@ -22,7 +22,7 @@ import (
"github.com/goodrain/rainbond/gateway/annotations/parser"
"github.com/goodrain/rainbond/gateway/annotations/resolver"
"github.com/sirupsen/logrus"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
)
// Config describes the per location redirect config
@ -85,7 +85,7 @@ func NewParser(r resolver.Resolver) parser.IngressAnnotation {
// ParseAnnotations parses the annotations contained in the ingress
// rule used to rewrite the defined paths
func (a rewrite) Parse(ing *extensions.Ingress) (interface{}, error) {
func (a rewrite) Parse(ing *networkingv1.Ingress) (interface{}, error) {
var err error
config := &Config{}

View File

@ -23,7 +23,7 @@ import (
"testing"
api "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
@ -32,13 +32,13 @@ const (
defRoute = "/demo"
)
func buildIngress() *extensions.Ingress {
func buildIngress() *networkingv1.Ingress {
defaultBackend := extensions.IngressBackend{
ServiceName: "default-backend",
ServicePort: intstr.FromInt(80),
}
return &extensions.Ingress{
return &networkingv1.Ingress{
ObjectMeta: meta_v1.ObjectMeta{
Name: "foo",
Namespace: api.NamespaceDefault,

View File

@ -19,7 +19,7 @@ package upstreamhashby
import (
"github.com/goodrain/rainbond/gateway/annotations/parser"
"github.com/goodrain/rainbond/gateway/annotations/resolver"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
)
type upstreamhashby struct {
@ -34,6 +34,6 @@ func NewParser(r resolver.Resolver) parser.IngressAnnotation {
// Parse parses the annotations contained in the ingress rule
// used to indicate if the location/s contains a fragment of
// configuration to be included inside the paths of the rules
func (a upstreamhashby) Parse(ing *extensions.Ingress) (interface{}, error) {
func (a upstreamhashby) Parse(ing *networkingv1.Ingress) (interface{}, error) {
return parser.GetStringAnnotation("upstream-hash-by", ing)
}

View File

@ -22,7 +22,7 @@ import (
"github.com/goodrain/rainbond/gateway/annotations/parser"
"github.com/goodrain/rainbond/gateway/annotations/resolver"
"github.com/sirupsen/logrus"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
"strconv"
)
@ -40,7 +40,7 @@ func NewParser(r resolver.Resolver) parser.IngressAnnotation {
return weight{r}
}
func (c weight) Parse(ing *extensions.Ingress) (interface{}, error) {
func (c weight) Parse(ing *networkingv1.Ingress) (interface{}, error) {
wstr, err := parser.GetStringAnnotation("weight", ing)
var w int
if err != nil || wstr == "" {

View File

@ -22,14 +22,14 @@ import (
"fmt"
"github.com/goodrain/rainbond/util/ingress-nginx/k8s"
"k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
)
type secretIngressMap struct {
v map[string][]string
}
func (m *secretIngressMap) update(ing *v1beta1.Ingress) {
func (m *secretIngressMap) update(ing *networkingv1.Ingress) {
ingKey := k8s.MetaNamespaceKey(ing)
for _, tls := range ing.Spec.TLS {
secretKey := fmt.Sprintf("%s/%s", ing.Namespace, tls.SecretName)

View File

@ -31,13 +31,12 @@ import (
"strings"
"sync"
"github.com/goodrain/rainbond/gateway/cluster"
"github.com/eapache/channels"
"github.com/goodrain/rainbond/cmd/gateway/option"
"github.com/goodrain/rainbond/gateway/annotations"
"github.com/goodrain/rainbond/gateway/annotations/l4"
"github.com/goodrain/rainbond/gateway/annotations/rewrite"
"github.com/goodrain/rainbond/gateway/cluster"
"github.com/goodrain/rainbond/gateway/controller/config"
"github.com/goodrain/rainbond/gateway/defaults"
"github.com/goodrain/rainbond/gateway/util"
@ -47,8 +46,7 @@ import (
ik8s "github.com/goodrain/rainbond/util/ingress-nginx/k8s"
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
@ -89,7 +87,7 @@ type Storer interface {
// list virtual service
ListVirtualService() ([]*v1.VirtualService, []*v1.VirtualService)
ListIngresses() []*extensions.Ingress
ListIngresses() []*networkingv1.Ingress
GetIngressAnnotations(key string) (*annotations.Ingress, error)
@ -177,7 +175,7 @@ func New(client kubernetes.Interface,
options.LabelSelector = "creator=Rainbond"
})
store.informers.Ingress = store.sharedInformer.Extensions().V1beta1().Ingresses().Informer()
store.informers.Ingress = store.sharedInformer.Networking().V1().Ingresses().Informer()
store.listers.Ingress.Store = store.informers.Ingress.GetStore()
store.informers.Service = store.sharedInformer.Core().V1().Services().Informer()
@ -191,7 +189,7 @@ func New(client kubernetes.Interface,
ingEventHandler := cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
ing := obj.(*extensions.Ingress)
ing := obj.(*networkingv1.Ingress)
// updating annotations information for ingress
store.extractAnnotations(ing)
@ -212,8 +210,8 @@ func New(client kubernetes.Interface,
}
},
UpdateFunc: func(old, cur interface{}) {
oldIng := old.(*extensions.Ingress)
curIng := cur.(*extensions.Ingress)
oldIng := old.(*networkingv1.Ingress)
curIng := cur.(*networkingv1.Ingress)
// ignore the same secret as the old one
if oldIng.ResourceVersion == curIng.ResourceVersion || reflect.DeepEqual(oldIng, curIng) {
return
@ -344,7 +342,7 @@ func New(client kubernetes.Interface,
}
// checkIngress checks whether the given ing is valid.
func (s *k8sStore) checkIngress(ing *extensions.Ingress) bool {
func (s *k8sStore) checkIngress(ing *networkingv1.Ingress) bool {
i, err := l4.NewParser(s).Parse(ing)
if err != nil {
logrus.Warningf("Uxpected error with ingress: %v", err)
@ -367,7 +365,7 @@ func (s *k8sStore) checkIngress(ing *extensions.Ingress) bool {
// extractAnnotations parses ingress annotations converting the value of the
// annotation to a go struct and also information about the referenced secrets
func (s *k8sStore) extractAnnotations(ing *extensions.Ingress) {
func (s *k8sStore) extractAnnotations(ing *networkingv1.Ingress) {
key := ik8s.MetaNamespaceKey(ing)
logrus.Debugf("updating annotations information for ingress %v", key)
@ -466,7 +464,7 @@ func (s *k8sStore) ListVirtualService() (l7vs []*v1.VirtualService, l4vs []*v1.V
// ServerName-LocationPath -> location
srvLocMap := make(map[string]*v1.Location)
for _, item := range s.listers.Ingress.List() {
ing := item.(*extensions.Ingress)
ing := item.(*networkingv1.Ingress)
if !s.ingressIsValid(ing) {
continue
}
@ -493,8 +491,8 @@ func (s *k8sStore) ListVirtualService() (l7vs []*v1.VirtualService, l4vs []*v1.V
continue
}
}
svcKey := fmt.Sprintf("%v/%v", ing.Namespace, ing.Spec.Backend.ServiceName)
protocol := s.GetServiceProtocol(svcKey, ing.Spec.Backend.ServicePort.IntVal)
svcKey := fmt.Sprintf("%v/%v", ing.Namespace, ing.Spec.DefaultBackend.Service.Name)
protocol := s.GetServiceProtocol(svcKey, ing.Spec.DefaultBackend.Service.Port.Number)
listening := fmt.Sprintf("%s:%v", host, anns.L4.L4Port)
if string(protocol) == string(v1.ProtocolUDP) {
listening = fmt.Sprintf("%s %s", listening, "udp")
@ -524,11 +522,11 @@ func (s *k8sStore) ListVirtualService() (l7vs []*v1.VirtualService, l4vs []*v1.V
}
vs.Namespace = anns.Namespace
vs.ServiceID = anns.Labels["service_id"]
l4PoolMap[ing.Spec.Backend.ServiceName] = struct{}{}
l4PoolMap[ing.Spec.DefaultBackend.Service.Name] = struct{}{}
l4vsMap[listening] = vs
l4vs = append(l4vs, vs)
backend := backend{name: backendName, weight: anns.Weight.Weight}
l4PoolBackendMap[ing.Spec.Backend.ServiceName] = append(l4PoolBackendMap[ing.Spec.Backend.ServiceName], backend)
l4PoolBackendMap[ing.Spec.DefaultBackend.Service.Name] = append(l4PoolBackendMap[ing.Spec.DefaultBackend.Service.Name], backend)
// endregion
} else {
// region l7
@ -593,7 +591,7 @@ func (s *k8sStore) ListVirtualService() (l7vs []*v1.VirtualService, l4vs []*v1.V
for _, path := range rule.IngressRuleValue.HTTP.Paths {
locKey := fmt.Sprintf("%s_%s", virSrvName, path.Path)
location := srvLocMap[locKey]
l7PoolMap[path.Backend.ServiceName] = struct{}{}
l7PoolMap[path.Backend.Service.Name] = struct{}{}
// if location do not exists, then creates a new one
if location == nil {
location = &v1.Location{
@ -631,7 +629,7 @@ func (s *k8sStore) ListVirtualService() (l7vs []*v1.VirtualService, l4vs []*v1.V
if anns.UpstreamHashBy != "" {
backend.hashBy = anns.UpstreamHashBy
}
l7PoolBackendMap[path.Backend.ServiceName] = append(l7PoolBackendMap[path.Backend.ServiceName], backend)
l7PoolBackendMap[path.Backend.Service.Name] = append(l7PoolBackendMap[path.Backend.Service.Name], backend)
}
}
// endregion
@ -639,7 +637,7 @@ func (s *k8sStore) ListVirtualService() (l7vs []*v1.VirtualService, l4vs []*v1.V
}
for _, item := range s.listers.Ingress.List() {
ing := item.(*extensions.Ingress)
ing := item.(*networkingv1.Ingress)
if !s.ingressIsValid(ing) {
continue
}
@ -701,15 +699,15 @@ func (s *k8sStore) ListVirtualService() (l7vs []*v1.VirtualService, l4vs []*v1.V
}
// ingressIsValid checks if the specified ingress is valid
func (s *k8sStore) ingressIsValid(ing *extensions.Ingress) bool {
func (s *k8sStore) ingressIsValid(ing *networkingv1.Ingress) bool {
var endpointKey string
if ing.Spec.Backend != nil { // stream
endpointKey = fmt.Sprintf("%s/%s", ing.Namespace, ing.Spec.Backend.ServiceName)
if ing.Spec.DefaultBackend != nil { // stream
endpointKey = fmt.Sprintf("%s/%s", ing.Namespace, ing.Spec.DefaultBackend.Service.Name)
} else { // http
Loop:
for _, rule := range ing.Spec.Rules {
for _, path := range rule.IngressRuleValue.HTTP.Paths {
endpointKey = fmt.Sprintf("%s/%s", ing.Namespace, path.Backend.ServiceName)
endpointKey = fmt.Sprintf("%s/%s", ing.Namespace, path.Backend.Service.Name)
if endpointKey != "" {
break Loop
}
@ -752,16 +750,16 @@ func hasReadyAddresses(endpoints *corev1.Endpoints) bool {
}
// GetIngress returns the Ingress matching key.
func (s *k8sStore) GetIngress(key string) (*extensions.Ingress, error) {
func (s *k8sStore) GetIngress(key string) (*networkingv1.Ingress, error) {
return s.listers.Ingress.ByKey(key)
}
// ListIngresses returns the list of Ingresses
func (s *k8sStore) ListIngresses() []*extensions.Ingress {
func (s *k8sStore) ListIngresses() []*networkingv1.Ingress {
// filter ingress rules
var ingresses []*extensions.Ingress
var ingresses []*networkingv1.Ingress
for _, item := range s.listers.Ingress.List() {
ing := item.(*extensions.Ingress)
ing := item.(*networkingv1.Ingress)
ingresses = append(ingresses, ing)
}
@ -803,7 +801,7 @@ func (s *k8sStore) Run(stopCh chan struct{}) {
// syncSecrets synchronizes data from all Secrets referenced by the given
// Ingress with the local store and file system.
func (s *k8sStore) syncSecrets(ing *extensions.Ingress) {
func (s *k8sStore) syncSecrets(ing *networkingv1.Ingress) {
key := ik8s.MetaNamespaceKey(ing)
for _, secrKey := range s.secretIngressMap.getSecretKeys(key) {
s.syncSecret(secrKey)
@ -895,7 +893,7 @@ func (s *k8sStore) loopUpdateIngress() {
for ipevent := range s.node.IPManager().NeedUpdateGatewayPolicy() {
ingress := s.listers.Ingress.List()
for i := range ingress {
curIng, ok := ingress[i].(*v1beta1.Ingress)
curIng, ok := ingress[i].(*networkingv1.Ingress)
if ok && curIng != nil && s.annotations.Extract(curIng).L4.L4Host == ipevent.IP.String() {
s.extractAnnotations(curIng)
s.secretIngressMap.update(curIng)

View File

@ -7,7 +7,7 @@ import (
"github.com/goodrain/rainbond/gateway/annotations/parser"
api "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
@ -60,8 +60,8 @@ func TestRbdStore_checkIngress(t *testing.T) {
}
}
func buildIngress() *extensions.Ingress {
return &extensions.Ingress{
func buildIngress() *networkingv1.Ingress {
return &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "foobar",
Namespace: api.NamespaceDefault,

View File

@ -25,7 +25,7 @@ import (
"github.com/goodrain/rainbond/gateway/controller"
corev1 "k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
api_meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@ -126,23 +126,27 @@ func TestHttpDefault(t *testing.T) {
_ = ensureService(service, clientSet, t)
time.Sleep(3 * time.Second)
ingress := &extensions.Ingress{
ingress := &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "default-ing",
Namespace: ns.Name,
},
Spec: extensions.IngressSpec{
Rules: []extensions.IngressRule{
Spec: networkingv1.IngressSpec{
Rules: []networkingv1.IngressRule{
{
Host: "www.http-router.com",
IngressRuleValue: extensions.IngressRuleValue{
HTTP: &extensions.HTTPIngressRuleValue{
Paths: []extensions.HTTPIngressPath{
IngressRuleValue: networkingv1.IngressRuleValue{
HTTP: &networkingv1.HTTPIngressRuleValue{
Paths: []networkingv1.HTTPIngressPath{
{
Path: "/http-router",
Backend: extensions.IngressBackend{
ServiceName: "default-svc",
ServicePort: intstr.FromInt(80),
Backend: networkingv1.IngressBackend{
Service: &networkingv1.IngressServiceBackend{
Name: "default-svc",
Port: networkingv1.ServiceBackendPort{
Number: 80,
},
},
},
},
},
@ -229,7 +233,7 @@ func TestHttpCookie(t *testing.T) {
time.Sleep(3 * time.Second)
ingress := &extensions.Ingress{
ingress := &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "router-cookie-ing",
Namespace: ns.Name,
@ -237,18 +241,22 @@ func TestHttpCookie(t *testing.T) {
parser.GetAnnotationWithPrefix("cookie"): "ck1:cv1;ck2:cv2;",
},
},
Spec: extensions.IngressSpec{
Rules: []extensions.IngressRule{
Spec: networkingv1.IngressSpec{
Rules: []networkingv1.IngressRule{
{
Host: "www.http-router.com",
IngressRuleValue: extensions.IngressRuleValue{
HTTP: &extensions.HTTPIngressRuleValue{
Paths: []extensions.HTTPIngressPath{
IngressRuleValue: networkingv1.IngressRuleValue{
HTTP: &networkingv1.HTTPIngressRuleValue{
Paths: []networkingv1.HTTPIngressPath{
{
Path: "/http-router",
Backend: extensions.IngressBackend{
ServiceName: "router-cookie-svc",
ServicePort: intstr.FromInt(80),
Backend: networkingv1.IngressBackend{
Service: &networkingv1.IngressServiceBackend{
Name: "router-cookie-svc",
Port: networkingv1.ServiceBackendPort{
Number: 80,
},
},
},
},
},
@ -338,7 +346,7 @@ func TestHttpHeader(t *testing.T) {
time.Sleep(3 * time.Second)
ingress := &extensions.Ingress{
ingress := &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "router-header-ing",
Namespace: ns.Name,
@ -346,18 +354,22 @@ func TestHttpHeader(t *testing.T) {
parser.GetAnnotationWithPrefix("header"): "hk1:hv1;hk2:hv2;",
},
},
Spec: extensions.IngressSpec{
Rules: []extensions.IngressRule{
Spec: networkingv1.IngressSpec{
Rules: []networkingv1.IngressRule{
{
Host: "www.http-router.com",
IngressRuleValue: extensions.IngressRuleValue{
HTTP: &extensions.HTTPIngressRuleValue{
Paths: []extensions.HTTPIngressPath{
IngressRuleValue: networkingv1.IngressRuleValue{
HTTP: &networkingv1.HTTPIngressRuleValue{
Paths: []networkingv1.HTTPIngressPath{
{
Path: "/http-router",
Backend: extensions.IngressBackend{
ServiceName: "router-header-svc",
ServicePort: intstr.FromInt(80),
Backend: networkingv1.IngressBackend{
Service: &networkingv1.IngressServiceBackend{
Name: "router-header-svc",
Port: networkingv1.ServiceBackendPort{
Number: 80,
},
},
},
},
},
@ -459,7 +471,7 @@ func TestHttpUpstreamHashBy(t *testing.T) {
time.Sleep(3 * time.Second)
ingress := &extensions.Ingress{
ingress := &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "upstreamhashby-ing",
Namespace: ns.Name,
@ -467,18 +479,22 @@ func TestHttpUpstreamHashBy(t *testing.T) {
parser.GetAnnotationWithPrefix("upstream-hash-by"): "$request_uri",
},
},
Spec: extensions.IngressSpec{
Rules: []extensions.IngressRule{
Spec: networkingv1.IngressSpec{
Rules: []networkingv1.IngressRule{
{
Host: "www.http-upstreamhashby.com",
IngressRuleValue: extensions.IngressRuleValue{
HTTP: &extensions.HTTPIngressRuleValue{
Paths: []extensions.HTTPIngressPath{
IngressRuleValue: networkingv1.IngressRuleValue{
HTTP: &networkingv1.HTTPIngressRuleValue{
Paths: []networkingv1.HTTPIngressPath{
{
Path: "/",
Backend: extensions.IngressBackend{
ServiceName: "upstreamhashby-svc",
ServicePort: intstr.FromInt(80),
Backend: networkingv1.IngressBackend{
Service: &networkingv1.IngressServiceBackend{
Name: "upstreamhashby-svc",
Port: networkingv1.ServiceBackendPort{
Number: 80,
},
},
},
},
},
@ -555,15 +571,15 @@ func ensureService(service *corev1.Service, clientSet kubernetes.Interface, t *t
}
func ensureIngress(ingress *extensions.Ingress, clientSet kubernetes.Interface, t *testing.T) *extensions.Ingress {
func ensureIngress(ingress *networkingv1.Ingress, clientSet kubernetes.Interface, t *testing.T) *networkingv1.Ingress {
t.Helper()
ing, err := clientSet.ExtensionsV1beta1().Ingresses(ingress.Namespace).Update(context.TODO(), ingress, metav1.UpdateOptions{})
ing, err := clientSet.NetworkingV1().Ingresses(ingress.Namespace).Update(context.TODO(), ingress, metav1.UpdateOptions{})
if err != nil {
if k8sErrors.IsNotFound(err) {
t.Logf("Ingress %v not found, creating", ingress)
ing, err = clientSet.ExtensionsV1beta1().Ingresses(ingress.Namespace).Create(context.TODO(), ingress, metav1.CreateOptions{})
ing, err = clientSet.NetworkingV1().Ingresses(ingress.Namespace).Create(context.TODO(), ingress, metav1.CreateOptions{})
if err != nil {
t.Fatalf("error creating ingress %+v: %v", ingress, err)
}

View File

@ -27,11 +27,10 @@ import (
"github.com/goodrain/rainbond/gateway/controller"
corev1 "k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
api_meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/kubernetes"
)
@ -174,7 +173,7 @@ func TestHttps(t *testing.T) {
Type: corev1.SecretTypeOpaque,
}, clientSet, t)
ingress := &extensions.Ingress{
ingress := &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "https-ing",
Namespace: ns.Name,
@ -182,24 +181,28 @@ func TestHttps(t *testing.T) {
parser.GetAnnotationWithPrefix("force-ssl-redirect"): "true",
},
},
Spec: extensions.IngressSpec{
TLS: []v1beta1.IngressTLS{
Spec: networkingv1.IngressSpec{
TLS: []networkingv1.IngressTLS{
{
Hosts: []string{"www.https.com"},
SecretName: secr.Name,
},
},
Rules: []extensions.IngressRule{
Rules: []networkingv1.IngressRule{
{
Host: "www.https.com",
IngressRuleValue: extensions.IngressRuleValue{
HTTP: &extensions.HTTPIngressRuleValue{
Paths: []extensions.HTTPIngressPath{
IngressRuleValue: networkingv1.IngressRuleValue{
HTTP: &networkingv1.HTTPIngressRuleValue{
Paths: []networkingv1.HTTPIngressPath{
{
Path: "/https",
Backend: extensions.IngressBackend{
ServiceName: "default-svc",
ServicePort: intstr.FromInt(80),
Backend: networkingv1.IngressBackend{
Service: &networkingv1.IngressServiceBackend{
Name: "default-svc",
Port: networkingv1.ServiceBackendPort{
Number: 80,
},
},
},
},
},
@ -276,15 +279,15 @@ func ensureService(service *corev1.Service, clientSet kubernetes.Interface, t *t
}
func ensureIngress(ingress *extensions.Ingress, clientSet kubernetes.Interface, t *testing.T) *extensions.Ingress {
func ensureIngress(ingress *networkingv1.Ingress, clientSet kubernetes.Interface, t *testing.T) *networkingv1.Ingress {
t.Helper()
ing, err := clientSet.ExtensionsV1beta1().Ingresses(ingress.Namespace).Update(context.TODO(), ingress, metav1.UpdateOptions{})
ing, err := clientSet.NetworkingV1().Ingresses(ingress.Namespace).Update(context.TODO(), ingress, metav1.UpdateOptions{})
if err != nil {
if k8sErrors.IsNotFound(err) {
t.Logf("Ingress %v not found, creating", ingress)
ing, err = clientSet.ExtensionsV1beta1().Ingresses(ingress.Namespace).Create(context.TODO(), ingress, metav1.CreateOptions{})
ing, err = clientSet.NetworkingV1().Ingresses(ingress.Namespace).Create(context.TODO(), ingress, metav1.CreateOptions{})
if err != nil {
t.Fatalf("error creating ingress %+v: %v", ingress, err)
}

View File

@ -27,11 +27,10 @@ import (
"github.com/goodrain/rainbond/gateway/controller"
corev1 "k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
api_meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/client-go/kubernetes"
)
@ -108,7 +107,7 @@ func TestTcp(t *testing.T) {
_ = ensureService(service, clientSet, t)
time.Sleep(3 * time.Second)
ingress := &extensions.Ingress{
ingress := &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: "tcp-ing",
Namespace: ns.Name,
@ -118,11 +117,13 @@ func TestTcp(t *testing.T) {
parser.GetAnnotationWithPrefix("l4-port"): "32145",
},
},
Spec: v1beta1.IngressSpec{
Backend: &v1beta1.IngressBackend{
ServiceName: "default-svc",
ServicePort: intstr.IntOrString{
IntVal: 30000,
Spec: networkingv1.IngressSpec{
DefaultBackend: &networkingv1.IngressBackend{
Service: &networkingv1.IngressServiceBackend{
Name: "default-svc",
Port: networkingv1.ServiceBackendPort{
Number: 30000,
},
},
},
},
@ -193,15 +194,15 @@ func ensureService(service *corev1.Service, clientSet kubernetes.Interface, t *t
return svc
}
func ensureIngress(ingress *extensions.Ingress, clientSet kubernetes.Interface, t *testing.T) *extensions.Ingress {
func ensureIngress(ingress *networkingv1.Ingress, clientSet kubernetes.Interface, t *testing.T) *networkingv1.Ingress {
t.Helper()
ing, err := clientSet.ExtensionsV1beta1().Ingresses(ingress.Namespace).Update(context.TODO(), ingress, metav1.UpdateOptions{})
ing, err := clientSet.NetworkingV1().Ingresses(ingress.Namespace).Update(context.TODO(), ingress, metav1.UpdateOptions{})
if err != nil {
if k8sErrors.IsNotFound(err) {
t.Logf("Ingress %v not found, creating", ingress)
ing, err = clientSet.ExtensionsV1beta1().Ingresses(ingress.Namespace).Create(context.TODO(), ingress, metav1.CreateOptions{})
ing, err = clientSet.NetworkingV1().Ingresses(ingress.Namespace).Create(context.TODO(), ingress, metav1.CreateOptions{})
if err != nil {
t.Fatalf("error creating ingress %+v: %v", ingress, err)
}

2
go.mod
View File

@ -58,6 +58,7 @@ require (
github.com/kr/pretty v0.2.1 // indirect
github.com/kr/pty v1.1.8
github.com/mattn/go-runewidth v0.0.6
github.com/melbahja/got v0.5.0
github.com/mitchellh/go-ps v1.0.0
github.com/mitchellh/go-wordwrap v1.0.0
github.com/mitchellh/mapstructure v1.3.3
@ -99,6 +100,7 @@ require (
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20201201144952-b05cb90ed32e // indirect
google.golang.org/grpc v1.33.2
google.golang.org/protobuf v1.25.0
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gopkg.in/src-d/go-git.v4 v4.13.1
gopkg.in/yaml.v2 v2.4.0

20
go.sum
View File

@ -93,12 +93,6 @@ github.com/DATA-DOG/go-sqlmock v1.4.1/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/GLYASAI/rainbond-oam v0.0.0-20210720142412-6faa7418c0ab h1:IvNXJNJhmZeMPbulJ7SMtcR9DduQIj0FyUsS5dcLqAQ=
github.com/GLYASAI/rainbond-oam v0.0.0-20210720142412-6faa7418c0ab/go.mod h1:/dRehR3e1pGexOaIDjA44AHBlVPbb7v+O7GWAVyo740=
github.com/GLYASAI/rainbond-oam v0.0.0-20210720150350-96daaa6aec86 h1:wCxXRbtOrsCjw9+gp8n5t1kTFy9/xsWyuZOPR5zvypY=
github.com/GLYASAI/rainbond-oam v0.0.0-20210720150350-96daaa6aec86/go.mod h1:/dRehR3e1pGexOaIDjA44AHBlVPbb7v+O7GWAVyo740=
github.com/GLYASAI/rainbond-oam v0.0.0-20210721020036-158e1be667dc h1:UMR1n8LoCY79PvroSDDlGfSSomqEgeQAgZ+k8MBgcYk=
github.com/GLYASAI/rainbond-oam v0.0.0-20210721020036-158e1be667dc/go.mod h1:/dRehR3e1pGexOaIDjA44AHBlVPbb7v+O7GWAVyo740=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/KyleBanks/depth v1.2.1/go.mod h1:jzSb9d0L43HxTQfT+oSA1EEp2q+ne2uh6XgeJcm8brE=
github.com/MakeNowJust/heredoc v0.0.0-20170808103936-bb23615498cd h1:sjQovDkwrZp8u+gxLtPgKGjk5hCxuy2hrRejBTA9xFU=
@ -384,6 +378,7 @@ github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815/go.mod h1:WwZ+bS3
github.com/dsnet/compress v0.0.1/go.mod h1:Aw8dCMJ7RioblQeTqt88akK31OvO8Dhf5JflhBbQEHo=
github.com/dsnet/golib v0.0.0-20171103203638-1ea166775780/go.mod h1:Lj+Z9rebOhdfkVLjJ8T6VcRQv3SXugXy999NBtR9aFY=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/eapache/channels v1.1.0 h1:F1taHcn7/F0i8DYqKXJnyhJcVpp2kgFcNePxXtnyu4k=
github.com/eapache/channels v1.1.0/go.mod h1:jMm2qB5Ubtg9zLd+inMZd2/NUvXgzmWXsDaLyQIGfH0=
@ -699,10 +694,6 @@ github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995/go.mod h1:lJgMEyOkY
github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e/go.mod h1:0AA//k/eakGydO4jKRoRL2j92ZKSzTgj9tclaCrvXHk=
github.com/goodrain/gorm-bulk-upsert v1.0.1-0.20210608013724-7e7870d16357 h1:kdSSrpA5yNvgqbfpMlEr8bvQWiLc1Uz9g0vYf3JVT7s=
github.com/goodrain/gorm-bulk-upsert v1.0.1-0.20210608013724-7e7870d16357/go.mod h1:b7/GgeVNbf/SFw4FYIWslxNV5I10C9Mhf/++3jsDk3M=
github.com/goodrain/rainbond-oam v0.0.0-20210206075623-511d0796af43 h1:xhUwEWQKk+maL6CmV5Y6kxKb+jA/RvN6SZcDbNm51FM=
github.com/goodrain/rainbond-oam v0.0.0-20210206075623-511d0796af43/go.mod h1:/dRehR3e1pGexOaIDjA44AHBlVPbb7v+O7GWAVyo740=
github.com/goodrain/rainbond-oam v0.0.0-20210531110322-0fc33198e2d1 h1:XnipcyrdVCxtKYpy7APoaQwXOX4WGwxgZVpy1XvYb/A=
github.com/goodrain/rainbond-oam v0.0.0-20210531110322-0fc33198e2d1/go.mod h1:/dRehR3e1pGexOaIDjA44AHBlVPbb7v+O7GWAVyo740=
github.com/goodrain/rainbond-oam v0.0.0-20210721020036-158e1be667dc h1:hCtxb/Yy4G+wEc2n+yaXx3j4SF/s34zNI8XK5qkHqXk=
github.com/goodrain/rainbond-oam v0.0.0-20210721020036-158e1be667dc/go.mod h1:/dRehR3e1pGexOaIDjA44AHBlVPbb7v+O7GWAVyo740=
github.com/goodrain/rainbond-operator v1.3.1-0.20210401055914-f8fe4bf89a21 h1:iCPI96slvJv88iPc1NJW8zhpkiza0kwB0jtsuZIJLRQ=
@ -1081,6 +1072,8 @@ github.com/mdlayher/netlink v1.1.0 h1:mpdLgm+brq10nI9zM1BpX1kpDbh3NLl3RSnVq6ZSkf
github.com/mdlayher/netlink v1.1.0/go.mod h1:H4WCitaheIsdF9yOYu8CFmCgQthAPIWZmcKp9uZHgmY=
github.com/mdlayher/wifi v0.0.0-20190303161829-b1436901ddee h1:hZDujBrW3ye2xxdKNFYT59D4yCH5Q0zLuNBNtysKtok=
github.com/mdlayher/wifi v0.0.0-20190303161829-b1436901ddee/go.mod h1:Evt/EIne46u9PtQbeTx2NTcqURpr5K4SvKtGmBuDPN8=
github.com/melbahja/got v0.5.0 h1:tFp5WasOUeZ/SiW82G4SS8clb5Q/Pw6IFYvOcLgt/ZY=
github.com/melbahja/got v0.5.0/go.mod h1:z/sG672dxMFNDZtZ9CHBbfuYeTzV0Xqilq6BUEw41oY=
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/mholt/archiver/v3 v3.3.0/go.mod h1:YnQtqsp+94Rwd0D/rk5cnLrxusUBUXg+08Ebtr1Mqao=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
@ -1499,6 +1492,8 @@ github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtX
github.com/urfave/cli v1.22.2 h1:gsqYFH8bb9ekPA12kRo0hfjngWQjkJPlN9R0N78BoUo=
github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli/v2 v2.1.1/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4=
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
github.com/vektah/gqlparser v1.1.2/go.mod h1:1ycwN7Ij5njmMkPPAOaRFY4rET2Enx7IkVv3vaXspKw=
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
@ -1545,6 +1540,11 @@ github.com/zclconf/go-cty v1.8.0/go.mod h1:vVKLxnk3puL4qRAv72AO+W99LUD4da90g3uUA
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8=
github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs=
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
gitlab.com/poldi1405/go-ansi v1.1.0 h1:BrWoD9TivJKjdnQUwiHVzyqAemDiRpDVBCbbNOPoySQ=
gitlab.com/poldi1405/go-ansi v1.1.0/go.mod h1:TLoRttGdPaq5H2qfF7I1cC5Lt2WXtQeIkFurjbUf6OI=
gitlab.com/poldi1405/go-indicators v0.0.0-20200820134929-9b373aa411a5/go.mod h1:jn34qwBiXTHz73wD9neAMeJGCeMijVro+WCqk1RJXL4=
gitlab.com/poldi1405/go-indicators v1.0.0 h1:miZ7CisCvAH6G16OuY6ATtC8QUUjVCYabNgVsRYjJIs=
gitlab.com/poldi1405/go-indicators v1.0.0/go.mod h1:jn34qwBiXTHz73wD9neAMeJGCeMijVro+WCqk1RJXL4=
go.elastic.co/apm v1.5.0/go.mod h1:OdB9sPtM6Vt7oz3VXt7+KR96i9li74qrxBGHTQygFvk=
go.elastic.co/apm/module/apmhttp v1.5.0/go.mod h1:1FbmNuyD3ddauwzgVwFB0fqY6KbZt3JkV187tGCYYhY=
go.elastic.co/apm/module/apmot v1.5.0/go.mod h1:d2KYwhJParTpyw2WnTNy8geNlHKKFX+4oK3YLlsesWE=

View File

@ -527,6 +527,16 @@ func Zip(source, target string) error {
return err
}
func UnTar(archive, target string, zip bool) error {
parameter := "-x"
if zip {
parameter = "-zx"
}
command := []string{"tar", parameter, "-C", target, "-f", archive}
cmd := exec.Command(command[0], command[1:]...)
return cmd.Run()
}
//Unzip archive file to target dir
func Unzip(archive, target string) error {
reader, err := zip.OpenDirectReader(archive)

View File

@ -17,7 +17,7 @@ limitations under the License.
package store
import (
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
"k8s.io/client-go/tools/cache"
)
@ -27,7 +27,7 @@ type IngressLister struct {
}
// ByKey returns the Ingress matching key in the local Ingress store.
func (il IngressLister) ByKey(key string) (*extensions.Ingress, error) {
func (il IngressLister) ByKey(key string) (*networkingv1.Ingress, error) {
i, exists, err := il.GetByKey(key)
if err != nil {
return nil, err
@ -35,5 +35,5 @@ func (il IngressLister) ByKey(key string) (*extensions.Ingress, error) {
if !exists {
return nil, NotExistsError(key)
}
return i.(*extensions.Ingress), nil
return i.(*networkingv1.Ingress), nil
}

View File

@ -2,6 +2,7 @@ package k8s
import (
"encoding/json"
networkingv1 "k8s.io/api/networking/v1"
"net"
"os"
@ -119,3 +120,8 @@ func CreatePatch(o, n, datastruct interface{}) ([]byte, error) {
}
return strategicpatch.CreateTwoWayMergePatch(oldData, newData, datastruct)
}
// IngressPathType -
func IngressPathType(pathType networkingv1.PathType) *networkingv1.PathType {
return &pathType
}

View File

@ -162,7 +162,7 @@ func (s *startController) startOne(app v1.AppService) error {
if ingresses := app.GetIngress(true); ingresses != nil {
for _, ingress := range ingresses {
if len(ingress.ResourceVersion) == 0 {
_, err := s.manager.client.ExtensionsV1beta1().Ingresses(app.TenantID).Create(s.ctx, ingress, metav1.CreateOptions{})
_, err := s.manager.client.NetworkingV1().Ingresses(app.TenantID).Create(s.ctx, ingress, metav1.CreateOptions{})
if err != nil && !errors.IsAlreadyExists(err) {
return fmt.Errorf("create ingress failure:%s", err.Error())
}

View File

@ -23,15 +23,15 @@ import (
"os"
"strconv"
"strings"
"github.com/goodrain/rainbond/util/k8s"
"github.com/goodrain/rainbond/db"
"github.com/goodrain/rainbond/db/model"
"github.com/goodrain/rainbond/event"
"github.com/goodrain/rainbond/gateway/annotations/parser"
v1 "github.com/goodrain/rainbond/worker/appm/types/v1"
"github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)
@ -89,7 +89,6 @@ type AppServiceBuild struct {
appService *v1.AppService
replicationType string
dbmanager db.Manager
logger event.Logger
}
//AppServiceBuilder returns a AppServiceBuild
@ -144,7 +143,7 @@ func (a *AppServiceBuild) Build() (*v1.K8sResources, error) {
}
var services []*corev1.Service
var ingresses []*extensions.Ingress
var ingresses []*networkingv1.Ingress
var secrets []*corev1.Secret
if len(ports) > 0 {
for i := range ports {
@ -194,8 +193,8 @@ func (a *AppServiceBuild) Build() (*v1.K8sResources, error) {
// ApplyRules applies http rules and tcp rules
func (a AppServiceBuild) ApplyRules(serviceID string, containerPort, pluginContainerPort int,
service *corev1.Service) ([]*extensions.Ingress, []*corev1.Secret, error) {
var ingresses []*extensions.Ingress
service *corev1.Service) ([]*networkingv1.Ingress, []*corev1.Secret, error) {
var ingresses []*networkingv1.Ingress
var secrets []*corev1.Secret
httpRules, err := a.dbmanager.HTTPRuleDao().GetHTTPRuleByServiceIDAndContainerPort(serviceID, containerPort)
if err != nil {
@ -203,7 +202,7 @@ func (a AppServiceBuild) ApplyRules(serviceID string, containerPort, pluginConta
}
// create http ingresses
logrus.Debugf("find %d count http rule", len(httpRules))
if httpRules != nil && len(httpRules) > 0 {
if len(httpRules) > 0 {
for _, httpRule := range httpRules {
ing, sec, err := a.applyHTTPRule(httpRule, containerPort, pluginContainerPort, service)
if err != nil {
@ -222,7 +221,7 @@ func (a AppServiceBuild) ApplyRules(serviceID string, containerPort, pluginConta
if err != nil {
logrus.Infof("Can't get TCPRule corresponding to ServiceID(%s): %v", serviceID, err)
}
if tcpRules != nil && len(tcpRules) > 0 {
if len(tcpRules) > 0 {
for _, tcpRule := range tcpRules {
ing, err := a.applyTCPRule(tcpRule, service, a.tenant.UUID)
if err != nil {
@ -239,7 +238,7 @@ func (a AppServiceBuild) ApplyRules(serviceID string, containerPort, pluginConta
// applyTCPRule applies stream rule into ingress
func (a *AppServiceBuild) applyHTTPRule(rule *model.HTTPRule, containerPort, pluginContainerPort int,
service *corev1.Service) (ing *extensions.Ingress, sec *corev1.Secret, err error) {
service *corev1.Service) (ing *networkingv1.Ingress, sec *corev1.Secret, err error) {
// deal with empty path and domain
path := strings.Replace(rule.Path, " ", "", -1)
if path == "" {
@ -251,24 +250,29 @@ func (a *AppServiceBuild) applyHTTPRule(rule *model.HTTPRule, containerPort, plu
}
// create ingress
ing = &extensions.Ingress{
ing = &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: rule.UUID,
Namespace: a.tenant.UUID,
Labels: a.appService.GetCommonLabels(),
},
Spec: extensions.IngressSpec{
Rules: []extensions.IngressRule{
Spec: networkingv1.IngressSpec{
Rules: []networkingv1.IngressRule{
{
Host: domain,
IngressRuleValue: extensions.IngressRuleValue{
HTTP: &extensions.HTTPIngressRuleValue{
Paths: []extensions.HTTPIngressPath{
IngressRuleValue: networkingv1.IngressRuleValue{
HTTP: &networkingv1.HTTPIngressRuleValue{
Paths: []networkingv1.HTTPIngressPath{
{
Path: path,
Backend: extensions.IngressBackend{
ServiceName: service.Name,
ServicePort: intstr.FromInt(pluginContainerPort),
Path: path,
PathType: k8s.IngressPathType(networkingv1.PathTypeExact),
Backend: networkingv1.IngressBackend{
Service: &networkingv1.IngressServiceBackend{
Name: service.Name,
Port: networkingv1.ServiceBackendPort{
Number: int32(pluginContainerPort),
},
},
},
},
},
@ -297,10 +301,10 @@ func (a *AppServiceBuild) applyHTTPRule(rule *model.HTTPRule, containerPort, plu
if rule.CertificateID != "" {
cert, err := a.dbmanager.CertificateDao().GetCertificateByID(rule.CertificateID)
if err != nil {
return nil, nil, fmt.Errorf("Cant not get certificate by id(%s): %v", rule.CertificateID, err)
return nil, nil, fmt.Errorf("cant not get certificate by id(%s): %v", rule.CertificateID, err)
}
if cert == nil || strings.TrimSpace(cert.Certificate) == "" || strings.TrimSpace(cert.PrivateKey) == "" {
return nil, nil, fmt.Errorf("Rule id: %s; certificate not found", rule.UUID)
return nil, nil, fmt.Errorf("rule id: %s; certificate not found", rule.UUID)
}
// create secret
sec = &corev1.Secret{
@ -315,7 +319,7 @@ func (a *AppServiceBuild) applyHTTPRule(rule *model.HTTPRule, containerPort, plu
},
Type: corev1.SecretTypeOpaque,
}
ing.Spec.TLS = []extensions.IngressTLS{
ing.Spec.TLS = []networkingv1.IngressTLS{
{
Hosts: []string{domain},
SecretName: sec.Name,
@ -356,7 +360,7 @@ func (a *AppServiceBuild) applyHTTPRule(rule *model.HTTPRule, containerPort, plu
if err != nil {
return nil, nil, err
}
if configs != nil && len(configs) > 0 {
if len(configs) > 0 {
for _, cfg := range configs {
annos[parser.GetAnnotationWithPrefix(cfg.Key)] = cfg.Value
}
@ -367,18 +371,22 @@ func (a *AppServiceBuild) applyHTTPRule(rule *model.HTTPRule, containerPort, plu
}
// applyTCPRule applies stream rule into ingress
func (a *AppServiceBuild) applyTCPRule(rule *model.TCPRule, service *corev1.Service, namespace string) (ing *extensions.Ingress, err error) {
func (a *AppServiceBuild) applyTCPRule(rule *model.TCPRule, service *corev1.Service, namespace string) (ing *networkingv1.Ingress, err error) {
// create ingress
ing = &extensions.Ingress{
ing = &networkingv1.Ingress{
ObjectMeta: metav1.ObjectMeta{
Name: rule.UUID,
Namespace: namespace,
Labels: a.appService.GetCommonLabels(),
},
Spec: extensions.IngressSpec{
Backend: &extensions.IngressBackend{
ServiceName: service.Name,
ServicePort: intstr.FromInt(int(service.Spec.Ports[0].Port)),
Spec: networkingv1.IngressSpec{
DefaultBackend: &networkingv1.IngressBackend{
Service: &networkingv1.IngressServiceBackend{
Name: service.Name,
Port: networkingv1.ServiceBackendPort{
Number: int32(service.Spec.Ports[0].Port),
},
},
},
},
}
@ -526,8 +534,7 @@ func (a *AppServiceBuild) createOuterService(port *model.TenantServicesPort) *co
servicePort.Name = fmt.Sprintf("%s-%d",
strings.ToLower(string(servicePort.Protocol)), port.ContainerPort)
servicePort.Port = int32(port.ContainerPort)
var portType corev1.ServiceType
portType = corev1.ServiceTypeClusterIP
portType := corev1.ServiceTypeClusterIP
spec := corev1.ServiceSpec{
Ports: []corev1.ServicePort{servicePort},
Type: portType,

View File

@ -31,7 +31,7 @@ import (
"github.com/sirupsen/logrus"
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
corev1 "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
apiequality "k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/api/errors"
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
@ -189,11 +189,11 @@ func persistUpdate(service *corev1.Service, clientSet kubernetes.Interface) erro
return err
}
func ensureIngress(ingress *extensions.Ingress, clientSet kubernetes.Interface) {
_, err := clientSet.ExtensionsV1beta1().Ingresses(ingress.Namespace).Update(context.Background(), ingress, metav1.UpdateOptions{})
func ensureIngress(ingress *networkingv1.Ingress, clientSet kubernetes.Interface) {
_, err := clientSet.NetworkingV1().Ingresses(ingress.Namespace).Update(context.Background(), ingress, metav1.UpdateOptions{})
if err != nil {
if k8sErrors.IsNotFound(err) {
_, err := clientSet.ExtensionsV1beta1().Ingresses(ingress.Namespace).Create(context.Background(), ingress, metav1.CreateOptions{})
_, err := clientSet.NetworkingV1().Ingresses(ingress.Namespace).Create(context.Background(), ingress, metav1.CreateOptions{})
if err != nil && !k8sErrors.IsAlreadyExists(err) {
logrus.Errorf("error creating ingress %+v: %v", ingress, err)
}
@ -297,12 +297,12 @@ func EnsureHPA(new *autoscalingv2.HorizontalPodAutoscaler, clientSet kubernetes.
}
}
// UpgradeIngress is used to update *extensions.Ingress.
// UpgradeIngress is used to update *networkingv1.Ingress.
func UpgradeIngress(clientset kubernetes.Interface,
as *v1.AppService,
old, new []*extensions.Ingress,
old, new []*networkingv1.Ingress,
handleErr func(msg string, err error) error) error {
var oldMap = make(map[string]*extensions.Ingress, len(old))
var oldMap = make(map[string]*networkingv1.Ingress, len(old))
for i, item := range old {
oldMap[item.Name] = old[i]
}
@ -310,7 +310,7 @@ func UpgradeIngress(clientset kubernetes.Interface,
if o, ok := oldMap[n.Name]; ok {
n.UID = o.UID
n.ResourceVersion = o.ResourceVersion
ing, err := clientset.ExtensionsV1beta1().Ingresses(n.Namespace).Update(context.Background(), n, metav1.UpdateOptions{})
ing, err := clientset.NetworkingV1().Ingresses(n.Namespace).Update(context.Background(), n, metav1.UpdateOptions{})
if err != nil {
if err := handleErr(fmt.Sprintf("error updating ingress: %+v: err: %v",
ing, err), err); err != nil {
@ -323,7 +323,7 @@ func UpgradeIngress(clientset kubernetes.Interface,
logrus.Debugf("ServiceID: %s; successfully update ingress: %s", as.ServiceID, ing.Name)
} else {
logrus.Debugf("ingress: %+v", n)
ing, err := clientset.ExtensionsV1beta1().Ingresses(n.Namespace).Create(context.Background(), n, metav1.CreateOptions{})
ing, err := clientset.NetworkingV1().Ingresses(n.Namespace).Create(context.Background(), n, metav1.CreateOptions{})
if err != nil {
if err := handleErr(fmt.Sprintf("error creating ingress: %+v: err: %v",
ing, err), err); err != nil {

View File

@ -24,13 +24,13 @@ import (
appsv1 "k8s.io/client-go/listers/apps/v1"
autoscalingv2 "k8s.io/client-go/listers/autoscaling/v2beta2"
corev1 "k8s.io/client-go/listers/core/v1"
"k8s.io/client-go/listers/extensions/v1beta1"
networkingv1 "k8s.io/client-go/listers/networking/v1"
storagev1 "k8s.io/client-go/listers/storage/v1"
)
//Lister kube-api client cache
type Lister struct {
Ingress v1beta1.IngressLister
Ingress networkingv1.IngressLister
Service corev1.ServiceLister
Secret corev1.SecretLister
StatefulSet appsv1.StatefulSetLister

View File

@ -49,7 +49,7 @@ import (
appsv1 "k8s.io/api/apps/v1"
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
corev1 "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
storagev1 "k8s.io/api/storage/v1"
apiextensions "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
internalclientset "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
@ -222,7 +222,7 @@ func NewStore(
store.listers.ConfigMap = infFactory.Core().V1().ConfigMaps().Lister()
store.informers.Ingress = infFactory.Extensions().V1beta1().Ingresses().Informer()
store.listers.Ingress = infFactory.Extensions().V1beta1().Ingresses().Lister()
store.listers.Ingress = infFactory.Networking().V1().Ingresses().Lister()
store.informers.ReplicaSet = infFactory.Apps().V1().ReplicaSets().Informer()
store.listers.ReplicaSets = infFactory.Apps().V1().ReplicaSets().Lister()
@ -609,7 +609,7 @@ func (a *appRuntimeStore) OnAdd(obj interface{}) {
}
}
}
if ingress, ok := obj.(*extensions.Ingress); ok {
if ingress, ok := obj.(*networkingv1.Ingress); ok {
serviceID := ingress.Labels["service_id"]
version := ingress.Labels["version"]
createrID := ingress.Labels["creater_id"]
@ -722,8 +722,8 @@ func (a *appRuntimeStore) getAppService(serviceID, version, createrID string, cr
}
func (a *appRuntimeStore) OnUpdate(oldObj, newObj interface{}) {
// ingress update maybe change owner component
if ingress, ok := newObj.(*extensions.Ingress); ok {
oldIngress := oldObj.(*extensions.Ingress)
if ingress, ok := newObj.(*networkingv1.Ingress); ok {
oldIngress := oldObj.(*networkingv1.Ingress)
if oldIngress.Labels["service_id"] != ingress.Labels["service_id"] {
logrus.Infof("ingress %s change owner component", oldIngress.Name)
serviceID := oldIngress.Labels["service_id"]
@ -832,7 +832,7 @@ func (a *appRuntimeStore) OnDeletes(objs ...interface{}) {
}
}
}
if ingress, ok := obj.(*extensions.Ingress); ok {
if ingress, ok := obj.(*networkingv1.Ingress); ok {
serviceID := ingress.Labels["service_id"]
version := ingress.Labels["version"]
createrID := ingress.Labels["creater_id"]

View File

@ -24,20 +24,19 @@ import (
"strconv"
"strings"
"github.com/goodrain/rainbond/builder"
"github.com/goodrain/rainbond/db/model"
dbmodel "github.com/goodrain/rainbond/db/model"
"github.com/goodrain/rainbond/event"
monitorv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
"github.com/sirupsen/logrus"
v1 "k8s.io/api/apps/v1"
autoscalingv2 "k8s.io/api/autoscaling/v2beta2"
corev1 "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
storagev1 "k8s.io/api/storage/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"github.com/goodrain/rainbond/builder"
"github.com/goodrain/rainbond/db/model"
"github.com/goodrain/rainbond/event"
)
// EventType type of event
@ -118,6 +117,7 @@ func (a AppServiceBase) GetComponentDefinitionName() string {
return ""
}
// IsCustomComponent -
func (a AppServiceBase) IsCustomComponent() bool {
if strings.HasPrefix(a.ServiceKind.String(), dbmodel.ServiceKindCustom.String()) {
return true
@ -128,10 +128,12 @@ func (a AppServiceBase) IsCustomComponent() bool {
return false
}
// IsThirdComponent -
func (a AppServiceBase) IsThirdComponent() bool {
return a.ServiceKind.String() == dbmodel.ServiceKindThirdParty.String()
}
// SetDiscoveryCfg -
func (a *AppServiceBase) SetDiscoveryCfg(discoveryCfg *dbmodel.ThirdPartySvcDiscoveryCfg) {
a.discoveryCfg = discoveryCfg
}
@ -150,8 +152,8 @@ type AppService struct {
delServices []*corev1.Service
endpoints []*corev1.Endpoints
configMaps []*corev1.ConfigMap
ingresses []*extensions.Ingress
delIngs []*extensions.Ingress // ingresses which need to be deleted
ingresses []*networkingv1.Ingress
delIngs []*networkingv1.Ingress // ingresses which need to be deleted
secrets []*corev1.Secret
delSecrets []*corev1.Secret // secrets which need to be deleted
pods []*corev1.Pod
@ -406,9 +408,9 @@ func (a *AppService) DelEndpoints(ep *corev1.Endpoints) {
}
//GetIngress get ingress
func (a *AppService) GetIngress(canCopy bool) []*extensions.Ingress {
func (a *AppService) GetIngress(canCopy bool) []*networkingv1.Ingress {
if canCopy {
cr := make([]*extensions.Ingress, len(a.ingresses))
cr := make([]*networkingv1.Ingress, len(a.ingresses))
copy(cr, a.ingresses[0:])
return cr
}
@ -416,12 +418,12 @@ func (a *AppService) GetIngress(canCopy bool) []*extensions.Ingress {
}
//GetDelIngs gets delIngs which need to be deleted
func (a *AppService) GetDelIngs() []*extensions.Ingress {
func (a *AppService) GetDelIngs() []*networkingv1.Ingress {
return a.delIngs
}
//SetIngress set kubernetes ingress model
func (a *AppService) SetIngress(d *extensions.Ingress) {
func (a *AppService) SetIngress(d *networkingv1.Ingress) {
if len(a.ingresses) > 0 {
for i, ingress := range a.ingresses {
if ingress.GetName() == d.GetName() {
@ -434,12 +436,12 @@ func (a *AppService) SetIngress(d *extensions.Ingress) {
}
// SetIngresses sets k8s ingress list
func (a *AppService) SetIngresses(i []*extensions.Ingress) {
func (a *AppService) SetIngresses(i []*networkingv1.Ingress) {
a.ingresses = i
}
//DeleteIngress delete kubernetes ingress model
func (a *AppService) DeleteIngress(d *extensions.Ingress) {
func (a *AppService) DeleteIngress(d *networkingv1.Ingress) {
for i, c := range a.ingresses {
if c.GetName() == d.GetName() {
a.ingresses = append(a.ingresses[0:i], a.ingresses[i+1:]...)
@ -838,7 +840,7 @@ func (a *AppService) GetManifests() []*unstructured.Unstructured {
return a.manifests
}
//GetManifests get component custom manifest
//SetManifests get component custom manifest
func (a *AppService) SetManifests(manifests []*unstructured.Unstructured) {
a.manifests = manifests
}
@ -876,7 +878,7 @@ func (a *AppService) String() string {
a.statefulset,
a.deployment,
len(a.pods),
func(ing []*extensions.Ingress) string {
func(ing []*networkingv1.Ingress) string {
result := ""
for _, i := range ing {
result += i.Name + ","
@ -911,7 +913,7 @@ type TenantResource struct {
type K8sResources struct {
Services []*corev1.Service
Secrets []*corev1.Secret
Ingresses []*extensions.Ingress
Ingresses []*networkingv1.Ingress
}
//GetTCPMeshImageName get tcp mesh image name