Skip to content

[WIP] ✨ Create kube-state-metrics configuration from markers #9347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ CAPD_DIR := $(TEST_DIR)/infrastructure/docker
CAPIM_DIR := $(TEST_DIR)/infrastructure/inmemory
TEST_EXTENSION_DIR := $(TEST_DIR)/extension
GO_INSTALL := ./scripts/go_install.sh
GO_INSTALL_FORK := ./scripts/go_install_fork.sh
OBSERVABILITY_DIR := hack/observability

export PATH := $(abspath $(TOOLS_BIN_DIR)):$(PATH)
Expand Down Expand Up @@ -112,10 +113,11 @@ SETUP_ENVTEST_BIN := setup-envtest
SETUP_ENVTEST := $(abspath $(TOOLS_BIN_DIR)/$(SETUP_ENVTEST_BIN)-$(SETUP_ENVTEST_VER))
SETUP_ENVTEST_PKG := sigs.k8s.io/controller-runtime/tools/setup-envtest

CONTROLLER_GEN_VER := v0.17.2
CONTROLLER_GEN_VER := 8e10d2c621f3468a5570bfcc9f49ca3a39001872
CONTROLLER_GEN_BIN := controller-gen
CONTROLLER_GEN := $(abspath $(TOOLS_BIN_DIR)/$(CONTROLLER_GEN_BIN)-$(CONTROLLER_GEN_VER))
CONTROLLER_GEN_PKG := sigs.k8s.io/controller-tools/cmd/controller-gen
CONTROLLER_GEN_PKG_REPLACE := sigs.k8s.io/controller-tools=github.com/chrischdi/controller-tools

GOTESTSUM_VER := v1.11.0
GOTESTSUM_BIN := gotestsum
Expand Down Expand Up @@ -618,18 +620,15 @@ generate-e2e-templates-main: $(KUSTOMIZE)
$(KUSTOMIZE) build $(DOCKER_TEMPLATES)/main/clusterclass-quick-start-kcp-only --load-restrictor LoadRestrictionsNone > $(DOCKER_TEMPLATES)/main/clusterclass-quick-start-kcp-only.yaml

.PHONY: generate-metrics-config
generate-metrics-config: ## Generate ./config/metrics/crd-metrics-config.yaml
OUTPUT_FILE="./config/metrics/crd-metrics-config.yaml"; \
METRIC_TEMPLATES_DIR="./config/metrics/templates"; \
echo "# This file was auto-generated via: make generate-metrics-config" > "$${OUTPUT_FILE}"; \
cat "$${METRIC_TEMPLATES_DIR}/header.yaml" >> "$${OUTPUT_FILE}"; \
for resource in clusterclass cluster kubeadmcontrolplane kubeadmconfig machine machinedeployment machinehealthcheck machineset machinepool; do \
cat "$${METRIC_TEMPLATES_DIR}/$${resource}.yaml"; \
sed 's/$${RESOURCE}/'$${resource}'/g' "$${METRIC_TEMPLATES_DIR}/common_metrics.yaml"; \
if [[ "$${resource}" != "cluster" ]]; then \
cat "$${METRIC_TEMPLATES_DIR}/owner_metric.yaml"; \
fi \
done >> "$${OUTPUT_FILE}"; \
generate-metrics-config: $(CONTROLLER_GEN) ## Generate ./config/metrics/crd-metrics-config.yaml
$(CONTROLLER_GEN) metrics output:metrics:dir=./config/metrics \
paths=./api/... \
paths=./controlplane/kubeadm/api/... \
paths=./bootstrap/kubeadm/api/... \
paths=./exp/api/... \
paths=./exp/ipam/api/... \
paths=./exp/runtime/api/... \
paths=./test/infrastructure/docker/api/...

.PHONY: generate-diagrams
generate-diagrams: ## Generate diagrams for *.plantuml files
Expand Down Expand Up @@ -1411,7 +1410,7 @@ $(GOVULNCHECK_BIN): $(GOVULNCHECK) ## Build a local copy of govulncheck.
$(IMPORT_BOSS_BIN): $(IMPORT_BOSS)

