You are developing code in the open-source project github.com/cobaltcore-dev/cortex.
Cortex is a modular and extensible service for initial placement and scheduling in cloud-native environments covering workloads such as compute, storage, network, and other scheduling domains.
It improves resource utilization and operational performance by making smart placement decisions based on the current state of the environment and defined constraints and objectives.
Cortex is written in Golang and is designed for production-scale deployments using algorithmic approaches to balance decision quality, execution efficiency, and maintaining a low resource footprint.
All code files must contain this license header:
// Copyright SAP SE
// SPDX-License-Identifier: Apache-2.0General:
- Keep it concise and always focus on good code quality. We go to production
- We are on modern Golang, so you no longer need
interface{}and useanyinstead - Similarly, you no longer have to capture loop variables in closures, as this is now the default behavior in Go
- Don’t document trivial steps you do and avoid unnecessary empty lines between code segments
- When adding imports, keep in mind that the autoformatter will remove them if you don't use them
fmt.Errorfshould not be used when there are no parameters. Useerrors.New- Errors should always be lowercase like
errors.New("this is an error")to conform to linting rules - You can use
maps.Copyinstead of iteratively copying a map - You can use
strings.Containsto check if some string is in another - You can use
slices.Containsto check if an element is part of a slice - And definitely use
testlib.Ptrfor test cases that require pointer values
Testing:
- Ideally test files should be short and contain only the necessary cases
- Avoid creating testing libraries, keep helper functions in the same file as the tests that use them
- Use golang native testing whenever possible, avoid using Ginkgo or testify
- Don't test for the existence of interface methods
- If applicable, use struct based test cases, but limit yourself to the most relevant cases
Helm charts:
- Note the
# from: file://../../library/cortex-postgrescomment inChart.yamlfiles, this is required and should point to the local chart path
Code:
cmd/manager/main.gois the entry point for the manager, which starts the controllers and webhookscmd/shim/main.gois the entry point for cortex shims exposing cortex capabilities over REST endpointsapi/v1alpha1is where the CRD specs of cortex livesapi/externalcontains messages sent to cortex via http from external openstack servicesinternal/schedulingcontains the logic for scheduling in different cloud domainsinternal/knowledgehas all the logic for feature extraction and raw data downloads from sources like prometheus and openstackpkgis the code that is very non-cortex-specific and can be used across other projects as well
Deployment:
helm/librarycontains a generic cortex setup, i.e. the manager and its dependencieshelm/devcontains charts that can deploy cortex dependencies that a typical production cluster already has, such as a fine-tuned kube-prometheus-stack for monitoringhelm/bundleshere are the charts that stylize the library chart into a deployment for a specific domain, for example a bundle for deploying cortex with openstack nova- In the
helmfolders there are also helpers for syncing helm dependencies which are used by the tiltfile for local development and our ci pipelines to replace oci dependencies with local paths
Tooling:
toolscontains miscallaneous tools for development, which should typically not be used by agents
Documentation:
docscontains documentation for cortex, which should be written in markdown
Before finishing your task, you should always ensure local tests and lints are passing:
makeregenerates CRDs and deepcopy methods, runs tests, and performs lints- Avoid running
makewhen you don't want to apply your crd changes just yet make lintruns golangci-lint,make lint-fixruns golangci-lint with--fixmake testruns all the unit tests withgo test ./...- If you are struggling with the Makefile, you can use
make helpto get a list of all available commands and their descriptions