h4. Creating a basic operator with Operator-SDK tool.
* To create the operator: (cluster level) {code:java} $ operator-sdk new mobile-security-service-operator --cluster-scoped {code}
* Adding the CDR {code:java} $ operator-sdk add api --api-version=mobile-security-service.aerogear.com/v1alpha1 --kind=MobileSecurityService {code}
* InitialTypes - Just to validate operator creation
{code:java} type MobileSecurityServiceSpec struct { // INSERT ADDITIONAL SPEC FIELDS - desired state of cluster // Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file // Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html Size int32 `json:"size"` }
// MobileSecurityServiceStatus defines the observed state of MobileSecurityService // +k8s:openapi-gen=true type MobileSecurityServiceStatus struct { // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster // Important: Run "operator-sdk generate k8s" to regenerate code after modifying this file // Add custom validation using kubebuilder tags: https://book.kubebuilder.io/beyond_basics/generating_crd.html Nodes []string `json:"nodes"` } {code}
* Generating deepcopy files
{code:java} $ operator-sdk generate k8s {code}
* Adding a controller {code:java} operator-sdk add controller --api-version=mobile-security-service.aerogear.com/v1alpha1 --kind=MobileSecurityService {code}
* Registering the CRD Operator
{code:java} kubectl create -f deploy/crds/mobile-security-service_v1alpha1_mobilesecurityservice_crd.yaml {code}
* Creating docker image / just for now to test it. {code:java} $ operator-sdk build cmacedo/mobile-security-service-operator:v0.0.1 $ sed -i "" 's|REPLACE_IMAGE|cmacedo/mobile-security-service-operator:v0.0.1|g' deploy/operator.yaml $ docker push cmacedo/mobile-security-service-operator:v0.0.1 {code}
* Deploy Locally {code:java} $ kubectl create -f deploy/role.yaml $ kubectl create -f deploy/role_binding.yaml $ kubectl create -f deploy/service_account.yaml $ kubectl create -f deploy/operator.yaml {code}
|
|