CRD-client-go
crd-client-go defines the custom types used by FogAtlas in terms of
k8s Custom Resource Definition (CRD). Once defined the types, it generates the corresponding
API using k8s code generator (see below).
FogAtlas CRDs definition and API
Types in FogAtlas are defined starting from the following domain models: the first one models
a distributed infrastructure while the second models an application as a graph of vertices (microservices)
and edges (dataflows).
Infrastructure model
Application model
FADepl
FADepl models a cloud-native application as a graph of microservices. With respect to the K8s Deployment resource, FADepl adds the modelling of the data flows among different Deployment and of the network requirements on those data flows (e.g., latancy and throughput). You can find the definition of FADepl here.
FAExternalEndpoint
FAExternalEndpoint models an external services or a sensor/camera. You can find the definition of FAExternalEndpoint here.
FARegion
FARegion models a computing region located in a specific geographical area. You can find the definition of FARegion here.
FALink
FALink models a network link between two FARegions.
You can find the definition of FALink here.
FAPlacement
FAPlacement is a structure containing the placement scores assigned to each node for a given microservice/pod. It represents a data structure where an algorithm can store a score for each Pod for each Node. It works in combination with the scheduler-plugin. You can find the definition of FAPlacements here.
Where to find the complete definition of CRDs
The file types.go defines programmatically the CRDs.
In the folder crd_definitions you can find (in yaml format) the CRDs that extend the k8s resources.
How to define or change CRDs
- Write/Update these three files in
pkg/apis/fogatlas/v1alpha1
doc.go
where global generation tags are defined
types.go
where custom types are defined
register.go
where custom types are registered to the k8s API
- Use
./hack/update-codegen.sh
script to generate the code. This step needs:
go get k8s.io/code-generator
go get k8s.io/apimachinery
- Use
./hack/gen_crd.sh
to generate the corresponding crd. This step needs:
go get sigs.k8s.io/controller-tools/cmd/controller-gen
The steps 1-3 can be executed with a convenient Makefile tag.
How to install CRDs
In order to install the defined CRD on a k8s cluster, just do the following:
cd crd-definitions
kubectl apply -f fogatlas.fbk.eu_region.yaml
kubectl apply -f fogatlas.fbk.eu_link.yaml
kubectl apply -f fogatlas.fbk.eu_externalendpoint.yaml
kubectl apply -f fogatlas.fbk.eu_fadepl.yaml
kubectl apply -f fogatlas.fbk.eu_ffedfaapp.yaml
Test
The file main.go
provides an example on how to call both k8s vanilla API and Fogatlas API.
You need a k8s cluster where the CRDs are loaded and where some instances of them are defined. Moreover, if you don't access the cluster as k8s admin, you might need additional RBAC setup.
The syntax to launch the main.go
is as follows:
go run main.go --kubeconfig=<kube config path> --loglevel=<log level>
where kube config path
is the path of the k8s configuration file to access the cluster
and log level
is the level of the log (use "trace").
License
Copyright 2023 Fondazione Bruno Kessler
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this
file except in compliance with the License. You may obtain a copy of the License
here.
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
either express or implied. See the License for the specific language governing permissions
and limitations under the License.