-
Notifications
You must be signed in to change notification settings - Fork 460
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
Simultaneously support versions v2 and v2beta2 of Autoscaling #1014
Changes from 12 commits
29518d9
1c4a35b
e8ff6b5
eb9ec44
693a099
ed148e6
0be053d
04d8f88
3abfacc
26414c9
b9f8af1
df711da
ceeaf37
bed58fc
e693549
4791659
5529f7a
a122e73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,9 @@ const ( | |
defaultAutoDetectFrequency = 5 * time.Second | ||
defaultCollectorConfigMapEntry = "collector.yaml" | ||
defaultTargetAllocatorConfigMapEntry = "targetallocator.yaml" | ||
AutoscalingVersionV2 = "v2" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: define these as enum (a golang type) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pavolloffay Can you point me to an example of what you want here? Googling "golang enums" returns a bunch of disparate answers |
||
AutoscalingVersionV2Beta2 = "v2beta2" | ||
DefaultAutoscalingVersion = AutoscalingVersionV2 | ||
) | ||
|
||
// Config holds the static configuration for this operator. | ||
|
@@ -45,6 +48,7 @@ type Config struct { | |
targetAllocatorConfigMapEntry string | ||
autoInstrumentationNodeJSImage string | ||
autoInstrumentationJavaImage string | ||
autoscalingVersion string | ||
onChange []func() error | ||
labelsFilter []string | ||
platform platform.Platform | ||
|
@@ -61,6 +65,7 @@ func New(opts ...Option) Config { | |
logger: logf.Log.WithName("config"), | ||
platform: platform.Unknown, | ||
version: version.Get(), | ||
autoscalingVersion: DefaultAutoscalingVersion, | ||
} | ||
for _, opt := range opts { | ||
opt(&o) | ||
|
@@ -81,6 +86,7 @@ func New(opts ...Option) Config { | |
autoInstrumentationPythonImage: o.autoInstrumentationPythonImage, | ||
autoInstrumentationDotNetImage: o.autoInstrumentationDotNetImage, | ||
labelsFilter: o.labelsFilter, | ||
autoscalingVersion: o.autoscalingVersion, | ||
} | ||
} | ||
|
||
|
@@ -132,6 +138,14 @@ func (c *Config) AutoDetect() error { | |
} | ||
} | ||
|
||
hpaVersion, err := c.autoDetect.HPAVersion() | ||
if err != nil { | ||
return err | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need for else branch |
||
c.autoscalingVersion = hpaVersion | ||
c.logger.Info("In Autodetect, Set HPA version to [", c.autoscalingVersion, "] from [", hpaVersion, "]") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
@@ -160,6 +174,11 @@ func (c *Config) Platform() platform.Platform { | |
return c.platform | ||
} | ||
|
||
// AutoscalingVersion represents the preferred version of autoscaling. | ||
func (c *Config) AutoscalingVersion() string { | ||
return c.autoscalingVersion | ||
} | ||
|
||
// AutoInstrumentationJavaImage returns OpenTelemetry Java auto-instrumentation container image. | ||
func (c *Config) AutoInstrumentationJavaImage() string { | ||
return c.autoInstrumentationJavaImage | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,8 @@ | |
package autodetect | ||
|
||
import ( | ||
"errors" | ||
|
||
"k8s.io/client-go/discovery" | ||
"k8s.io/client-go/rest" | ||
|
||
|
@@ -27,6 +29,7 @@ var _ AutoDetect = (*autoDetect)(nil) | |
// AutoDetect provides an assortment of routines that auto-detect traits based on the runtime. | ||
type AutoDetect interface { | ||
Platform() (platform.Platform, error) | ||
HPAVersion() (string, error) | ||
} | ||
|
||
type autoDetect struct { | ||
|
@@ -64,3 +67,23 @@ func (a *autoDetect) Platform() (platform.Platform, error) { | |
|
||
return platform.Kubernetes, nil | ||
} | ||
|
||
func (a *autoDetect) HPAVersion() (string, error) { | ||
apiList, err := a.dcl.ServerGroups() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
for _, apiGroup := range apiList.Groups { | ||
if apiGroup.Name == "autoscaling" { | ||
for _, version := range apiGroup.Versions { | ||
if version.Version == "v2" { // Can't use the constants from internal/config/main.go as that would create an import cycle | ||
return version.Version, nil | ||
} | ||
} | ||
return "v2beta2", nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returning this just like this does not seem right. It should be returned only if that version is present in the cluster. |
||
} | ||
} | ||
|
||
return "", errors.New("Failed to find apiGroup autoscaling") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: move this closer to the place where it is used - line 192