Simplify if logic in container executor deployment creation (#2282)
Signed-off-by: Dylan Arbour <arbourd@users.noreply.github.com>
This commit is contained in:
@@ -55,7 +55,33 @@ func (cn *Container) createOrGetDeployment(ctx context.Context, fn *fv1.Function
|
|||||||
}
|
}
|
||||||
|
|
||||||
existingDepl, err := cn.kubernetesClient.AppsV1().Deployments(deployNamespace).Get(ctx, deployName, metav1.GetOptions{})
|
existingDepl, err := cn.kubernetesClient.AppsV1().Deployments(deployNamespace).Get(ctx, deployName, metav1.GetOptions{})
|
||||||
if err == nil {
|
if err != nil && !k8s_err.IsNotFound(err) {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create new deployment if one does not previously exist
|
||||||
|
if k8s_err.IsNotFound(err) {
|
||||||
|
depl, err := cn.kubernetesClient.AppsV1().Deployments(deployNamespace).Create(ctx, deployment, metav1.CreateOptions{})
|
||||||
|
if err != nil {
|
||||||
|
if k8s_err.IsAlreadyExists(err) {
|
||||||
|
depl, err = cn.kubernetesClient.AppsV1().Deployments(deployNamespace).Get(ctx, deployName, metav1.GetOptions{})
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("error while creating function deployment",
|
||||||
|
zap.Error(err),
|
||||||
|
zap.String("function", fn.ObjectMeta.Name),
|
||||||
|
zap.String("deployment_name", deployName),
|
||||||
|
zap.String("deployment_namespace", deployNamespace))
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
otelUtils.SpanTrackEvent(ctx, "deploymentCreated", otelUtils.GetAttributesForDeployment(depl)...)
|
||||||
|
if minScale > 0 {
|
||||||
|
depl, err = cn.waitForDeploy(ctx, depl, minScale, specializationTimeout)
|
||||||
|
}
|
||||||
|
return depl, err
|
||||||
|
}
|
||||||
|
|
||||||
// Try to adopt orphan deployment created by the old executor.
|
// Try to adopt orphan deployment created by the old executor.
|
||||||
if existingDepl.Annotations[fv1.EXECUTOR_INSTANCEID_LABEL] != cn.instanceID {
|
if existingDepl.Annotations[fv1.EXECUTOR_INSTANCEID_LABEL] != cn.instanceID {
|
||||||
existingDepl.Annotations = deployment.Annotations
|
existingDepl.Annotations = deployment.Annotations
|
||||||
@@ -88,28 +114,6 @@ func (cn *Container) createOrGetDeployment(ctx context.Context, fn *fv1.Function
|
|||||||
}
|
}
|
||||||
|
|
||||||
return existingDepl, err
|
return existingDepl, err
|
||||||
} else if k8s_err.IsNotFound(err) {
|
|
||||||
depl, err := cn.kubernetesClient.AppsV1().Deployments(deployNamespace).Create(ctx, deployment, metav1.CreateOptions{})
|
|
||||||
if err != nil {
|
|
||||||
if k8s_err.IsAlreadyExists(err) {
|
|
||||||
depl, err = cn.kubernetesClient.AppsV1().Deployments(deployNamespace).Get(ctx, deployName, metav1.GetOptions{})
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
logger.Error("error while creating function deployment",
|
|
||||||
zap.Error(err),
|
|
||||||
zap.String("function", fn.ObjectMeta.Name),
|
|
||||||
zap.String("deployment_name", deployName),
|
|
||||||
zap.String("deployment_namespace", deployNamespace))
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
otelUtils.SpanTrackEvent(ctx, "deploymentCreated", otelUtils.GetAttributesForDeployment(depl)...)
|
|
||||||
if minScale > 0 {
|
|
||||||
depl, err = cn.waitForDeploy(ctx, depl, minScale, specializationTimeout)
|
|
||||||
}
|
|
||||||
return depl, err
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cn *Container) updateDeployment(ctx context.Context, deployment *appsv1.Deployment, ns string) error {
|
func (cn *Container) updateDeployment(ctx context.Context, deployment *appsv1.Deployment, ns string) error {
|
||||||
|
|||||||
Reference in New Issue
Block a user