Skip to content

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

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 8 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,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 @@ -111,10 +112,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.18.0
CONTROLLER_GEN_VER := fb8e57da18d1a7e2faa074a3835f8326e9b64f75
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.12.3
GOTESTSUM_BIN := gotestsum
Expand Down Expand Up @@ -635,9 +637,10 @@ 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
@echo "Use PR state from 'https://github.com/kubernetes-sigs/cluster-api/pull/9347'"; \
exit 1
generate-metrics-config: $(CONTROLLER_GEN) ## Generate ./config/metrics/crd-metrics-config.yaml
$(CONTROLLER_GEN) metrics output:metrics:dir=./config/metrics \
paths=./api/... \
paths=./test/infrastructure/docker/api/...

.PHONY: generate-diagrams
generate-diagrams: ## Generate diagrams for *.plantuml files
Expand Down Expand Up @@ -1447,7 +1450,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/v1beta2/clusterresourceset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ type ClusterResourceSetStatus 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"`

// observedGeneration reflects the generation of the most recently observed ClusterResourceSet.
Expand Down Expand Up @@ -192,6 +194,10 @@ func (m *ClusterResourceSet) SetConditions(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/bootstrap/kubeadm/v1beta2/kubeadmconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,8 @@ type KubeadmConfigStatus struct {
// +listType=map
// +listMapKey=type
// +kubebuilder:validation:MaxItems=32
// +Metrics:stateset:name="status_condition",help="The condition of a kubeadmconfig.",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 kubeadmconfig.",valueFrom=.lastTransitionTime,labelsFromPath={"type":".type","status":".status"}
Conditions []metav1.Condition `json:"conditions,omitempty"`

// initialization provides observations of the KubeadmConfig initialization process.
Expand Down Expand Up @@ -532,11 +534,20 @@ type KubeadmConfigV1Beta1DeprecatedStatus struct {
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of KubeadmConfig"

// KubeadmConfig is the Schema for the kubeadmconfigs API.
// +Metrics:gvk:namePrefix="capi_kubeadmconfig"
// +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=.metadata.labels.cluster\.x-k8s\.io/cluster-name
// +Metrics:info:name="info",help="Information about a kubeadmconfig.",labelsFromPath={name:.metadata.name}
type KubeadmConfig 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 kubeadmconfig 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 KubeadmConfig.
Expand Down
17 changes: 17 additions & 0 deletions api/controlplane/kubeadm/v1beta2/kubeadm_control_plane_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ type KubeadmControlPlaneSpec struct {
// odd numbers are permitted, as per [etcd best practice](https://etcd.io/docs/v3.3.12/faq/#why-an-odd-number-of-cluster-members).
// This is a pointer to distinguish between explicit zero and not specified.
// +optional
// +Metrics:gauge:name="spec_replicas",help="The number of desired machines for a kubeadmcontrolplane."
Replicas *int32 `json:"replicas,omitempty"`

// version defines the desired Kubernetes version.
Expand Down Expand Up @@ -587,6 +588,7 @@ type KubeadmControlPlaneRolloutStrategyRollingUpdate struct {
// Example: when this is set to 1, the control plane can be scaled
// up immediately when the rolling update starts.
// +optional
// +Metrics:gauge:name="spec_strategy_rollingupdate_max_surge",help="Maximum number of replicas that can be scheduled above the desired number of replicas during a rolling update of a kubeadmcontrolplane."
MaxSurge *intstr.IntOrString `json:"maxSurge,omitempty"`
}

Expand Down Expand Up @@ -667,6 +669,8 @@ type KubeadmControlPlaneStatus struct {
// +listType=map
// +listMapKey=type
// +kubebuilder:validation:MaxItems=32
// +Metrics:stateset:name="status_condition",help="The condition of a kubeadmcontrolplane.",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 kubeadmcontrolplane.",valueFrom=.lastTransitionTime,labelsFromPath={"type":".type","status":".status"}
Conditions []metav1.Condition `json:"conditions,omitempty"`

// initialization provides observations of the KubeadmControlPlane initialization process.
Expand All @@ -687,18 +691,22 @@ type KubeadmControlPlaneStatus struct {
// replicas is the total number of non-terminated machines targeted by this control plane
// (their labels match the selector).
// +optional
// +Metrics:gauge:name="status_replicas",help="The number of replicas per kubeadmcontrolplane.",nilIsZero=true
Replicas *int32 `json:"replicas,omitempty"`

// readyReplicas is the number of ready replicas for this KubeadmControlPlane. A machine is considered ready when Machine's Ready condition is true.
// +optional
// +Metrics:gauge:name="status_replicas_ready",help="The number of ready replicas per kubeadmcontrolplane.",nilIsZero=true
ReadyReplicas *int32 `json:"readyReplicas,omitempty"`

// availableReplicas is the number of available replicas targeted by this KubeadmControlPlane. A machine is considered available when Machine's Available condition is true.
// +optional
// +Metrics:gauge:name="status_replicas_available",help="The number of available replicas per kubeadmcontrolplane.",nilIsZero=true
AvailableReplicas *int32 `json:"availableReplicas,omitempty"`

// upToDateReplicas is the number of up-to-date replicas targeted by this KubeadmControlPlane. A machine is considered up-to-date when Machine's UpToDate condition is true.
// +optional
// +Metrics:gauge:name="status_replicas_uptodate",help="The number of up-to-date replicas per kubeadmcontrolplane.",nilIsZero=true
UpToDateReplicas *int32 `json:"upToDateReplicas,omitempty"`

// version represents the minimum Kubernetes version for the control plane machines
Expand Down Expand Up @@ -836,11 +844,20 @@ type LastRemediationStatus struct {
// +kubebuilder:printcolumn:name="Version",type=string,JSONPath=".spec.version",description="Kubernetes version associated with this control plane"

// KubeadmControlPlane is the Schema for the KubeadmControlPlane API.
// +Metrics:gvk:namePrefix="capi_kubeadmcontrolplane"
// +Metrics:labelFromPath:name="cluster_name",JSONPath=.metadata.ownerReferences.\[kind=Cluster\].name
// +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 kubeadmcontrolplane.",labelsFromPath={version:".spec.version"}
type KubeadmControlPlane 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:info:name="annotation_paused",JSONPath=.annotations['cluster\.x-k8s\.io/paused'],help="Whether the kubeadmcontrolplane is paused and any of its resources will not be processed by the controllers.",labelsFromPath={paused_value:"."}
// +Metrics:gauge:name="created",JSONPath=".creationTimestamp",help="Unix creation timestamp."
// +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 KubeadmControlPlane.
Expand Down
2 changes: 1 addition & 1 deletion api/core/v1beta1/machinehealthcheck_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ type MachineHealthCheckV1Beta2Status struct {
type MachineHealthCheck 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
// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata{
// +optional
metav1.ObjectMeta `json:"metadata,omitempty"`

Expand Down
11 changes: 11 additions & 0 deletions api/core/v1beta2/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,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 @@ -1320,6 +1321,8 @@ type ClusterStatus 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"`

// initialization provides observations of the Cluster initialization process.
Expand All @@ -1346,6 +1349,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"`

// observedGeneration is the latest generation observed by the controller.
Expand Down Expand Up @@ -1538,11 +1542,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.classRef.name",topology_class_namespace:".spec.topology.classRef.namespace",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/core/v1beta2/clusterclass_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,19 @@ const (

// ClusterClass is a template which can be used to create managed topologies.
// NOTE: This CRD can only be used if the ClusterTopology feature gate is enabled.
// +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 @@ -1512,6 +1520,8 @@ type ClusterClassStatus 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"`

// variables is a list of ClusterClassStatusVariable that are defined for the ClusterClass.
Expand Down
Loading