Fixed: Allow to disable owner references for cross namespace access with builder and function namespace (#3024)

* Add DISABLE_OWNER_REFERENCES env variable to executor and buildermgr deployment.
Use this env var to decide adding ownerReferences to K8s resources created by fission CRD.
* Resolve review comments
* Fix lint failure

---------

Signed-off-by: Md Soharab Ansari <soharab.ansari@infracloud.io>
This commit is contained in:
soharab-ic
2024-09-27 15:11:07 +05:30
committed by GitHub
parent b8f746cb98
commit 2bf00025ed
13 changed files with 155 additions and 82 deletions
+31 -20
View File
@@ -74,6 +74,7 @@ type (
useIstio bool
podSpecPatch *apiv1.PodSpec
envWatchInformer map[string]k8sCache.SharedIndexInformer
enableOwnerReferences bool
}
)
@@ -108,6 +109,7 @@ func makeEnvironmentWatcher(
fetcherConfig: fetcherConfig,
podSpecPatch: podSpecPatch,
envWatchInformer: utils.GetInformersForNamespaces(fissionClient, time.Minute*30, fv1.EnvironmentResource),
enableOwnerReferences: utils.IsOwnerReferencesEnabled(),
}
err := envWatcher.EnvWatchEventHandlers(ctx)
@@ -325,18 +327,22 @@ func (envw *environmentWatcher) getBuilderServiceList(ctx context.Context, sel m
func (envw *environmentWatcher) createBuilderService(ctx context.Context, env *fv1.Environment, ns string) (*apiv1.Service, error) {
name := fmt.Sprintf("%v-%v", env.ObjectMeta.Name, env.ObjectMeta.ResourceVersion)
sel := envw.getLabels(env.ObjectMeta.Name, ns, env.ObjectMeta.ResourceVersion)
var ownerReferences []metav1.OwnerReference
if envw.enableOwnerReferences {
ownerReferences = []metav1.OwnerReference{
*metav1.NewControllerRef(env, schema.GroupVersionKind{
Group: "fission.io",
Version: "v1",
Kind: "Environment",
}),
}
}
service := apiv1.Service{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
Name: name,
Labels: sel,
OwnerReferences: []metav1.OwnerReference{
*metav1.NewControllerRef(env, schema.GroupVersionKind{
Group: "fission.io",
Version: "v1",
Kind: "Environment",
}),
},
Namespace: ns,
Name: name,
Labels: sel,
OwnerReferences: ownerReferences,
},
Spec: apiv1.ServiceSpec{
Selector: sel,
@@ -443,18 +449,23 @@ func (envw *environmentWatcher) createBuilderDeployment(ctx context.Context, env
pod.Spec = *(util.ApplyImagePullSecret(env.Spec.ImagePullSecret, pod.Spec))
var ownerReferences []metav1.OwnerReference
if envw.enableOwnerReferences {
ownerReferences = []metav1.OwnerReference{
*metav1.NewControllerRef(env, schema.GroupVersionKind{
Group: "fission.io",
Version: "v1",
Kind: "Environment",
}),
}
}
deployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Namespace: ns,
Name: name,
Labels: sel,
OwnerReferences: []metav1.OwnerReference{
*metav1.NewControllerRef(env, schema.GroupVersionKind{
Group: "fission.io",
Version: "v1",
Kind: "Environment",
}),
},
Namespace: ns,
Name: name,
Labels: sel,
OwnerReferences: ownerReferences,
},
Spec: appsv1.DeploymentSpec{
Replicas: &replicas,