Codebase cleanup & optimization (#1493)
Remove old v1 types that are no longer used and move fetcher structs to fetcher directory.
This commit is contained in:
@@ -19,7 +19,6 @@ package buildermgr
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -27,14 +26,15 @@ import (
|
||||
"github.com/dchest/uniuri"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/zap"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
"github.com/fission/fission/pkg/builder"
|
||||
builderClient "github.com/fission/fission/pkg/builder/client"
|
||||
"github.com/fission/fission/pkg/crd"
|
||||
ferror "github.com/fission/fission/pkg/error"
|
||||
"github.com/fission/fission/pkg/fetcher"
|
||||
fetcherClient "github.com/fission/fission/pkg/fetcher/client"
|
||||
"github.com/fission/fission/pkg/types"
|
||||
)
|
||||
|
||||
// buildPackage helps to build source package into deployment package.
|
||||
@@ -45,7 +45,7 @@ import (
|
||||
// 4. Return upload response and build logs.
|
||||
// *. Return build logs and error if any one of steps above failed.
|
||||
func buildPackage(ctx context.Context, logger *zap.Logger, fissionClient *crd.FissionClient, envBuilderNamespace string,
|
||||
storageSvcUrl string, pkg *fv1.Package) (uploadResp *types.ArchiveUploadResponse, buildLogs string, err error) {
|
||||
storageSvcUrl string, pkg *fv1.Package) (uploadResp *fetcher.ArchiveUploadResponse, buildLogs string, err error) {
|
||||
|
||||
env, err := fissionClient.V1().Environments(pkg.Spec.Environment.Namespace).Get(pkg.Spec.Environment.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
@@ -60,8 +60,8 @@ func buildPackage(ctx context.Context, logger *zap.Logger, fissionClient *crd.Fi
|
||||
fetcherC := fetcherClient.MakeClient(logger, fmt.Sprintf("http://%v:8000", svcName))
|
||||
builderC := builderClient.MakeClient(logger, fmt.Sprintf("http://%v:8001", svcName))
|
||||
|
||||
fetchReq := &types.FunctionFetchRequest{
|
||||
FetchType: types.FETCH_SOURCE,
|
||||
fetchReq := &fetcher.FunctionFetchRequest{
|
||||
FetchType: fv1.FETCH_SOURCE,
|
||||
Package: pkg.ObjectMeta,
|
||||
Filename: srcPkgFilename,
|
||||
KeepArchive: false,
|
||||
@@ -103,7 +103,7 @@ func buildPackage(ctx context.Context, logger *zap.Logger, fissionClient *crd.Fi
|
||||
|
||||
archivePackage := !env.Spec.KeepArchive
|
||||
|
||||
uploadReq := &types.ArchiveUploadRequest{
|
||||
uploadReq := &fetcher.ArchiveUploadRequest{
|
||||
Filename: buildResp.ArtifactFilename,
|
||||
StorageSvcUrl: storageSvcUrl,
|
||||
ArchivePackage: archivePackage,
|
||||
@@ -123,7 +123,7 @@ func buildPackage(ctx context.Context, logger *zap.Logger, fissionClient *crd.Fi
|
||||
|
||||
func updatePackage(logger *zap.Logger, fissionClient *crd.FissionClient,
|
||||
pkg *fv1.Package, status fv1.BuildStatus, buildLogs string,
|
||||
uploadResp *types.ArchiveUploadResponse) (*fv1.Package, error) {
|
||||
uploadResp *fetcher.ArchiveUploadResponse) (*fv1.Package, error) {
|
||||
|
||||
pkg.Status = fv1.PackageStatus{
|
||||
BuildStatus: status,
|
||||
@@ -133,7 +133,7 @@ func updatePackage(logger *zap.Logger, fissionClient *crd.FissionClient,
|
||||
|
||||
if uploadResp != nil {
|
||||
pkg.Spec.Deployment = fv1.Archive{
|
||||
Type: types.ArchiveTypeUrl,
|
||||
Type: fv1.ArchiveTypeUrl,
|
||||
URL: uploadResp.ArchiveDownloadUrl,
|
||||
Checksum: uploadResp.Checksum,
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ import (
|
||||
"github.com/fission/fission/pkg/crd"
|
||||
"github.com/fission/fission/pkg/executor/util"
|
||||
fetcherConfig "github.com/fission/fission/pkg/fetcher/config"
|
||||
"github.com/fission/fission/pkg/types"
|
||||
"github.com/fission/fission/pkg/utils"
|
||||
)
|
||||
|
||||
@@ -346,9 +345,9 @@ func (envw *environmentWatcher) createBuilder(env *fv1.Environment, ns string) (
|
||||
// there should be only one deploy in deployList
|
||||
if len(deployList) == 0 {
|
||||
// create builder SA in this ns, if not already created
|
||||
_, err := utils.SetupSA(envw.kubernetesClient, types.FissionBuilderSA, ns)
|
||||
_, err := utils.SetupSA(envw.kubernetesClient, fv1.FissionBuilderSA, ns)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "error creating %q in ns: %s", types.FissionBuilderSA, ns)
|
||||
return nil, errors.Wrapf(err, "error creating %q in ns: %s", fv1.FissionBuilderSA, ns)
|
||||
}
|
||||
|
||||
deploy, err = envw.createBuilderDeployment(env, ns)
|
||||
|
||||
@@ -32,7 +32,6 @@ import (
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
"github.com/fission/fission/pkg/cache"
|
||||
"github.com/fission/fission/pkg/crd"
|
||||
"github.com/fission/fission/pkg/types"
|
||||
"github.com/fission/fission/pkg/utils"
|
||||
)
|
||||
|
||||
@@ -157,17 +156,17 @@ func (pkgw *packageWatcher) build(buildCache *cache.Cache, srcpkg *fv1.Package)
|
||||
// Add the package getter rolebinding to builder sa
|
||||
// we continue here if role binding was not setup succeesffully. this is because without this, the fetcher wont be able to fetch the source pkg into the container and
|
||||
// the build will fail eventually
|
||||
err := utils.SetupRoleBinding(pkgw.logger, pkgw.k8sClient, types.PackageGetterRB, pkg.ObjectMeta.Namespace, types.PackageGetterCR, types.ClusterRole, types.FissionBuilderSA, builderNs)
|
||||
err := utils.SetupRoleBinding(pkgw.logger, pkgw.k8sClient, fv1.PackageGetterRB, pkg.ObjectMeta.Namespace, fv1.PackageGetterCR, fv1.ClusterRole, fv1.FissionBuilderSA, builderNs)
|
||||
if err != nil {
|
||||
pkgw.logger.Error("error setting up role binding for package",
|
||||
zap.Error(err),
|
||||
zap.String("role_binding", types.PackageGetterRB),
|
||||
zap.String("role_binding", fv1.PackageGetterRB),
|
||||
zap.String("package_name", pkg.ObjectMeta.Name),
|
||||
zap.String("package_namespace", pkg.ObjectMeta.Namespace))
|
||||
continue
|
||||
} else {
|
||||
pkgw.logger.Info("setup rolebinding for sa package",
|
||||
zap.String("sa", fmt.Sprintf("%s.%s", types.FissionBuilderSA, builderNs)),
|
||||
zap.String("sa", fmt.Sprintf("%s.%s", fv1.FissionBuilderSA, builderNs)),
|
||||
zap.String("package", fmt.Sprintf("%s.%s", pkg.ObjectMeta.Name, pkg.ObjectMeta.Namespace)))
|
||||
}
|
||||
|
||||
@@ -175,7 +174,7 @@ func (pkgw *packageWatcher) build(buildCache *cache.Cache, srcpkg *fv1.Package)
|
||||
uploadResp, buildLogs, err := buildPackage(ctx, pkgw.logger, pkgw.fissionClient, builderNs, pkgw.storageSvcUrl, pkg)
|
||||
if err != nil {
|
||||
pkgw.logger.Error("error building package", zap.Error(err), zap.String("package_name", pkg.ObjectMeta.Name))
|
||||
updatePackage(pkgw.logger, pkgw.fissionClient, pkg, types.BuildStatusFailed, buildLogs, nil)
|
||||
updatePackage(pkgw.logger, pkgw.fissionClient, pkg, fv1.BuildStatusFailed, buildLogs, nil)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -210,10 +209,10 @@ func (pkgw *packageWatcher) build(buildCache *cache.Cache, srcpkg *fv1.Package)
|
||||
}
|
||||
|
||||
_, err = updatePackage(pkgw.logger, pkgw.fissionClient, pkg,
|
||||
types.BuildStatusSucceeded, buildLogs, uploadResp)
|
||||
fv1.BuildStatusSucceeded, buildLogs, uploadResp)
|
||||
if err != nil {
|
||||
pkgw.logger.Error("error updating package info", zap.Error(err), zap.String("package_name", pkg.ObjectMeta.Name))
|
||||
updatePackage(pkgw.logger, pkgw.fissionClient, pkg, types.BuildStatusFailed, buildLogs, nil)
|
||||
updatePackage(pkgw.logger, pkgw.fissionClient, pkg, fv1.BuildStatusFailed, buildLogs, nil)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -223,7 +222,7 @@ func (pkgw *packageWatcher) build(buildCache *cache.Cache, srcpkg *fv1.Package)
|
||||
}
|
||||
// build timeout
|
||||
updatePackage(pkgw.logger, pkgw.fissionClient, pkg,
|
||||
types.BuildStatusFailed, "Build timeout due to environment builder not ready", nil)
|
||||
fv1.BuildStatusFailed, "Build timeout due to environment builder not ready", nil)
|
||||
|
||||
pkgw.logger.Error("max retries exceeded in building source package, timeout due to environment builder not ready",
|
||||
zap.String("package", fmt.Sprintf("%s.%s", pkg.ObjectMeta.Name, pkg.ObjectMeta.Namespace)))
|
||||
|
||||
Reference in New Issue
Block a user