containers as functions (#1681)
PR adds a new executortype which supports running containers as functions. New CLI under functions is added to create container as functions. Co-authored-by: Harsh Thakur <harshthakur9030@gmail.com> Co-authored-by: Sanket Sudake <sanketsudake@gmail.com>
This commit is contained in:
co-authored by
Harsh Thakur
Sanket Sudake
parent
f3e1f9df90
commit
a82281ad1c
@@ -17,10 +17,16 @@ limitations under the License.
|
||||
package util
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/client-go/kubernetes"
|
||||
|
||||
fv1 "github.com/fission/fission/pkg/apis/core/v1"
|
||||
)
|
||||
|
||||
// ApplyImagePullSecret applies image pull secret to the give pod spec.
|
||||
@@ -49,3 +55,61 @@ func WaitTimeout(wg *sync.WaitGroup, timeout time.Duration) {
|
||||
case <-time.After(timeout):
|
||||
}
|
||||
}
|
||||
|
||||
// ConvertConfigSecrets returns envFromSource which can be passed directly into the pod spec
|
||||
func ConvertConfigSecrets(fn *fv1.Function, kc *kubernetes.Clientset) ([]apiv1.EnvFromSource, error) {
|
||||
|
||||
cmList := fn.Spec.ConfigMaps
|
||||
secList := fn.Spec.Secrets
|
||||
cmEnvSources := make([]*apiv1.ConfigMapEnvSource, 0)
|
||||
secEnvSources := make([]*apiv1.SecretEnvSource, 0)
|
||||
for _, cm := range cmList {
|
||||
if cm.Namespace != fn.Namespace {
|
||||
return nil, errors.New("Function should not reference config map of different namespace")
|
||||
}
|
||||
_, err := kc.CoreV1().ConfigMaps(cm.Namespace).Get(context.TODO(), cm.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
cmEnvSource := &apiv1.ConfigMapEnvSource{
|
||||
LocalObjectReference: apiv1.LocalObjectReference{Name: cm.Name},
|
||||
}
|
||||
|
||||
cmEnvSources = append(cmEnvSources, cmEnvSource)
|
||||
}
|
||||
|
||||
for _, sec := range secList {
|
||||
if sec.Namespace != fn.Namespace {
|
||||
return nil, errors.New("Function should not reference secret of different namespace")
|
||||
}
|
||||
_, err := kc.CoreV1().Secrets(sec.Namespace).Get(context.TODO(), sec.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
secEnvSource := &apiv1.SecretEnvSource{
|
||||
LocalObjectReference: apiv1.LocalObjectReference{Name: sec.Name},
|
||||
}
|
||||
|
||||
secEnvSources = append(secEnvSources, secEnvSource)
|
||||
}
|
||||
|
||||
envFromSources := make([]apiv1.EnvFromSource, 0)
|
||||
for _, cmEnvSource := range cmEnvSources {
|
||||
envFromSource := apiv1.EnvFromSource{
|
||||
|
||||
ConfigMapRef: cmEnvSource,
|
||||
}
|
||||
envFromSources = append(envFromSources, envFromSource)
|
||||
}
|
||||
|
||||
for _, secEnvSource := range secEnvSources {
|
||||
envFromSource := apiv1.EnvFromSource{
|
||||
|
||||
SecretRef: secEnvSource,
|
||||
}
|
||||
envFromSources = append(envFromSources, envFromSource)
|
||||
}
|
||||
return envFromSources, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user