Skip to content
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

Add status field information #99

Open
wants to merge 3 commits into
base: master
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
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,27 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- New status fields to help debugging and to give more context for scaling decisions.
- `lastScaleTime` is the last time the CustomPodAutoscaler scaled the number of pods, used by the autoscaler to
keep track of downscale stabilization between restarts.
- `currentReplicas` is the current number of replicas of pods managed by this autoscaler, as last seen by the
autoscaler.
- `desiredReplicas` is the desired number of replicas of pods managed by this autoscaler, as last calculated by the
autoscaler.
- `currentMetrics` is the last set of metrics gathered by this autoscaler, the last metrics gathered in the
metric gathering stage
- `currentEvaluation` is the last evaluation decision retrieved by this autoscaler, the last evaluation decision
retrieved in the evaluation stage
- `reference` is the identifier for the resource being scaled in the format `<api-version>/<api-kind/<name>`.
- Certain fields are now added as printer columns, so are visible when you do `kubectl get cpa` to add more context:
- `Last Scale Time` is the last time the CustomPodAutoscaler scaled the number of pods.
- `Current Replicas` is the current number of replicas of pods managed by this autoscaler.
- `Desired Replicas` is the desired number of replicas of pods managed by this autoscaler.
- `Reference` is the identifier for the resource being scaled in the format `<api-version>/<api-kind/<name>`.
### Changed
- Project restructured to be a Go dependency, all Go modules not under the `internal/` directory can be used as
dependencies and will have a backwards compatiblity guarantee.

## [v1.3.0] - 2022-07-08
### Fixed
Expand Down
38 changes: 36 additions & 2 deletions api/v1/custompodautoscaler_types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 The Custom Pod Autoscaler Authors.
Copyright 2022 The Custom Pod Autoscaler Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -23,6 +23,8 @@ import (

autoscaling "k8s.io/api/autoscaling/v1"

"github.com/jthomperoo/custom-pod-autoscaler/v2/evaluate"
"github.com/jthomperoo/custom-pod-autoscaler/v2/metric"
corev1 "k8s.io/api/core/v1"
)

Expand All @@ -49,14 +51,46 @@ type CustomPodAutoscalerSpec struct {
}

// CustomPodAutoscalerStatus defines the observed state of CustomPodAutoscaler
type CustomPodAutoscalerStatus struct{}
type CustomPodAutoscalerStatus struct {
// LastScaleTime is the last time the CustomPodAutoscaler scaled the number of pods, used by the autoscaler to
// keep track of downscale stabilization between restarts.
// +optional
LastScaleTime *metav1.Time `json:"lastScaleTime,omitempty"`

// CurrentReplicas is the current number of replicas of pods managed by this autoscaler, as last seen by the autoscaler.
// +optional
CurrentReplicas int32 `json:"currentReplicas"`

// DesiredReplicas is the desired number of replicas of pods managed by this autoscaler, as last calculated by the
// autoscaler.
// +optional
DesiredReplicas int32 `json:"desiredReplicas"`

// CurrentMetrics is the last set of metrics gathered by this autoscaler, the last metrics gathered in the
// metric gathering stage.
// +optional
CurrentMetrics []metric.ResourceMetric `json:"currentMetrics"`

// CurrentEvaluation is the last evaluation decision retrieved by this autoscaler, the last evaluation decision
// retrieved in the evaluation stage.
// +optional
CurrentEvaluation evaluate.Evaluation `json:"currentEvaluation"`

// Reference is the identifier for the resource being scaled in the format <api-version>/<api-kind/<name>.
// +optional
Reference string `json:"reference"`
}

// CustomPodAutoscaler is the Schema for the custompodautoscalers API
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:shortName=cpa
// +kubebuilder:printcolumn:name="Reference",type="string",JSONPath=`.status.reference`,description="The identifier for the resource being scaled in the format <api-version>/<api-kind/<name>"
// +kubebuilder:printcolumn:name="Current Replicas",type="string",JSONPath=`.status.currentReplicas`,description="The current number of replicas of pods managed by this autoscaler as last seen by the autoscaler"
// +kubebuilder:printcolumn:name="Desired Replicas",type="string",JSONPath=`.status.desiredReplicas`,description="The desired number of replicas of pods managed by this autoscaler as last calculated by the autoscaler"
// +kubebuilder:printcolumn:name="Last Scale Time",type="date",JSONPath=`.status.lastScaleTime`,description="The last time the CustomPodAutoscaler scaled the number of pods"
// +groupName=custompodautoscaler.com
type CustomPodAutoscaler struct {
metav1.TypeMeta `json:",inline"`
Expand Down
15 changes: 13 additions & 2 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.18
require (
github.com/go-logr/logr v1.2.3
github.com/google/go-cmp v0.5.8
github.com/jthomperoo/custom-pod-autoscaler/v2 v2.7.0
honnef.co/go/tools v0.3.2
k8s.io/api v0.24.2
k8s.io/apimachinery v0.24.2
Expand All @@ -15,28 +16,27 @@ require (
require (
cloud.google.com/go v0.81.0 // indirect
github.com/BurntSushi/toml v0.4.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful v2.9.5+incompatible // indirect
github.com/emicklei/go-restful v2.15.0+incompatible // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-logr/zapr v1.2.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/go-openapi/jsonreference v0.20.0 // indirect
github.com/go-openapi/swag v0.21.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/gofuzz v1.1.0 // indirect
github.com/google/gnostic v0.6.9 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/jthomperoo/k8shorizmetrics v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
Expand All @@ -52,23 +52,23 @@ require (
go.uber.org/zap v1.19.1 // indirect
golang.org/x/exp/typeparams v0.0.0-20220218215828-6cf2b201936e // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.0.0-20220209214540-3681064d5158 // indirect
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
golang.org/x/net v0.0.0-20220513224357-95641704303c // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/sys v0.0.0-20220513210249-45d2b4557a2a // indirect
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
golang.org/x/tools v0.1.11-0.20220513221640-090b14e8501f // indirect
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/protobuf v1.27.1 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gopkg.in/yaml.v3 v3.0.0-20220512140231-539c8e751b99 // indirect
k8s.io/apiextensions-apiserver v0.24.2 // indirect
k8s.io/component-base v0.24.2 // indirect
k8s.io/klog/v2 v2.60.1 // indirect
k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42 // indirect
k8s.io/kube-openapi v0.0.0-20220413171646-5e7f5fdc6da6 // indirect
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9 // indirect
sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
Expand Down
Loading