serverless / serverless-kubeless

This plugin enables support for Kubeless within the Serverless Framework.
Apache License 2.0
303 stars 81 forks source link

Unable to redeploy functions #124

Closed AlexRex closed 6 years ago

AlexRex commented 6 years ago

When deploying a function, the first time I can deploy it without any issues, but if I try to redeploy it, either with the command sls deploy or only deploying the function with sls deploy -f ping, I got an error coming from kubernetes:

$ sls deploy -f ping
Serverless: Packaging function: ping...
Serverless: Excluding development dependencies...
Serverless: Redeploying ping...

  Error --------------------------------------------------

  Found errors while processing the given functions:
Error: Unable to update the function ping. Received:
  Code: 422
  Message: Function.kubeless.io "ping" is invalid: apiVersion: Invalid value: "Function": must be kubeless.io/v1beta1

     For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Issues:        forum.serverless.com

  Your Environment Information -----------------------------
     OS:                     darwin
     Node Version:           8.11.1
     Serverless Version:     1.27.3

The first time after deploying everything it works perfect, but afterwards I am getting this error.

This is my serverless.yml file:

service: pingpong
provider:
  name: kubeless
  runtime: nodejs8
  hostname: myhostname.io

plugins:
  - serverless-kubeless

functions:
  ping:
    handler: handler.ping
    events:
      - http:
          path: /ping

And this is the handler:

const _ = require('lodash');
const fetch = require('node-fetch');

const ping = (event, context) => {
  const { request, response } = event.extensions;
  _.assign(event.data, { date: new Date().toTimeString() });

  return fetch('http://pong:8080/pong', {
    method: 'GET'
  }).then(async (res) => {
    const resp = await res.json();
    return {
      msg: 'called from ping, and response from',
      resp
    }
  }); 
};

module.exports = {
  ping
};

I noticed that if I change the handler file and try to redeploy, then I don't get any error, even if I only change one space.

sebgoa commented 6 years ago

most likely the deployment of a specific function uses the old function API group.

should be a small fix

sebgoa commented 6 years ago

no,I read to fast sorry. We will check it out.

andresmgot commented 6 years ago

hi @AlexRex, it is weird but I am not able to reproduce it with the latest kubeless and serverless-kubeless:

▶ sls deploy -v
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Deploying function ping...
Serverless: Pods status: {"waiting":{"reason":"PodInitializing"}}
Serverless: Function ping successfully deployed
Serverless: Deployed Ingress rule pingpong

▶ sls deploy -v
Serverless: Packaging service...
Serverless: Excluding development dependencies...
Serverless: Pods status: {"running":{"startedAt":"2018-05-30T13:08:59Z"}},{"waiting":{"reason":"PodInitializing"}}
Serverless: Function ping successfully deployed
Serverless: Updated Ingress rule pingpong

▶ sls deploy -f ping
Serverless: Packaging function: ping...
executing this?
Serverless: Excluding development dependencies...
Serverless: Redeploying ping...
Serverless: Function ping successfully deployed

which versions are you running? where are you running kubernetes?

AlexRex commented 6 years ago

@andresmgot

I am using: serverless-kubeless version 0.4.2 kubernetes version 1.8.0 on Minikube (maybe this is the cause) serverless version 1.27.3 Kubeless version: v1.0.0-alpha.4

andresmgot commented 6 years ago

that's seems correct but in any case, if your minikube is a development environment, could you try to upgrade/delete your current cluster?

AlexRex commented 6 years ago

I tried out twice and same effect. Not sure what else I can try. I mean, is not really a blocker as whenever I want to redeploy I can change a file and do it, but only happens if I change a handler file, not the serverless.yml file, for example.

andresmgot commented 6 years ago

I finally was able to reproduce it forcing the version 1.8.0. Apparently it's a bug there but I am not able to find any reference to that. I recommend you to upgrade to 1.9 but if for some reason you need to run Kubernetes 1.8 you can still create it as:

minikube start --vm-driver=hyperkit --bootstrapper=kubeadm  --kubernetes-version=v1.8.1

Note that you need hyperkit for that. Sorry for the inconveniences.

AlexRex commented 6 years ago

Thanks for looking at it! I'm in fact using 1.8.0, using hyperkit. I will move to 1.8.1 or try with 1.9.