preStop hook inside pod using K8s API - kubernetes-apiserver

Is there a way to call a function before the Pod is being terminated? preStop hook examples are based on yaml specs.
I want to use the K8s API, should I just write a SIGTERM handler ? What is the "safe" way to do it ?

Please, checkout finalizers.
They exactly get invoked before getting terminated.
example:
https://book.kubebuilder.io/reference/using-finalizers.html?highlight=finalizers#using-finalizers

Related

NiFi - Call Redis Commands in Groovy Script

I am trying to connect to my Redis instance from a groovy script (ExecuteGroovyScript) and execute arbitrary commands such as LPUSH. I currently have RedisConnectionPoolService enabled and working fine for caching processors.
Is there any way to achieve this? Any examples are appreciated.
EDIT:
I got to the point where I can call a command but for some reason it fails, here is the code and error
service = context.getControllerServiceLookup().getControllerService("2b841623-35ed-1e1a-0a77-46087267939d")
service.getConnection().withCloseable { redis ->
redis.listCommands().lPush("key".getBytes(), "1".getBytes())
}
If you have a RedisConnectionPoolService called service and call service.getConnection(), you will have a Spring Redis RedisConnection instance, so you can check their API for the kinds of calls you can make.
For LPUSH specifically you can call service.getConnection().listCommands().lpush()

laravel-shopify osiset Uninstallation webhook not getting work

https://github.com/osiset/laravel-shopify/wiki/Installation
I follow the step to add Uninstallation Job, But not getting any webhook call after uninstalling the app.
So when I try to install getting an error.
There’s no page at this address.
Can anyone help me with an example to check or debug that uninstallation Process?
It is an exercise in two parts. One, your App needs to listen to an endpoint. Create an endpoint that accepts webhooks and has the capability of ensuring security with the Shopify HMAC. Test your endpoint is working with Postman or some other simple too. By working we mean NOT 404. Now setup your webhook with the App API key you have, in your test store. Usually this is done by installing your App. Now uninstall. Watch your endpoint logs. Nothing much else to it.
If you are getting 404 errors, your App is not working properly. Work on that aspect of your web development before trying more complex things.
Did you type in ‘php artisan vendor:publish --tag=shopify-jobs‘
And also check if there is an Job at ‘App/Jobs/AppUninstalledJob‘
Also make sure that your shopify-config looks like this:
'webhooks' => [
[
'topic' => env('SHOPIFY_WEBHOOK_1_TOPIC', 'app/uninstalled'),
'address' => env('SHOPIFY_WEBHOOK_1_ADDRESS', env('APP_URL').'webhook/app-uninstalled')
]
]
Now you should also be aware of the fact that the webhook will not work on your local installation. If you went through all of the steps correctly and deploy your app to a public Server it will work.

Spring Config Client - ConfigClientWatch

I am looking at the class ConfigClientWatch in the package package org.springframework.cloud.config.client;
I was expecting that I could use this to poll the server periodically to see if the config had changed and then execute an refresh.
I am not able to get this to work? How does the value
String newState = this.environment.getProperty("config.client.state");
Get updated.
I have not been able to find any documentation on this.
Thanks in Advance
Raghu
Unfortunately, this property is only used by Vault backend. Anyway, there is a thread in the Spring Config's GitHub proposing changes to support other backends such as Git.
If you are using Git-backed configurations, this solution may work for you:
https://github.com/spring-cloud/spring-cloud-config/issues/1378#issuecomment-492073851
Please, upvote the GitHub thread so this feature gets accepted.

Ansible API : Custom Module

I would like to use a custom module for which I require "hostname" so that I can initiate SSH connection from the custom module and run commands. So I pass transport = "local" to the Runner object. However, I find no way to obtain "hostname" information in the custom module.
I am using Ansible 1.9.2 using Python API.
A module only has the information available that was explicitly passed to it. What you might be interested in instead is an action plugin, which by (non-exisiting) definition runs local on the control machine and has access to more (all?) data.
You can see some action plugin code here: https://github.com/ansible/ansible/tree/devel/lib/ansible/plugins/action
PS: Don't you want to upgrade to Ansible 2 before getting started writing custom modules/plugins? The API changed completely and once you upgrade you have to rewrite you module/plugin.
Okay, silly me. It's exactly the same way in the API too. You can extract hostname using {{ inventory_hostname }}.

How to test a rest api with Zend?

I don't know how to make unit test of my rest controller. Here is my code :
public function testpostAction(){
$this->dispatch('/chain');
$this->request->setHeader('Content-Type', 'text/json')
->setMethod('POST')
->setPost(array(
'chain_name' => 'mychaintest'
));
$this->assertAction('post'); ???
}
How I make a post?
Not sure if this is what you need but, if you want to make a POST call (http) to test your REST service, you can use Zend_Http_Client:
http://framework.zend.com/manual/en/zend.http.client.html
Anyway, if this is for unit testing it will be more complicated, since you'll need your application (the current build being testet) to be live and accesible in the server. That depends on how you have configured your build environment.
There should be a staging (virtual) machine where the build is (automatically) deployed before tests are run. That machine should be visible to the machine runing the tests.
Hope this helped. Cheers!
So, basically your question is how to emulate calling PUT and DELETE in your controller tests?
Since this apparently doesn't work:
$this->request->setMethod('PUT');
You can access both these actions with plain HTTP POST by providing _method parameter.
So to call PUT:
$this->request->setMethod('POST');
$this->dispatch('articles/123?_method=put');
To call DELETE:
$this->request->setMethod('POST');
$this->dispatch('articles/123?_method=delete');
More reading on how to deal with RESTful routing here - http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.rest