$(CONTROLLER_GEN): # Build controller-gen from tools folder.
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) $(CONTROLLER_GEN_PKG) $(CONTROLLER_GEN_BIN) $(CONTROLLER_GEN_VER)
GOTOOLCHAIN=go1.24.1 GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL_FORK) $(CONTROLLER_GEN_PKG) $(CONTROLLER_GEN_BIN) $(CONTROLLER_GEN_VER) $(CONTROLLER_GEN_PKG_REPLACE)

## We are forcing a rebuilt of conversion-gen via PHONY so that we're always using an up-to-date version.
## We can't use a versioned name for the binary, because that would be reflected in generated files.
Expand Down
6 changes: 6 additions & 0 deletions api/addons/v1beta1/clusterresourceset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ type ClusterResourceSetV1Beta2Status struct {
// +listType=map
// +listMapKey=type
// +kubebuilder:validation:MaxItems=32
// +Metrics:stateset:name="status_condition",help="The condition of a clusterresourceset.",labelName="status",JSONPath=.status,list={"True","False","Unknown"},labelsFromPath={"type":".type"}
// +Metrics:gauge:name="status_condition_last_transition_time",help="The condition's last transition time of a clusterresourceset.",valueFrom=.lastTransitionTime,labelsFromPath={"type":".type","status":".status"}
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

Expand Down Expand Up @@ -180,6 +182,10 @@ func (m *ClusterResourceSet) SetV1Beta2Conditions(conditions []metav1.Condition)

// ClusterResourceSet is the Schema for the clusterresourcesets API.
// For advanced use cases an add-on provider should be used instead.
// +Metrics:gvk:namePrefix="capi_clusterresourceset"
// +Metrics:labelFromPath:name="name",JSONPath=".metadata.name"
// +Metrics:labelFromPath:name="namespace",JSONPath=".metadata.namespace"
// +Metrics:labelFromPath:name="uid",JSONPath=".metadata.uid"
type ClusterResourceSet struct {
metav1.TypeMeta `json:",inline"`
// metadata is the standard object's metadata.
Expand Down
11 changes: 11 additions & 0 deletions api/v1beta1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,7 @@ const (
type ClusterSpec struct {
// paused can be used to prevent controllers from processing the Cluster and all its associated objects.
// +optional
// +Metrics:gauge:name="spec_paused",help="Whether the cluster is paused and any of its resources will not be processed by the controllers.",nilIsZero=true
Paused bool `json:"paused,omitempty"`

// clusterNetwork represents the cluster network configuration.
Expand Down Expand Up @@ -982,6 +983,7 @@ type ClusterStatus struct {
// phase represents the current phase of cluster actuation.
// +optional
// +kubebuilder:validation:Enum=Pending;Provisioning;Provisioned;Deleting;Failed;Unknown
// +Metrics:stateset:name="status_phase",help="The clusters current phase.",labelName="phase",list={"Pending","Provisioning","Provisioned","Deleting","Failed","Unknown"}
Phase string `json:"phase,omitempty"`

// infrastructureReady is the state of the infrastructure provider.
Expand Down Expand Up @@ -1020,6 +1022,8 @@ type ClusterV1Beta2Status struct {
// +listType=map
// +listMapKey=type
// +kubebuilder:validation:MaxItems=32
// +Metrics:stateset:name="status_condition",help="The condition of a cluster.",labelName="status",JSONPath=.status,list={"True","False","Unknown"},labelsFromPath={"type":".type"}
// +Metrics:gauge:name="status_condition_last_transition_time",help="The condition's last transition time of a cluster.",valueFrom=.lastTransitionTime,labelsFromPath={"type":".type","status":".status"}
Conditions []metav1.Condition `json:"conditions,omitempty"`

// controlPlane groups all the observations about Cluster's ControlPlane current state.
Expand Down Expand Up @@ -1144,11 +1148,18 @@ func (v APIEndpoint) String() string {
// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.topology.version",description="Kubernetes version associated with this Cluster"

// Cluster is the Schema for the clusters API.
// +Metrics:gvk:namePrefix="capi_cluster"
// +Metrics:labelFromPath:name="name",JSONPath=.metadata.name
// +Metrics:labelFromPath:name="namespace",JSONPath=.metadata.namespace
// +Metrics:labelFromPath:name="uid",JSONPath=.metadata.uid
// +Metrics:info:name="info",help="Information about a cluster.",labelsFromPath={topology_version:".spec.topology.version",topology_class:".spec.topology.class",control_plane_endpoint_host:".spec.controlPlaneEndpoint.host",control_plane_endpoint_port:".spec.controlPlaneEndpoint.port",control_plane_reference_kind:".spec.controlPlaneRef.kind",control_plane_reference_name:".spec.controlPlaneRef.name",infrastructure_reference_kind:".spec.infrastructureRef.kind",infrastructure_reference_name:".spec.infrastructureRef.name"}
type Cluster struct {
metav1.TypeMeta `json:",inline"`
// metadata is the standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
// +Metrics:gauge:name="created",JSONPath=".creationTimestamp",help="Unix creation timestamp."
// +Metrics:info:name="annotation_paused",JSONPath=.annotations['cluster\.x-k8s\.io/paused'],help="Whether the cluster is paused and any of its resources will not be processed by the controllers.",labelsFromPath={paused_value:"."}
metav1.ObjectMeta `json:"metadata,omitempty"`

// spec is the desired state of Cluster.
Expand Down
10 changes: 10 additions & 0 deletions api/v1beta1/clusterclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,19 @@ const (
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of ClusterClass"

// ClusterClass is a template which can be used to create managed topologies.
// +Metrics:gvk:namePrefix="capi_clusterclass"
// +Metrics:labelFromPath:name="name",JSONPath=.metadata.name
// +Metrics:labelFromPath:name="namespace",JSONPath=.metadata.namespace
// +Metrics:labelFromPath:name="uid",JSONPath=.metadata.uid
// +Metrics:info:name="info",help="Information about a clusterclass.",labelsFromPath={name:.metadata.name}
type ClusterClass struct {
metav1.TypeMeta `json:",inline"`
// metadata is the standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
// +Metrics:gauge:name="created",JSONPath=".creationTimestamp",help="Unix creation timestamp."
// +Metrics:info:name="annotation_paused",JSONPath=.annotations['cluster\.x-k8s\.io/paused'],help="Whether the clusterclass is paused and any of its resources will not be processed by the controllers.",labelsFromPath={paused_value:"."}
// +Metrics:info:name="owner",JSONPath=".ownerReferences",help="Owner references.",labelsFromPath={owner_is_controller:".controller",owner_kind:".kind",owner_name:".name",owner_uid:".uid"}
metav1.ObjectMeta `json:"metadata,omitempty"`

// spec is the desired state of ClusterClass.
Expand Down Expand Up @@ -1167,6 +1175,8 @@ type ClusterClassV1Beta2Status struct {
// +listType=map
// +listMapKey=type
// +kubebuilder:validation:MaxItems=32
// +Metrics:stateset:name="status_condition",help="The condition of a clusterclass.",labelName="status",JSONPath=.status,list={"True","False","Unknown"},labelsFromPath={"type":".type"}
// +Metrics:gauge:name="status_condition_last_transition_time",help="The condition's last transition time of a clusterclass.",valueFrom=.lastTransitionTime,labelsFromPath={"type":".type","status":".status"}
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

Expand Down
15 changes: 15 additions & 0 deletions api/v1beta1/machine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,7 @@ type MachineReadinessGate struct {
type MachineStatus struct {
// nodeRef will point to the corresponding Node if it exists.
// +optional
// +Metrics:info:name="status_noderef",help="Information about the node reference of a machine.",labelsFromPath={node_name:".name",node_uid:".uid"}
NodeRef *corev1.ObjectReference `json:"nodeRef,omitempty"`

// nodeInfo is a set of ids/uuids to uniquely identify the node.
Expand Down Expand Up @@ -559,16 +560,19 @@ type MachineStatus struct {
// addresses is a list of addresses assigned to the machine.
// This field is copied from the infrastructure provider reference.
// +optional
// +Metrics:info:name="addresses",help="Address information about a machine.",labelsFromPath={address:".address",type:".type"}
Addresses MachineAddresses `json:"addresses,omitempty"`

// phase represents the current phase of machine actuation.
// +optional
// +kubebuilder:validation:Enum=Pending;Provisioning;Provisioned;Running;Deleting;Deleted;Failed;Unknown
// +Metrics:stateset:name="status_phase",help="The machines current phase.",labelName="phase",list={"Pending","Provisioning","Provisioned","Running","Deleting","Deleted","Failed","Unknown"}
Phase string `json:"phase,omitempty"`

// certificatesExpiryDate is the expiry date of the machine certificates.
// This value is only set for control plane machines.
// +optional
// +Metrics:gauge:name="status_certificatesexpirydate",help="Information about certificate expiration date of a control plane node.",nilIsZero=true
CertificatesExpiryDate *metav1.Time `json:"certificatesExpiryDate,omitempty"`

// bootstrapReady is the state of the bootstrap provider.
Expand Down Expand Up @@ -610,6 +614,8 @@ type MachineV1Beta2Status struct {
// +listType=map
// +listMapKey=type
// +kubebuilder:validation:MaxItems=32
// +Metrics:stateset:name="status_condition",help="The condition of a machine.",labelName="status",JSONPath=".status",list={"True","False","Unknown"},labelsFromPath={"type":".type"}
// +Metrics:gauge:name="status_condition_last_transition_time",help="The condition's last transition time of a machine.",valueFrom=.lastTransitionTime,labelsFromPath={"type":".type","status":".status"}
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

Expand Down Expand Up @@ -688,11 +694,20 @@ type Bootstrap struct {
// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.version",description="Kubernetes version associated with this Machine"

// Machine is the Schema for the machines API.
// +Metrics:gvk:namePrefix="capi_machine"
// +Metrics:labelFromPath:name="name",JSONPath=".metadata.name"
// +Metrics:labelFromPath:name="namespace",JSONPath=".metadata.namespace"
// +Metrics:labelFromPath:name="uid",JSONPath=".metadata.uid"
// +Metrics:labelFromPath:name="cluster_name",JSONPath=".spec.clusterName"
// +Metrics:info:name="info",help="Information about a machine.",labelsFromPath={bootstrap_reference_kind:.spec.bootstrap.configRef.kind,bootstrap_reference_name:.spec.bootstrap.configRef.name,container_runtime_version:.status.nodeInfo.containerRuntimeVersion,control_plane_name:.metadata.labels.cluster\.x-k8s\.io/control-plane-name,failure_domain:.spec.failureDomain,infrastructure_reference_kind:.spec.infrastructureRef.kind,infrastructure_reference_name:.spec.infrastructureRef.name,kernel_version:.status.nodeInfo.kernelVersion,kube_proxy_version:.status.nodeInfo.kubeProxyVersion,kubelet_version:.status.nodeInfo.kubeletVersion,os_image:.status.nodeInfo.osImage,provider_id:.spec.providerID,version:.spec.version}
type Machine struct {
metav1.TypeMeta `json:",inline"`
// metadata is the standard object's metadata.
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
// +optional
// +Metrics:gauge:name="created",JSONPath=".creationTimestamp",help="Unix creation timestamp."
// +Metrics:info:name="annotation_paused",JSONPath=.annotations['cluster\.x-k8s\.io/paused'],help="Whether the machine is paused and any of its resources will not be processed by the controllers.",labelsFromPath={paused_value:"."}
// +Metrics:info:name="owner",JSONPath=".ownerReferences",help="Owner references.",labelsFromPath={owner_is_controller:".controller",owner_kind:".kind",owner_name:".name",owner_uid:".uid"}
metav1.ObjectMeta `json:"metadata,omitempty"`

// spec is the desired state of Machine.
Expand Down
Loading