List fission resources in specific namespace instead of all namespace (#2604)
This commit is contained in:
@@ -33,6 +33,7 @@ import (
|
|||||||
fv1 "github.com/fission/fission/pkg/apis/core/v1"
|
fv1 "github.com/fission/fission/pkg/apis/core/v1"
|
||||||
"github.com/fission/fission/pkg/crd"
|
"github.com/fission/fission/pkg/crd"
|
||||||
"github.com/fission/fission/pkg/generated/clientset/versioned"
|
"github.com/fission/fission/pkg/generated/clientset/versioned"
|
||||||
|
"github.com/fission/fission/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
@@ -124,9 +125,11 @@ func (client *PreUpgradeTaskClient) VerifyFunctionSpecReferences(ctx context.Con
|
|||||||
|
|
||||||
var err error
|
var err error
|
||||||
var fList *fv1.FunctionList
|
var fList *fv1.FunctionList
|
||||||
|
errs := &multierror.Error{}
|
||||||
|
|
||||||
|
for _, namespace := range utils.GetNamespaces() {
|
||||||
for i := 0; i < maxRetries; i++ {
|
for i := 0; i < maxRetries; i++ {
|
||||||
fList, err = client.fissionClient.CoreV1().Functions(metav1.NamespaceAll).List(ctx, metav1.ListOptions{})
|
fList, err = client.fissionClient.CoreV1().Functions(namespace).List(ctx, metav1.ListOptions{})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -138,8 +141,6 @@ func (client *PreUpgradeTaskClient) VerifyFunctionSpecReferences(ctx context.Con
|
|||||||
zap.Int("max_retries", maxRetries))
|
zap.Int("max_retries", maxRetries))
|
||||||
}
|
}
|
||||||
|
|
||||||
errs := &multierror.Error{}
|
|
||||||
|
|
||||||
// check that all secrets, configmaps, packages are in the same namespace
|
// check that all secrets, configmaps, packages are in the same namespace
|
||||||
for _, fn := range fList.Items {
|
for _, fn := range fList.Items {
|
||||||
secrets := fn.Spec.Secrets
|
secrets := fn.Spec.Secrets
|
||||||
@@ -160,6 +161,7 @@ func (client *PreUpgradeTaskClient) VerifyFunctionSpecReferences(ctx context.Con
|
|||||||
errs = multierror.Append(errs, fmt.Errorf("function : %s.%s cannot reference a package : %s in namespace : %s", fn.ObjectMeta.Name, fn.ObjectMeta.Namespace, fn.Spec.Package.PackageRef.Name, fn.Spec.Package.PackageRef.Namespace))
|
errs = multierror.Append(errs, fmt.Errorf("function : %s.%s cannot reference a package : %s in namespace : %s", fn.ObjectMeta.Name, fn.ObjectMeta.Namespace, fn.Spec.Package.PackageRef.Name, fn.Spec.Package.PackageRef.Namespace))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if errs.ErrorOrNil() != nil {
|
if errs.ErrorOrNil() != nil {
|
||||||
client.logger.Fatal("installation failed",
|
client.logger.Fatal("installation failed",
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ func (pkgw *packageWatcher) build(ctx context.Context, srcpkg *fv1.Package) {
|
|||||||
pkgw.logger.Info("starting package info update", zap.String("package_name", pkg.ObjectMeta.Name))
|
pkgw.logger.Info("starting package info update", zap.String("package_name", pkg.ObjectMeta.Name))
|
||||||
|
|
||||||
fnList, err := pkgw.fissionClient.CoreV1().
|
fnList, err := pkgw.fissionClient.CoreV1().
|
||||||
Functions(metav1.NamespaceAll).List(ctx, metav1.ListOptions{})
|
Functions(pkg.Namespace).List(ctx, metav1.ListOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e := "error getting function list"
|
e := "error getting function list"
|
||||||
pkgw.logger.Error(e, zap.Error(err))
|
pkgw.logger.Error(e, zap.Error(err))
|
||||||
|
|||||||
@@ -269,14 +269,15 @@ func (caaf *Container) RefreshFuncPods(ctx context.Context, logger *zap.Logger,
|
|||||||
|
|
||||||
// AdoptExistingResources attempts to adopt resources for functions in all namespaces.
|
// AdoptExistingResources attempts to adopt resources for functions in all namespaces.
|
||||||
func (caaf *Container) AdoptExistingResources(ctx context.Context) {
|
func (caaf *Container) AdoptExistingResources(ctx context.Context) {
|
||||||
fnList, err := caaf.fissionClient.CoreV1().Functions(metav1.NamespaceAll).List(ctx, metav1.ListOptions{})
|
wg := &sync.WaitGroup{}
|
||||||
|
|
||||||
|
for _, namepsace := range utils.GetNamespaces() {
|
||||||
|
fnList, err := caaf.fissionClient.CoreV1().Functions(namepsace).List(ctx, metav1.ListOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
caaf.logger.Error("error getting function list", zap.Error(err))
|
caaf.logger.Error("error getting function list", zap.Error(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
wg := &sync.WaitGroup{}
|
|
||||||
|
|
||||||
for i := range fnList.Items {
|
for i := range fnList.Items {
|
||||||
fn := &fnList.Items[i]
|
fn := &fnList.Items[i]
|
||||||
if fn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType == fv1.ExecutorTypeContainer {
|
if fn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType == fv1.ExecutorTypeContainer {
|
||||||
@@ -293,6 +294,7 @@ func (caaf *Container) AdoptExistingResources(ctx context.Context) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -290,14 +290,15 @@ func (deploy *NewDeploy) RefreshFuncPods(ctx context.Context, logger *zap.Logger
|
|||||||
|
|
||||||
// AdoptExistingResources attempts to adopt resources for functions in all namespaces.
|
// AdoptExistingResources attempts to adopt resources for functions in all namespaces.
|
||||||
func (deploy *NewDeploy) AdoptExistingResources(ctx context.Context) {
|
func (deploy *NewDeploy) AdoptExistingResources(ctx context.Context) {
|
||||||
fnList, err := deploy.fissionClient.CoreV1().Functions(metav1.NamespaceAll).List(ctx, metav1.ListOptions{})
|
wg := &sync.WaitGroup{}
|
||||||
|
|
||||||
|
for _, namepsace := range utils.GetNamespaces() {
|
||||||
|
fnList, err := deploy.fissionClient.CoreV1().Functions(namepsace).List(ctx, metav1.ListOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
deploy.logger.Error("error getting function list", zap.Error(err))
|
deploy.logger.Error("error getting function list", zap.Error(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
wg := &sync.WaitGroup{}
|
|
||||||
|
|
||||||
for i := range fnList.Items {
|
for i := range fnList.Items {
|
||||||
fn := &fnList.Items[i]
|
fn := &fnList.Items[i]
|
||||||
if fn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType == fv1.ExecutorTypeNewdeploy {
|
if fn.Spec.InvokeStrategy.ExecutionStrategy.ExecutorType == fv1.ExecutorTypeNewdeploy {
|
||||||
@@ -314,6 +315,7 @@ func (deploy *NewDeploy) AdoptExistingResources(ctx context.Context) {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
@@ -349,7 +351,7 @@ func (deploy *NewDeploy) CleanupOldExecutorObjects(ctx context.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (deploy *NewDeploy) getEnvFunctions(ctx context.Context, m *metav1.ObjectMeta) []fv1.Function {
|
func (deploy *NewDeploy) getEnvFunctions(ctx context.Context, m *metav1.ObjectMeta) []fv1.Function {
|
||||||
funcList, err := deploy.fissionClient.CoreV1().Functions(metav1.NamespaceAll).List(ctx, metav1.ListOptions{})
|
funcList, err := deploy.fissionClient.CoreV1().Functions(m.Namespace).List(ctx, metav1.ListOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
deploy.logger.Error("Error getting functions for env", zap.Error(err), zap.Any("environment", m))
|
deploy.logger.Error("Error getting functions for env", zap.Error(err), zap.Any("environment", m))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -289,7 +289,7 @@ func (gpm *GenericPoolManager) RefreshFuncPods(ctx context.Context, logger *zap.
|
|||||||
|
|
||||||
funcLabels := gp.labelsForFunction(&f.ObjectMeta)
|
funcLabels := gp.labelsForFunction(&f.ObjectMeta)
|
||||||
|
|
||||||
podList, err := gpm.kubernetesClient.CoreV1().Pods(metav1.NamespaceAll).List(ctx, metav1.ListOptions{
|
podList, err := gpm.kubernetesClient.CoreV1().Pods(f.Spec.Environment.Namespace).List(ctx, metav1.ListOptions{
|
||||||
LabelSelector: labels.Set(funcLabels).AsSelector().String(),
|
LabelSelector: labels.Set(funcLabels).AsSelector().String(),
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -311,15 +311,16 @@ func (gpm *GenericPoolManager) RefreshFuncPods(ctx context.Context, logger *zap.
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (gpm *GenericPoolManager) AdoptExistingResources(ctx context.Context) {
|
func (gpm *GenericPoolManager) AdoptExistingResources(ctx context.Context) {
|
||||||
envs, err := gpm.fissionClient.CoreV1().Environments(metav1.NamespaceAll).List(ctx, metav1.ListOptions{})
|
envMap := make(map[string]fv1.Environment)
|
||||||
|
wg := &sync.WaitGroup{}
|
||||||
|
|
||||||
|
for _, namespace := range utils.GetNamespaces() {
|
||||||
|
envs, err := gpm.fissionClient.CoreV1().Environments(namespace).List(ctx, metav1.ListOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gpm.logger.Error("error getting environment list", zap.Error(err))
|
gpm.logger.Error("error getting environment list", zap.Error(err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
envMap := make(map[string]fv1.Environment, len(envs.Items))
|
|
||||||
wg := &sync.WaitGroup{}
|
|
||||||
|
|
||||||
for i := range envs.Items {
|
for i := range envs.Items {
|
||||||
env := envs.Items[i]
|
env := envs.Items[i]
|
||||||
|
|
||||||
@@ -341,12 +342,14 @@ func (gpm *GenericPoolManager) AdoptExistingResources(ctx context.Context) {
|
|||||||
key := fmt.Sprintf("%v/%v", env.ObjectMeta.Namespace, env.ObjectMeta.Name)
|
key := fmt.Sprintf("%v/%v", env.ObjectMeta.Namespace, env.ObjectMeta.Name)
|
||||||
envMap[key] = env
|
envMap[key] = env
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
l := map[string]string{
|
l := map[string]string{
|
||||||
fv1.EXECUTOR_TYPE: string(fv1.ExecutorTypePoolmgr),
|
fv1.EXECUTOR_TYPE: string(fv1.ExecutorTypePoolmgr),
|
||||||
}
|
}
|
||||||
|
|
||||||
podList, err := gpm.kubernetesClient.CoreV1().Pods(metav1.NamespaceAll).List(ctx, metav1.ListOptions{
|
for _, namespace := range utils.GetNamespaces() {
|
||||||
|
podList, err := gpm.kubernetesClient.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{
|
||||||
LabelSelector: labels.Set(l).AsSelector().String(),
|
LabelSelector: labels.Set(l).AsSelector().String(),
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -438,6 +441,7 @@ func (gpm *GenericPoolManager) AdoptExistingResources(ctx context.Context) {
|
|||||||
zap.String("pod", pod.Name), zap.Any("labels", pod.Labels), zap.Any("annotations", pod.Annotations))
|
zap.String("pod", pod.Name), zap.Any("labels", pod.Labels), zap.Any("annotations", pod.Annotations))
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -263,7 +263,7 @@ func (p *PoolPodController) workerRun(ctx context.Context, name string, processF
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *PoolPodController) getEnvLister(namespace string) (flisterv1.EnvironmentLister, error) {
|
func (p *PoolPodController) getEnvLister(namespace string) (flisterv1.EnvironmentLister, error) {
|
||||||
lister, ok := p.envLister[metav1.NamespaceAll]
|
lister, ok := p.envLister[namespace]
|
||||||
if ok {
|
if ok {
|
||||||
return lister, nil
|
return lister, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ func CleanupDeployments(ctx context.Context, logger *zap.Logger, client kubernet
|
|||||||
// ignore err
|
// ignore err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,6 +121,7 @@ func CleanupPods(ctx context.Context, logger *zap.Logger, client kubernetes.Inte
|
|||||||
// ignore err
|
// ignore err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -147,6 +149,7 @@ func CleanupServices(ctx context.Context, logger *zap.Logger, client kubernetes.
|
|||||||
// ignore err
|
// ignore err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -175,6 +178,7 @@ func CleanupHpa(ctx context.Context, logger *zap.Logger, client kubernetes.Inter
|
|||||||
// ignore err
|
// ignore err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,6 +190,7 @@ func CleanupRoleBindings(ctx context.Context, logger *zap.Logger, client kuberne
|
|||||||
time.Sleep(cleanupRoleBindingInterval)
|
time.Sleep(cleanupRoleBindingInterval)
|
||||||
|
|
||||||
logger.Debug("starting cleanupRoleBindings cycle")
|
logger.Debug("starting cleanupRoleBindings cycle")
|
||||||
|
|
||||||
// get all rolebindings ( just to be efficient, one call to kubernetes )
|
// get all rolebindings ( just to be efficient, one call to kubernetes )
|
||||||
rbList, err := client.RbacV1().RoleBindings(metav1.NamespaceAll).List(ctx, metav1.ListOptions{})
|
rbList, err := client.RbacV1().RoleBindings(metav1.NamespaceAll).List(ctx, metav1.ListOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -122,9 +122,6 @@ func (frr *functionReferenceResolver) resolve(trigger fv1.HTTPTrigger) (*resolve
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (frr *functionReferenceResolver) getInformerByNamespace(namespace string) (k8sCache.SharedIndexInformer, error) {
|
func (frr *functionReferenceResolver) getInformerByNamespace(namespace string) (k8sCache.SharedIndexInformer, error) {
|
||||||
if informer, ok := frr.funcInformer[metav1.NamespaceAll]; ok {
|
|
||||||
return informer, nil
|
|
||||||
}
|
|
||||||
if informer, ok := frr.funcInformer[namespace]; ok {
|
if informer, ok := frr.funcInformer[namespace]; ok {
|
||||||
return informer, nil
|
return informer, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import (
|
|||||||
|
|
||||||
"github.com/fission/fission/pkg/crd"
|
"github.com/fission/fission/pkg/crd"
|
||||||
"github.com/fission/fission/pkg/generated/clientset/versioned"
|
"github.com/fission/fission/pkg/generated/clientset/versioned"
|
||||||
|
"github.com/fission/fission/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ArchivePruner struct {
|
type ArchivePruner struct {
|
||||||
@@ -82,7 +83,8 @@ func (pruner *ArchivePruner) getOrphanArchives(ctx context.Context) {
|
|||||||
var archiveID string
|
var archiveID string
|
||||||
|
|
||||||
// get all pkgs from kubernetes
|
// get all pkgs from kubernetes
|
||||||
pkgList, err := pruner.crdClient.CoreV1().Packages(metav1.NamespaceAll).List(ctx, metav1.ListOptions{})
|
for _, namespace := range utils.GetNamespaces() {
|
||||||
|
pkgList, err := pruner.crdClient.CoreV1().Packages(namespace).List(ctx, metav1.ListOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
pruner.logger.Error("error getting package list from kubernetes", zap.Error(err))
|
pruner.logger.Error("error getting package list from kubernetes", zap.Error(err))
|
||||||
return
|
return
|
||||||
@@ -111,6 +113,7 @@ func (pruner *ArchivePruner) getOrphanArchives(ctx context.Context) {
|
|||||||
archivesRefByPkgs = append(archivesRefByPkgs, archiveID)
|
archivesRefByPkgs = append(archivesRefByPkgs, archiveID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pruner.logger.Debug("archives referenced by packagese", zap.Strings("archives", archivesRefByPkgs))
|
pruner.logger.Debug("archives referenced by packagese", zap.Strings("archives", archivesRefByPkgs))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user