crd-client-go

command module
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 13, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

README

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 Infrastructure model

Application model Application model

In the folder crd_definitions you can find (in yaml format) the CRDs that extend the k8s resources:

  • fogatlas.fbk.eu_faexternalendpoint.yaml: defines an external endpoint (sensor, camera or external service).
  • fogatlas.fbk.eu_fadepl.yaml: defines a so called FogAtlas deployment (FADepl) that models a cloud native application.
  • fogatlas.fbk.eu_faregion.yaml: defines a computing region.
  • fogatlas.fbk.eu_falink.yaml: defines a network link between two Regions.
  • fogatlas.fbk.eu_faplacements.yaml: stores placement info for the k8s scheduler.

Note that the definition of type FAPlacement 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.

The file types.go defines programmatically the CRDs.

How to define or change CRDs

  1. 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
  2. Use ./hack/update-codegen.sh script to generate the code. This step needs:
    go get k8s.io/code-generator
    go get k8s.io/apimachinery
    
  3. 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.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
pkg
apis/fogatlas/v1alpha1
Package v1alpha1 is the v1alpha1 version of the API.
Package v1alpha1 is the v1alpha1 version of the API.
generated/clientset/versioned
This package has the automatically generated clientset.
This package has the automatically generated clientset.
generated/clientset/versioned/fake
This package has the automatically generated fake clientset.
This package has the automatically generated fake clientset.
generated/clientset/versioned/scheme
This package contains the scheme of the automatically generated clientset.
This package contains the scheme of the automatically generated clientset.
generated/clientset/versioned/typed/fogatlas/v1alpha1
This package has the automatically generated typed clients.
This package has the automatically generated typed clients.
generated/clientset/versioned/typed/fogatlas/v1alpha1/fake
Package fake has the automatically generated clients.
Package fake has the automatically generated clients.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL