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:
@@ -35,7 +35,6 @@ import (
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
"github.com/fission/fission/pkg/executor/util"
|
||||
"github.com/fission/fission/pkg/types"
|
||||
"github.com/fission/fission/pkg/utils"
|
||||
)
|
||||
|
||||
@@ -127,7 +126,7 @@ func (deploy *NewDeploy) setupRBACObjs(deployNamespace string, fn *fv1.Function)
|
||||
if err != nil {
|
||||
deploy.logger.Error("error creating fission fetcher service account for function",
|
||||
zap.Error(err),
|
||||
zap.String("service_account_name", types.FissionFetcherSA),
|
||||
zap.String("service_account_name", fv1.FissionFetcherSA),
|
||||
zap.String("service_account_namespace", deployNamespace),
|
||||
zap.String("function_name", fn.ObjectMeta.Name),
|
||||
zap.String("function_namespace", fn.ObjectMeta.Namespace))
|
||||
@@ -135,22 +134,22 @@ func (deploy *NewDeploy) setupRBACObjs(deployNamespace string, fn *fv1.Function)
|
||||
}
|
||||
|
||||
// create a cluster role binding for the fetcher SA, if not already created, granting access to do a get on packages in any ns
|
||||
err = utils.SetupRoleBinding(deploy.logger, deploy.kubernetesClient, types.PackageGetterRB, fn.Spec.Package.PackageRef.Namespace, types.PackageGetterCR, types.ClusterRole, types.FissionFetcherSA, deployNamespace)
|
||||
err = utils.SetupRoleBinding(deploy.logger, deploy.kubernetesClient, fv1.PackageGetterRB, fn.Spec.Package.PackageRef.Namespace, fv1.PackageGetterCR, fv1.ClusterRole, fv1.FissionFetcherSA, deployNamespace)
|
||||
if err != nil {
|
||||
deploy.logger.Error("error creating role binding for function",
|
||||
zap.Error(err),
|
||||
zap.String("role_binding", types.PackageGetterRB),
|
||||
zap.String("role_binding", fv1.PackageGetterRB),
|
||||
zap.String("function_name", fn.ObjectMeta.Name),
|
||||
zap.String("function_namespace", fn.ObjectMeta.Namespace))
|
||||
return err
|
||||
}
|
||||
|
||||
// create rolebinding in function namespace for fetcherSA.envNamespace to be able to get secrets and configmaps
|
||||
err = utils.SetupRoleBinding(deploy.logger, deploy.kubernetesClient, types.SecretConfigMapGetterRB, fn.ObjectMeta.Namespace, types.SecretConfigMapGetterCR, types.ClusterRole, types.FissionFetcherSA, deployNamespace)
|
||||
err = utils.SetupRoleBinding(deploy.logger, deploy.kubernetesClient, fv1.SecretConfigMapGetterRB, fn.ObjectMeta.Namespace, fv1.SecretConfigMapGetterCR, fv1.ClusterRole, fv1.FissionFetcherSA, deployNamespace)
|
||||
if err != nil {
|
||||
deploy.logger.Error("error creating role binding for function",
|
||||
zap.Error(err),
|
||||
zap.String("role_binding", types.SecretConfigMapGetterRB),
|
||||
zap.String("role_binding", fv1.SecretConfigMapGetterRB),
|
||||
zap.String("function_name", fn.ObjectMeta.Name),
|
||||
zap.String("function_namespace", fn.ObjectMeta.Namespace))
|
||||
return err
|
||||
|
||||
@@ -46,7 +46,6 @@ import (
|
||||
"github.com/fission/fission/pkg/executor/reaper"
|
||||
fetcherConfig "github.com/fission/fission/pkg/fetcher/config"
|
||||
"github.com/fission/fission/pkg/throttler"
|
||||
"github.com/fission/fission/pkg/types"
|
||||
"github.com/fission/fission/pkg/utils"
|
||||
)
|
||||
|
||||
@@ -278,7 +277,7 @@ func (deploy *NewDeploy) CleanupOldExecutorObjects() {
|
||||
|
||||
errs := &multierror.Error{}
|
||||
listOpts := metav1.ListOptions{
|
||||
LabelSelector: labels.Set(map[string]string{types.EXECUTOR_TYPE: string(fv1.ExecutorTypeNewdeploy)}).AsSelector().String(),
|
||||
LabelSelector: labels.Set(map[string]string{fv1.EXECUTOR_TYPE: string(fv1.ExecutorTypeNewdeploy)}).AsSelector().String(),
|
||||
}
|
||||
|
||||
err := reaper.CleanupHpa(deploy.logger, deploy.kubernetesClient, deploy.instanceID, listOpts)
|
||||
@@ -744,20 +743,20 @@ func (deploy *NewDeploy) getObjName(fn *fv1.Function) string {
|
||||
|
||||
func (deploy *NewDeploy) getDeployLabels(fnMeta metav1.ObjectMeta, envMeta metav1.ObjectMeta) map[string]string {
|
||||
return map[string]string{
|
||||
types.EXECUTOR_TYPE: string(fv1.ExecutorTypeNewdeploy),
|
||||
types.ENVIRONMENT_NAME: envMeta.Name,
|
||||
types.ENVIRONMENT_NAMESPACE: envMeta.Namespace,
|
||||
types.ENVIRONMENT_UID: string(envMeta.UID),
|
||||
types.FUNCTION_NAME: fnMeta.Name,
|
||||
types.FUNCTION_NAMESPACE: fnMeta.Namespace,
|
||||
types.FUNCTION_UID: string(fnMeta.UID),
|
||||
fv1.EXECUTOR_TYPE: string(fv1.ExecutorTypeNewdeploy),
|
||||
fv1.ENVIRONMENT_NAME: envMeta.Name,
|
||||
fv1.ENVIRONMENT_NAMESPACE: envMeta.Namespace,
|
||||
fv1.ENVIRONMENT_UID: string(envMeta.UID),
|
||||
fv1.FUNCTION_NAME: fnMeta.Name,
|
||||
fv1.FUNCTION_NAMESPACE: fnMeta.Namespace,
|
||||
fv1.FUNCTION_UID: string(fnMeta.UID),
|
||||
}
|
||||
}
|
||||
|
||||
func (deploy *NewDeploy) getDeployAnnotations(fnMeta metav1.ObjectMeta) map[string]string {
|
||||
return map[string]string{
|
||||
types.EXECUTOR_INSTANCEID_LABEL: deploy.instanceID,
|
||||
types.FUNCTION_RESOURCE_VERSION: fnMeta.ResourceVersion,
|
||||
fv1.EXECUTOR_INSTANCEID_LABEL: deploy.instanceID,
|
||||
fv1.FUNCTION_RESOURCE_VERSION: fnMeta.ResourceVersion,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package poolmgr
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/fission/fission/pkg/types"
|
||||
"go.uber.org/zap"
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
kerrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
@@ -74,12 +73,12 @@ func (gpm *GenericPoolManager) makeFuncController(fissionClient *crd.FissionClie
|
||||
// setup rolebinding is tried, if it fails, we dont return. we just log an error and move on, because :
|
||||
// 1. not all functions have secrets and/or configmaps, so things will work without this rolebinding in that case.
|
||||
// 2. on the contrary, when the route is tried, the env fetcher logs will show a 403 forbidden message and same will be relayed to executor.
|
||||
err := utils.SetupRoleBinding(gpm.logger, kubernetesClient, types.SecretConfigMapGetterRB, fn.ObjectMeta.Namespace, types.SecretConfigMapGetterCR, types.ClusterRole, types.FissionFetcherSA, envNs)
|
||||
err := utils.SetupRoleBinding(gpm.logger, kubernetesClient, fv1.SecretConfigMapGetterRB, fn.ObjectMeta.Namespace, fv1.SecretConfigMapGetterCR, fv1.ClusterRole, fv1.FissionFetcherSA, envNs)
|
||||
if err != nil {
|
||||
gpm.logger.Error("error creating rolebinding", zap.Error(err), zap.String("role_binding", types.SecretConfigMapGetterRB))
|
||||
gpm.logger.Error("error creating rolebinding", zap.Error(err), zap.String("role_binding", fv1.SecretConfigMapGetterRB))
|
||||
} else {
|
||||
gpm.logger.Debug("successfully set up rolebinding for fetcher service account for function",
|
||||
zap.String("service_account", types.FissionFetcherSA),
|
||||
zap.String("service_account", fv1.FissionFetcherSA),
|
||||
zap.String("service_account_namepsace", envNs),
|
||||
zap.String("function_name", fn.ObjectMeta.Name),
|
||||
zap.String("function_namespace", fn.ObjectMeta.Namespace))
|
||||
@@ -187,15 +186,15 @@ func (gpm *GenericPoolManager) makeFuncController(fissionClient *crd.FissionClie
|
||||
envNs = newFunc.Spec.Environment.Namespace
|
||||
}
|
||||
|
||||
err := utils.SetupRoleBinding(gpm.logger, kubernetesClient, types.SecretConfigMapGetterRB,
|
||||
newFunc.ObjectMeta.Namespace, types.SecretConfigMapGetterCR, types.ClusterRole,
|
||||
types.FissionFetcherSA, envNs)
|
||||
err := utils.SetupRoleBinding(gpm.logger, kubernetesClient, fv1.SecretConfigMapGetterRB,
|
||||
newFunc.ObjectMeta.Namespace, fv1.SecretConfigMapGetterCR, fv1.ClusterRole,
|
||||
fv1.FissionFetcherSA, envNs)
|
||||
|
||||
if err != nil {
|
||||
gpm.logger.Error("error creating rolebinding", zap.Error(err), zap.String("role_binding", types.SecretConfigMapGetterRB))
|
||||
gpm.logger.Error("error creating rolebinding", zap.Error(err), zap.String("role_binding", fv1.SecretConfigMapGetterRB))
|
||||
} else {
|
||||
gpm.logger.Debug("successfully set up rolebinding for fetcher service account for function",
|
||||
zap.String("service_account", types.FissionFetcherSA),
|
||||
zap.String("service_account", fv1.FissionFetcherSA),
|
||||
zap.String("service_account_namepsace", envNs),
|
||||
zap.String("function_name", newFunc.ObjectMeta.Name),
|
||||
zap.String("function_namespace", newFunc.ObjectMeta.Namespace))
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/dchest/uniuri"
|
||||
"github.com/fission/fission/pkg/types"
|
||||
"github.com/fission/fission/pkg/utils"
|
||||
multierror "github.com/hashicorp/go-multierror"
|
||||
"github.com/pkg/errors"
|
||||
@@ -148,11 +147,11 @@ func MakeGenericPool(
|
||||
|
||||
func (gp *GenericPool) getEnvironmentPoolLabels() map[string]string {
|
||||
return map[string]string{
|
||||
types.EXECUTOR_TYPE: string(fv1.ExecutorTypePoolmgr),
|
||||
types.ENVIRONMENT_NAME: gp.env.ObjectMeta.Name,
|
||||
types.ENVIRONMENT_NAMESPACE: gp.env.ObjectMeta.Namespace,
|
||||
types.ENVIRONMENT_UID: string(gp.env.ObjectMeta.UID),
|
||||
"managed": "true", // this allows us to easily find pods managed by the deployment
|
||||
fv1.EXECUTOR_TYPE: string(fv1.ExecutorTypePoolmgr),
|
||||
fv1.ENVIRONMENT_NAME: gp.env.ObjectMeta.Name,
|
||||
fv1.ENVIRONMENT_NAMESPACE: gp.env.ObjectMeta.Namespace,
|
||||
fv1.ENVIRONMENT_UID: string(gp.env.ObjectMeta.UID),
|
||||
"managed": "true", // this allows us to easily find pods managed by the deployment
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,7 +240,7 @@ func (gp *GenericPool) _choosePod(newLabels map[string]string) (*apiv1.Pod, erro
|
||||
// and make a good scheduling decision.
|
||||
chosenPod := readyPods[rand.Intn(len(readyPods))]
|
||||
|
||||
if gp.env.Spec.AllowedFunctionsPerContainer != types.AllowedFunctionsPerContainerInfinite {
|
||||
if gp.env.Spec.AllowedFunctionsPerContainer != fv1.AllowedFunctionsPerContainerInfinite {
|
||||
// Relabel. If the pod already got picked and
|
||||
// modified, this should fail; in that case just
|
||||
// retry.
|
||||
@@ -265,10 +264,10 @@ func (gp *GenericPool) _choosePod(newLabels map[string]string) (*apiv1.Pod, erro
|
||||
|
||||
func (gp *GenericPool) labelsForFunction(metadata *metav1.ObjectMeta) map[string]string {
|
||||
label := gp.getEnvironmentPoolLabels()
|
||||
label[types.FUNCTION_NAME] = metadata.Name
|
||||
label[types.FUNCTION_UID] = string(metadata.UID)
|
||||
label[types.FUNCTION_NAMESPACE] = metadata.Namespace // function CRD must stay within same namespace of environment CRD
|
||||
label["managed"] = "false" // this allows us to easily find pods not managed by the deployment
|
||||
label[fv1.FUNCTION_NAME] = metadata.Name
|
||||
label[fv1.FUNCTION_UID] = string(metadata.UID)
|
||||
label[fv1.FUNCTION_NAMESPACE] = metadata.Namespace // function CRD must stay within same namespace of environment CRD
|
||||
label["managed"] = "false" // this allows us to easily find pods not managed by the deployment
|
||||
return label
|
||||
|
||||
}
|
||||
@@ -634,7 +633,7 @@ func (gp *GenericPool) getFuncSvc(ctx context.Context, fn *fv1.Function) (*fscac
|
||||
|
||||
// patch svc-host and resource version to the pod annotations for new executor to adopt the pod
|
||||
patch := fmt.Sprintf(`{"metadata":{"annotations":{"%v":"%v","%v":"%v"}}}`,
|
||||
types.ANNOTATION_SVC_HOST, svcHost, types.FUNCTION_RESOURCE_VERSION, fn.ObjectMeta.ResourceVersion)
|
||||
fv1.ANNOTATION_SVC_HOST, svcHost, fv1.FUNCTION_RESOURCE_VERSION, fn.ObjectMeta.ResourceVersion)
|
||||
p, err := gp.kubernetesClient.CoreV1().Pods(pod.Namespace).Patch(pod.Name, k8sTypes.StrategicMergePatchType, []byte(patch))
|
||||
if err != nil {
|
||||
// just log the error since it won't affect the function serving
|
||||
|
||||
@@ -43,7 +43,6 @@ import (
|
||||
"github.com/fission/fission/pkg/executor/fscache"
|
||||
"github.com/fission/fission/pkg/executor/reaper"
|
||||
fetcherConfig "github.com/fission/fission/pkg/fetcher/config"
|
||||
"github.com/fission/fission/pkg/types"
|
||||
"github.com/fission/fission/pkg/utils"
|
||||
)
|
||||
|
||||
@@ -278,7 +277,7 @@ func (gpm *GenericPoolManager) AdoptExistingResources() {
|
||||
}
|
||||
|
||||
l := map[string]string{
|
||||
types.EXECUTOR_TYPE: string(fv1.ExecutorTypePoolmgr),
|
||||
fv1.EXECUTOR_TYPE: string(fv1.ExecutorTypePoolmgr),
|
||||
}
|
||||
|
||||
podList, err := gpm.kubernetesClient.CoreV1().Pods(metav1.NamespaceAll).List(metav1.ListOptions{
|
||||
@@ -303,7 +302,7 @@ func (gpm *GenericPoolManager) AdoptExistingResources() {
|
||||
// avoid too many requests arrive Kubernetes API server at the same time.
|
||||
time.Sleep(time.Duration(rand.Intn(30)) * time.Millisecond)
|
||||
|
||||
patch := fmt.Sprintf(`{"metadata":{"annotations":{"%v":"%v"}}}`, types.EXECUTOR_INSTANCEID_LABEL, gpm.instanceId)
|
||||
patch := fmt.Sprintf(`{"metadata":{"annotations":{"%v":"%v"}}}`, fv1.EXECUTOR_INSTANCEID_LABEL, gpm.instanceId)
|
||||
pod, err = gpm.kubernetesClient.CoreV1().Pods(pod.Namespace).Patch(pod.Name, k8sTypes.StrategicMergePatchType, []byte(patch))
|
||||
if err != nil {
|
||||
// just log the error since it won't affect the function serving
|
||||
@@ -317,13 +316,13 @@ func (gpm *GenericPoolManager) AdoptExistingResources() {
|
||||
return
|
||||
}
|
||||
|
||||
fnName, ok1 := pod.Labels[types.FUNCTION_NAME]
|
||||
fnNS, ok2 := pod.Labels[types.FUNCTION_NAMESPACE]
|
||||
fnUID, ok3 := pod.Labels[types.FUNCTION_UID]
|
||||
fnRV, ok4 := pod.Annotations[types.FUNCTION_RESOURCE_VERSION]
|
||||
envName, ok5 := pod.Labels[types.ENVIRONMENT_NAME]
|
||||
envNS, ok6 := pod.Labels[types.ENVIRONMENT_NAMESPACE]
|
||||
svcHost, ok7 := pod.Annotations[types.ANNOTATION_SVC_HOST]
|
||||
fnName, ok1 := pod.Labels[fv1.FUNCTION_NAME]
|
||||
fnNS, ok2 := pod.Labels[fv1.FUNCTION_NAMESPACE]
|
||||
fnUID, ok3 := pod.Labels[fv1.FUNCTION_UID]
|
||||
fnRV, ok4 := pod.Annotations[fv1.FUNCTION_RESOURCE_VERSION]
|
||||
envName, ok5 := pod.Labels[fv1.ENVIRONMENT_NAME]
|
||||
envNS, ok6 := pod.Labels[fv1.ENVIRONMENT_NAMESPACE]
|
||||
svcHost, ok7 := pod.Annotations[fv1.ANNOTATION_SVC_HOST]
|
||||
env, ok8 := envMap[fmt.Sprintf("%v/%v", envNS, envName)]
|
||||
|
||||
if !(ok1 && ok2 && ok3 && ok4 && ok5 && ok6 && ok7 && ok8) {
|
||||
@@ -382,7 +381,7 @@ func (gpm *GenericPoolManager) CleanupOldExecutorObjects() {
|
||||
|
||||
errs := &multierror.Error{}
|
||||
listOpts := metav1.ListOptions{
|
||||
LabelSelector: labels.Set(map[string]string{types.EXECUTOR_TYPE: string(fv1.ExecutorTypePoolmgr)}).AsSelector().String(),
|
||||
LabelSelector: labels.Set(map[string]string{fv1.EXECUTOR_TYPE: string(fv1.ExecutorTypePoolmgr)}).AsSelector().String(),
|
||||
}
|
||||
|
||||
err := reaper.CleanupDeployments(gpm.logger, gpm.kubernetesClient, gpm.instanceId, listOpts)
|
||||
@@ -412,7 +411,7 @@ func (gpm *GenericPoolManager) service() {
|
||||
if !ok {
|
||||
poolsize := gpm.getEnvPoolsize(req.env)
|
||||
switch req.env.Spec.AllowedFunctionsPerContainer {
|
||||
case types.AllowedFunctionsPerContainerInfinite:
|
||||
case fv1.AllowedFunctionsPerContainerInfinite:
|
||||
poolsize = 1
|
||||
}
|
||||
|
||||
@@ -589,7 +588,7 @@ func (gpm *GenericPoolManager) idleObjectReaper() {
|
||||
zap.String("function", fsvc.Name))
|
||||
}
|
||||
|
||||
if fsvc.Environment.Spec.AllowedFunctionsPerContainer == types.AllowedFunctionsPerContainerInfinite {
|
||||
if fsvc.Environment.Spec.AllowedFunctionsPerContainer == fv1.AllowedFunctionsPerContainerInfinite {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package poolmgr
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/fission/fission/pkg/types"
|
||||
"github.com/fission/fission/pkg/utils"
|
||||
"go.uber.org/zap"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
@@ -53,18 +52,18 @@ func (gpm *GenericPoolManager) makePkgController(fissionClient *crd.FissionClien
|
||||
|
||||
// here, we return if we hit an error during rolebinding setup. this is because this rolebinding is mandatory for
|
||||
// every function's package to be loaded into its env. without that, there's no point to move forward.
|
||||
err := utils.SetupRoleBinding(gpm.logger, kubernetesClient, types.PackageGetterRB, pkg.ObjectMeta.Namespace, types.PackageGetterCR, types.ClusterRole, types.FissionFetcherSA, envNs)
|
||||
err := utils.SetupRoleBinding(gpm.logger, kubernetesClient, fv1.PackageGetterRB, pkg.ObjectMeta.Namespace, fv1.PackageGetterCR, fv1.ClusterRole, fv1.FissionFetcherSA, envNs)
|
||||
if err != nil {
|
||||
gpm.logger.Error("error creating rolebinding 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))
|
||||
return
|
||||
}
|
||||
|
||||
gpm.logger.Debug("successfully set up rolebinding for fetcher service account",
|
||||
zap.String("service_account", types.FissionFetcherSA),
|
||||
zap.String("service_account", fv1.FissionFetcherSA),
|
||||
zap.String("service_account_namespace", envNs),
|
||||
zap.String("package_name", pkg.ObjectMeta.Name),
|
||||
zap.String("package_namespace", pkg.ObjectMeta.Namespace))
|
||||
@@ -87,20 +86,20 @@ func (gpm *GenericPoolManager) makePkgController(fissionClient *crd.FissionClien
|
||||
envNs = newPkg.Spec.Environment.Namespace
|
||||
}
|
||||
|
||||
err := utils.SetupRoleBinding(gpm.logger, kubernetesClient, types.PackageGetterRB,
|
||||
newPkg.ObjectMeta.Namespace, types.PackageGetterCR, types.ClusterRole,
|
||||
types.FissionFetcherSA, envNs)
|
||||
err := utils.SetupRoleBinding(gpm.logger, kubernetesClient, fv1.PackageGetterRB,
|
||||
newPkg.ObjectMeta.Namespace, fv1.PackageGetterCR, fv1.ClusterRole,
|
||||
fv1.FissionFetcherSA, envNs)
|
||||
if err != nil {
|
||||
gpm.logger.Error("error updating rolebinding for package",
|
||||
zap.Error(err),
|
||||
zap.String("role_binding", types.PackageGetterRB),
|
||||
zap.String("role_binding", fv1.PackageGetterRB),
|
||||
zap.String("package_name", newPkg.ObjectMeta.Name),
|
||||
zap.String("package_namespace", newPkg.ObjectMeta.Namespace))
|
||||
return
|
||||
}
|
||||
|
||||
gpm.logger.Debug("successfully updated rolebinding for fetcher service account",
|
||||
zap.String("service_account", types.FissionFetcherSA),
|
||||
zap.String("service_account", fv1.FissionFetcherSA),
|
||||
zap.String("service_account_namespace", envNs),
|
||||
zap.String("package_name", newPkg.ObjectMeta.Name),
|
||||
zap.String("package_namespace", newPkg.ObjectMeta.Namespace))
|
||||
|
||||
@@ -27,7 +27,6 @@ import (
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/fission.io/v1"
|
||||
"github.com/fission/fission/pkg/crd"
|
||||
"github.com/fission/fission/pkg/types"
|
||||
"github.com/fission/fission/pkg/utils"
|
||||
)
|
||||
|
||||
@@ -75,10 +74,10 @@ func CleanupDeployments(logger *zap.Logger, client *kubernetes.Clientset, instan
|
||||
return err
|
||||
}
|
||||
for _, dep := range deploymentList.Items {
|
||||
id, ok := dep.ObjectMeta.Annotations[types.EXECUTOR_INSTANCEID_LABEL]
|
||||
id, ok := dep.ObjectMeta.Annotations[fv1.EXECUTOR_INSTANCEID_LABEL]
|
||||
if !ok {
|
||||
// Backward compatibility with older label name
|
||||
id, ok = dep.ObjectMeta.Labels[types.EXECUTOR_INSTANCEID_LABEL]
|
||||
id, ok = dep.ObjectMeta.Labels[fv1.EXECUTOR_INSTANCEID_LABEL]
|
||||
}
|
||||
if ok && id != instanceId {
|
||||
logger.Info("cleaning up deployment", zap.String("deployment", dep.ObjectMeta.Name))
|
||||
@@ -101,10 +100,10 @@ func CleanupPods(logger *zap.Logger, client *kubernetes.Clientset, instanceId st
|
||||
return err
|
||||
}
|
||||
for _, pod := range podList.Items {
|
||||
id, ok := pod.ObjectMeta.Annotations[types.EXECUTOR_INSTANCEID_LABEL]
|
||||
id, ok := pod.ObjectMeta.Annotations[fv1.EXECUTOR_INSTANCEID_LABEL]
|
||||
if !ok {
|
||||
// Backward compatibility with older label name
|
||||
id, ok = pod.ObjectMeta.Labels[types.EXECUTOR_INSTANCEID_LABEL]
|
||||
id, ok = pod.ObjectMeta.Labels[fv1.EXECUTOR_INSTANCEID_LABEL]
|
||||
}
|
||||
if ok && id != instanceId {
|
||||
logger.Info("cleaning up pod", zap.String("pod", pod.ObjectMeta.Name))
|
||||
@@ -127,10 +126,10 @@ func CleanupServices(logger *zap.Logger, client *kubernetes.Clientset, instanceI
|
||||
return err
|
||||
}
|
||||
for _, svc := range svcList.Items {
|
||||
id, ok := svc.ObjectMeta.Annotations[types.EXECUTOR_INSTANCEID_LABEL]
|
||||
id, ok := svc.ObjectMeta.Annotations[fv1.EXECUTOR_INSTANCEID_LABEL]
|
||||
if !ok {
|
||||
// Backward compatibility with older label name
|
||||
id, ok = svc.ObjectMeta.Labels[types.EXECUTOR_INSTANCEID_LABEL]
|
||||
id, ok = svc.ObjectMeta.Labels[fv1.EXECUTOR_INSTANCEID_LABEL]
|
||||
}
|
||||
if ok && id != instanceId {
|
||||
logger.Info("cleaning up service", zap.String("service", svc.ObjectMeta.Name))
|
||||
@@ -154,10 +153,10 @@ func CleanupHpa(logger *zap.Logger, client *kubernetes.Clientset, instanceId str
|
||||
}
|
||||
|
||||
for _, hpa := range hpaList.Items {
|
||||
id, ok := hpa.ObjectMeta.Annotations[types.EXECUTOR_INSTANCEID_LABEL]
|
||||
id, ok := hpa.ObjectMeta.Annotations[fv1.EXECUTOR_INSTANCEID_LABEL]
|
||||
if !ok {
|
||||
// Backward compatibility with older label name
|
||||
id, ok = hpa.ObjectMeta.Labels[types.EXECUTOR_INSTANCEID_LABEL]
|
||||
id, ok = hpa.ObjectMeta.Labels[fv1.EXECUTOR_INSTANCEID_LABEL]
|
||||
}
|
||||
if ok && id != instanceId {
|
||||
logger.Info("cleaning up HPA", zap.String("hpa", hpa.ObjectMeta.Name))
|
||||
@@ -199,7 +198,7 @@ func CleanupRoleBindings(logger *zap.Logger, client *kubernetes.Clientset, fissi
|
||||
}
|
||||
|
||||
// ignore role-bindings not created by fission
|
||||
if roleBinding.Name != types.PackageGetterRB && roleBinding.Name != types.SecretConfigMapGetterRB {
|
||||
if roleBinding.Name != fv1.PackageGetterRB && roleBinding.Name != fv1.SecretConfigMapGetterRB {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -250,7 +249,7 @@ func CleanupRoleBindings(logger *zap.Logger, client *kubernetes.Clientset, fissi
|
||||
|
||||
// if its a package-getter-rb, we have 2 kinds of SAs and each of them is handled differently
|
||||
// else if its a secret-configmap-rb, we have only one SA which is fission-fetcher
|
||||
if roleBinding.Name == types.PackageGetterRB {
|
||||
if roleBinding.Name == fv1.PackageGetterRB {
|
||||
// check if there is an env obj in saNs
|
||||
envList, err := fissionClient.V1().Environments(saNs).List(meta_v1.ListOptions{})
|
||||
if err != nil {
|
||||
@@ -263,7 +262,7 @@ func CleanupRoleBindings(logger *zap.Logger, client *kubernetes.Clientset, fissi
|
||||
// if there's at least one function in the role-binding namespace with env reference
|
||||
// to the SA's namespace.
|
||||
// if neither, then we can remove this SA from this role-binding
|
||||
if subj.Name == types.FissionBuilderSA {
|
||||
if subj.Name == fv1.FissionBuilderSA {
|
||||
if len(envList.Items) == 0 && !funcEnvReference {
|
||||
saToRemove[utils.MakeSAMapKey(subj.Name, subj.Namespace)] = true
|
||||
}
|
||||
@@ -273,13 +272,13 @@ func CleanupRoleBindings(logger *zap.Logger, client *kubernetes.Clientset, fissi
|
||||
// we also need to check if there's at least one function with executor type New deploy
|
||||
// in the rolebinding's namespace.
|
||||
// if none of them are true, then remove this SA from this role-binding
|
||||
if subj.Name == types.FissionFetcherSA {
|
||||
if subj.Name == fv1.FissionFetcherSA {
|
||||
if len(envList.Items) == 0 && !ndmFunc && !funcEnvReference {
|
||||
// remove SA from rolebinding
|
||||
saToRemove[utils.MakeSAMapKey(subj.Name, subj.Namespace)] = true
|
||||
}
|
||||
}
|
||||
} else if roleBinding.Name == types.SecretConfigMapGetterRB {
|
||||
} else if roleBinding.Name == fv1.SecretConfigMapGetterRB {
|
||||
// if there's not even one function in the role-binding's namespace and there's not even
|
||||
// one function with env reference to the SA's namespace, then remove that SA
|
||||
// from this role-binding
|
||||
|
||||
Reference in New Issue
Block a user