kubeplus
kubeplus copied to clipboard
Support for duration based licenses on Kinds
Currently KubePlus supports license definition for a Kind based on number of application instances that can be created and absolute time when an application instance can be created.
Occassionally, it might be useful to define a license that is duration-based. For instance, TrialKind can be associated with a license of "one month". This would mean that an application instance created for the TrialKind will be "in-license" for a period of one month after it is created.
One approach to implement this will be as follows:
We will implement a licensemanager component, whose job will be to go through all the Kinds registered by KubePlus and find the Kinds that have defined a duration-based license. For such a Kind, find all the application instances, and check their age. If the instance age is past the defined duration, then mark the application instance as "out-of-license".
In the status dictionary for the app instance, we will need to include a field "license-status". If no license is defined for a Kind, then this field will be empty. Otherwise, it will have values "in-license" or "out-of-license" depending upon the license status. The status dictionary update will need to happen here
The licensemanager component can be included as part of helmer as a separate func that sleeps for sometime, wakes up and does its work, and goes back to sleep. The reason helmer will be a good place to add this functionality is because we already have code to update an object's status in helmer.
Current license implementation is in [kubeconfiggenerator.py]((https://github.com/cloud-ark/kubeplus/blob/master/deploy/kubeconfiggenerator.py#L1185)
We can move this implementation to helm-pod so that all the license implementation is in one place.
Other changes will be as follows:
- License is created using the kubectl-license-create plugin. It uses crlicense.py file to create the license. License is stored as a configmap in the Namespace where KubePlus is installed. The license specs are added to this configmap as annotations. We will need to update crlicense.py appropriately to include an option to take a duration-based license as input, and adding it as an annotation on the configmap.
- We have the kubectl-appstatus plugin that gives an app instance's status. The core logic of getting an app's status is implemented in appstatus.py. We should include an app's license status in it's output.