...
Code Block |
---|
|
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
name: software.bpa.akraino.org
spec:
group: bpa.akraino.org
names:
kind: software
listKind: softwarerList
plural: software
singular: software
shortNames:
- susw
scope: Namespaced
subresources:
status: {}
validation:
openAPIV3Schema:
properties:
apiVersion:
description:
type: string
kind:
description:
type: string
metadata:
type: object
spec:
type: object
status:
type: object
version: v1alpha1
versions:
- name: v1alpha1
served: true
storage: true |
...
Software CR Object Definition(*_types.go)
The software_types.go file is the API for the software Custom resource
Code Block |
---|
package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
// SoftwareSpec defines the desired state of Software
// +k8s:openapi-gen=true
type SoftwareSpec 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-v1.book.kubebuilder.io/beyond_basics/generating_crd.html
SoftwareConfigMap string `json:"SoftwareConfigMapName,required"`
}
// SoftwareStatus defines the observed state of Software
// +k8s:openapi-gen=true
type SoftwareStatus struct {
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// Software is the Schema for the softwares API
// +k8s:openapi-gen=true
// +kubebuilder:subresource:status
type Software struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec SoftwareSpec `json:"spec,omitempty"`
Status SoftwareStatus `json:"status,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// SoftwareList contains a list of Software
type SoftwareList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Software `json:"items"`
}
func init() {
SchemeBuilder.Register(&Software{}, &SoftwareList{})
} |
SoftwareConfigMap: This corresponds to SoftwareConfigMapName in the SW CR (see sample below). The Software Config Map will contain a list of software and versions to install and update for each node type (master or worker).
Sample Software CR YAML files
Code Block |
---|
|
apiVersion: bpa.akraino.org/v1alpha1
kind: softwareSoftware
metadata:
name: example-software-sample
labels:
cluster: cluster-abc
owner: c1
spec:
masterSoftwareConfigMapName: software-sample-configmap
|
Sample Software ConfigMap
Code Block |
---|
|
apiVersion: v1
kind: softwareFromConfigMap
metadata:
name: software-sample-configmap
data:
- configMapRefmaster: |
curl:""
namehtop:""
master-configmap workertmux:""
softwareFrom:golang-go:"v12.1"
worker: |
- configMapRefcurl:""
htop:""
namejq: worker-configmap
""
tmux:"" |
The config map above is an example of how config map used by the software custom resource. The software specified under master would be installed on all master nodes and the software specified under worker would be installed on all the worker nodes. If a version is specified, that version of the software will be installed, if no version is specified as in the cases where "" is used above, the latest version would be installed from the apt repository.