Skip to content

Commit

Permalink
chore: code linting (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikouaj authored Dec 13, 2024
1 parent a4b11f7 commit 2942fa0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ jobs:
- name: Lint
uses: dominikh/staticcheck-action@v1
with:
version: "2023.1.7"
version: "2024.1.1"
install-go: false
8 changes: 4 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Google LLC
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -45,7 +45,7 @@ import (
)

const (
IN_PLACE_VERTICAL_POD_AUTOSCALING_FG_NAME = "InPlacePodVerticalScaling"
InPlacePodVerticalScalingFeatureGateName = "InPlacePodVerticalScaling"
)

var (
Expand Down Expand Up @@ -76,9 +76,9 @@ func main() {
setupLog.Info("validating required feature gates")
featureGates, err := getFeatureGatesFromMetrics(context.Background(), restConfig)
if err == nil {
if !featureGates.IsEnabledAnyStage(IN_PLACE_VERTICAL_POD_AUTOSCALING_FG_NAME) {
if !featureGates.IsEnabledAnyStage(InPlacePodVerticalScalingFeatureGateName) {
setupLog.Error(
fmt.Errorf("%s is not enabled at any stage", IN_PLACE_VERTICAL_POD_AUTOSCALING_FG_NAME),
fmt.Errorf("%s is not enabled at any stage", InPlacePodVerticalScalingFeatureGateName),
"required feature gates are not enabled")
os.Exit(1)
}
Expand Down
16 changes: 16 additions & 0 deletions internal/util/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2024 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package util provides utility structs and functions
package util
21 changes: 8 additions & 13 deletions internal/util/fg_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,10 @@ type FeatureGates map[string]map[string]bool
type FeatureGateStage string

const (
METRICS_ENDPOINT = "/metrics"
K8S_FEATURE_ENABLED_METRIC_NAME = "kubernetes_feature_enabled"
K8S_FEATURE_ENABLED_NAME_LABEL = "name"
K8S_FEATURE_ENABLED_STAGE_LABEL = "stage"

FEATURE_GATE_STAGE_ALPHA FeatureGateStage = "ALPHA"
FEATURE_GATE_STAGE_BETA FeatureGateStage = "BETA"
FEATURE_GATE_STAGE_GA FeatureGateStage = ""
FEATURE_GATE_STAGE_DEPRECATED FeatureGateStage = "DEPRECATED"
metricsEndpoint = "/metrics"
k8sFeatureEnabledMetricName = "kubernetes_feature_enabled"
k8sFeatureEnabledNameLabel = "name"
k8sFeatureEnabledStageLabel = "stage"
)

func (f FeatureGates) IsEnabled(featureGate string, stage FeatureGateStage) bool {
Expand Down Expand Up @@ -95,7 +90,7 @@ func NewMetricsFeatureGateValidator(ctx context.Context, RESTClient restclient.I
}

func (m *metricsFeatureGateValidator) GetFeatureGates() (FeatureGates, error) {
reader, err := m.client.Get().AbsPath(METRICS_ENDPOINT).Stream(m.ctx)
reader, err := m.client.Get().AbsPath(metricsEndpoint).Stream(m.ctx)
if err != nil {
return nil, err
}
Expand All @@ -107,7 +102,7 @@ func (m *metricsFeatureGateValidator) GetFeatureGates() (FeatureGates, error) {
}
featureGates := make(map[string]map[string]bool)
for name, family := range metricFamilies {
if name != K8S_FEATURE_ENABLED_METRIC_NAME {
if name != k8sFeatureEnabledMetricName {
continue
}
for _, metric := range family.Metric {
Expand All @@ -131,10 +126,10 @@ func getNameAndStage(labels []*promclient.LabelPair) (string, string, error) {
var name string
var stagePtr *string
for _, label := range labels {
if label.GetName() == K8S_FEATURE_ENABLED_NAME_LABEL {
if label.GetName() == k8sFeatureEnabledNameLabel {
name = label.GetValue()
}
if label.GetName() == K8S_FEATURE_ENABLED_STAGE_LABEL {
if label.GetName() == k8sFeatureEnabledStageLabel {
stagePtr = label.Value
}
}
Expand Down
8 changes: 4 additions & 4 deletions internal/util/fg_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import (
)

const (
K8S_FG_METRIC_HELP = "# HELP kubernetes_feature_enabled [BETA] This metric records the data about the stage and enablement of a k8s feature."
K8S_FG_METRIC_TYPE = "# TYPE kubernetes_feature_enabled gauge"
k8sFeatureGateMetricHelp = "# HELP kubernetes_feature_enabled [BETA] This metric records the data about the stage and enablement of a k8s feature."
k8sFeatureGateMetricType = "# TYPE kubernetes_feature_enabled gauge"
)

var _ = Describe("Feature Gate Validator", func() {
Expand Down Expand Up @@ -141,9 +141,9 @@ var _ = Describe("Feature Gate Validator", func() {

func featureGateString(data map[string]map[string]int) string {
builder := strings.Builder{}
builder.WriteString(K8S_FG_METRIC_HELP)
builder.WriteString(k8sFeatureGateMetricHelp)
builder.WriteString("\n")
builder.WriteString(K8S_FG_METRIC_TYPE)
builder.WriteString(k8sFeatureGateMetricType)
builder.WriteString("\n")
if data == nil {
return builder.String()
Expand Down

0 comments on commit 2942fa0

Please sign in to comment.