Support for providing multiple CMs and secrets in fn create/update (#1282)
This commit is contained in:
committed by
Ta-Ching Chen
parent
ef8289ff73
commit
cd36047660
+32
-26
@@ -226,8 +226,8 @@ func fnCreate(c *cli.Context) error {
|
||||
entrypoint := c.String("entrypoint")
|
||||
pkgName := c.String("pkg")
|
||||
|
||||
secretName := c.String("secret")
|
||||
cfgMapName := c.String("configmap")
|
||||
secretNames := c.StringSlice("secret")
|
||||
cfgMapNames := c.StringSlice("configmap")
|
||||
|
||||
invokeStrategy, err := getInvokeStrategy(c, nil)
|
||||
if err != nil {
|
||||
@@ -299,38 +299,44 @@ func fnCreate(c *cli.Context) error {
|
||||
var secrets []fv1.SecretReference
|
||||
var cfgmaps []fv1.ConfigMapReference
|
||||
|
||||
if len(secretName) > 0 {
|
||||
if len(secretNames) > 0 {
|
||||
// check the referenced secret is in the same ns as the function, if not give a warning.
|
||||
_, err := client.SecretGet(&metav1.ObjectMeta{
|
||||
Namespace: fnNamespace,
|
||||
Name: secretName,
|
||||
})
|
||||
if k8serrors.IsNotFound(err) {
|
||||
log.Warn(fmt.Sprintf("Secret %s not found in Namespace: %s. Secret needs to be present in the same namespace as function", secretName, fnNamespace))
|
||||
for _, secretName := range secretNames {
|
||||
_, err := client.SecretGet(&metav1.ObjectMeta{
|
||||
Namespace: fnNamespace,
|
||||
Name: secretName,
|
||||
})
|
||||
if k8serrors.IsNotFound(err) {
|
||||
log.Warn(fmt.Sprintf("Secret %s not found in Namespace: %s. Secret needs to be present in the same namespace as function", secretName, fnNamespace))
|
||||
}
|
||||
}
|
||||
|
||||
newSecret := fv1.SecretReference{
|
||||
Name: secretName,
|
||||
Namespace: fnNamespace,
|
||||
for _, secretName := range secretNames {
|
||||
newSecret := fv1.SecretReference{
|
||||
Name: secretName,
|
||||
Namespace: fnNamespace,
|
||||
}
|
||||
secrets = append(secrets, newSecret)
|
||||
}
|
||||
secrets = []fv1.SecretReference{newSecret}
|
||||
}
|
||||
|
||||
if len(cfgMapName) > 0 {
|
||||
if len(cfgMapNames) > 0 {
|
||||
// check the referenced cfgmap is in the same ns as the function, if not give a warning.
|
||||
_, err := client.ConfigMapGet(&metav1.ObjectMeta{
|
||||
Namespace: fnNamespace,
|
||||
Name: cfgMapName,
|
||||
})
|
||||
if k8serrors.IsNotFound(err) {
|
||||
log.Warn(fmt.Sprintf("ConfigMap %s not found in Namespace: %s. ConfigMap needs to be present in the same namespace as function", cfgMapName, fnNamespace))
|
||||
for _, cfgMapName := range cfgMapNames {
|
||||
_, err := client.ConfigMapGet(&metav1.ObjectMeta{
|
||||
Namespace: fnNamespace,
|
||||
Name: cfgMapName,
|
||||
})
|
||||
if k8serrors.IsNotFound(err) {
|
||||
log.Warn(fmt.Sprintf("ConfigMap %s not found in Namespace: %s. ConfigMap needs to be present in the same namespace as function", cfgMapName, fnNamespace))
|
||||
}
|
||||
}
|
||||
|
||||
newCfgMap := fv1.ConfigMapReference{
|
||||
Name: cfgMapName,
|
||||
Namespace: fnNamespace,
|
||||
for _, cfgMapName := range cfgMapNames {
|
||||
newCfgMap := fv1.ConfigMapReference{
|
||||
Name: cfgMapName,
|
||||
Namespace: fnNamespace,
|
||||
}
|
||||
cfgmaps = append(cfgmaps, newCfgMap)
|
||||
}
|
||||
cfgmaps = []fv1.ConfigMapReference{newCfgMap}
|
||||
}
|
||||
|
||||
function := &fv1.Function{
|
||||
|
||||
@@ -115,8 +115,8 @@ func NewCliApp() *cli.App {
|
||||
fnQueryFlag := cli.StringSliceFlag{Name: "query, q", Usage: "request query parameters: -q key1=value1 -q key2=value2"}
|
||||
fnEntryPointFlag := cli.StringFlag{Name: "entrypoint", Usage: "entry point for environment v2 to load with"}
|
||||
fnBuildCmdFlag := cli.StringFlag{Name: "buildcmd", Usage: "build command for builder to run with"}
|
||||
fnSecretFlag := cli.StringFlag{Name: "secret", Usage: "function access to secret, should be present in the same namespace as the function"}
|
||||
fnCfgMapFlag := cli.StringFlag{Name: "configmap", Usage: "function access to configmap, should be present in the same namespace as the function"}
|
||||
fnSecretFlag := cli.StringSliceFlag{Name: "secret", Usage: "function access to secret, should be present in the same namespace as the function. You can provide multiple secrets using multiple --secrets flags."}
|
||||
fnCfgMapFlag := cli.StringSliceFlag{Name: "configmap", Usage: "function access to configmap, should be present in the same namespace as the function. You can provide multiple configmaps using multiple --configmap flags."}
|
||||
fnLogCountFlag := cli.StringFlag{Name: "recordcount", Usage: "the n most recent log records"}
|
||||
fnForceFlag := cli.BoolFlag{Name: "force", Usage: "Force update a package even if it is used by one or more functions"}
|
||||
fnExecutorTypeFlag := cli.StringFlag{Name: "executortype", Value: types.ExecutorTypePoolmgr, Usage: "Executor type for execution; one of 'poolmgr', 'newdeploy' defaults to 'poolmgr'"}
|
||||
|
||||
Reference in New Issue
Block a user