lib/deploy.js
function deployMQTrigger(mqType, name, namespace, topic, options) {
  const opts = _.defaults({}, options, {
    log: console.log,
  });
  const trigger = {
    apiVersion: 'kubeless.io/v1beta1',
    kind: `${mqType}Trigger`,
    metadata: {
      name: _.kebabCase(`${name}-${topic}`),
      namespace,
      labels: {
        'created-by': 'kubeless',
      },
    },
    spec: {
      functionSelector: {
        matchLabels: {
          'created-by': 'kubeless',
          function: name,
        },
      },
      topic,
    },
  };
  const triggerApi = new CRD(
    'apis/kubeless.io',
    'v1beta1',
    namespace,
    `${mqType.toLowerCase()}triggers`
  );
  opts.log(`Deploying ${mqType} trigger: ${trigger.metadata.name}`);
  return triggerApi.getItem(trigger.metadata.name)
    .then((res) => {
      if (res.code === 404) {
        return triggerApi.post({ body: trigger });
      }
      opts.log(`Updating existing ${mqType} trigger`);
      return triggerApi.put(trigger.metadata.name, { body: trigger });
    });
}
function deployMQTrigger(mqType, name, namespace, topic, options) {
  const opts = _.defaults({}, options, {
    log: console.log,
  });
  const trigger = {
    apiVersion: 'kubeless.io/v1beta1',
    kind: `${mqType}Trigger`,
    metadata: {
      name: _.kebabCase(`${name}-${topic}`),
      namespace,
      labels: {
        'created-by': 'kubeless',
      },
    },
    spec: {
      functionSelector: {
        matchLabels: {
          'created-by': 'kubeless',
          function: name,
        },
      },
      topic,
    },
  };
  const triggerApi = new CRD(
    'apis/kubeless.io',
    'v1beta1',
    namespace,
    `${mqType.toLowerCase()}triggers`
  );
  opts.log(`Deploying ${mqType} trigger: ${trigger.metadata.name}`);
  return triggerApi.getItem(trigger.metadata.name)
    .then((res) => {
      if (res.code === 404) {
        return triggerApi.post({ body: trigger });
      }
      opts.log(`Updating existing ${mqType} trigger`);
      return triggerApi.put(trigger.metadata.name, { body: trigger });
    });
}
function deployMQTrigger ( mqType , name , namespace , topic , options ) { const opts = _ . defaults ( { } , options , { log : console . log , } ) ; const trigger = { apiVersion : 'kubeless.io/v1beta1' , kind : ` ${ mqType } ` , metadata : { name : _ . kebabCase ( ` ${ name } ${ topic } ` ) , namespace , labels : { 'created-by' : 'kubeless' , } , } , spec : { functionSelector : { matchLabels : { 'created-by' : 'kubeless' , function : name , } , } , topic , } , } ; const triggerApi = new CRD ( 'apis/kubeless.io' , 'v1beta1' , namespace , ` ${ mqType . toLowerCase ( ) } ` ) ; opts . log ( ` ${ mqType } ${ trigger . metadata . name } ` ) ; return triggerApi . getItem ( trigger . metadata . name ) . then ( ( res ) => { if ( res . code === 404 ) { return triggerApi . post ( { body : trigger } ) ; } opts . log ( ` ${ mqType } ` ) ; return triggerApi . put ( trigger . metadata . name , { body : trigger } ) ; } ) ; }
Handling Kafka and NATS message queue trigger

@param {MQTypes} mqType
@param {string} name
@param {string} namespace
@param {string} topic
@param {object} options
Handling Kafka and NATS message queue trigger