Skip to content

Commit

Permalink
Remove duplicate imports (#47)
Browse files Browse the repository at this point in the history
Remove imports that import an already-imported package with a different
alias. Also, change the import alias of "k8s.io/api/autoscaling/v2" from
`v2` to `autoscalingv2` for consistency.
  • Loading branch information
soroushj authored Aug 25, 2023
1 parent 5f43b03 commit 668da16
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
3 changes: 1 addition & 2 deletions cmd/weaver-kube/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"os"

"github.com/ServiceWeaver/weaver-kube/internal/impl"
"github.com/ServiceWeaver/weaver/runtime"
swruntime "github.com/ServiceWeaver/weaver/runtime"
"github.com/ServiceWeaver/weaver/runtime/bin"
"github.com/ServiceWeaver/weaver/runtime/codegen"
Expand Down Expand Up @@ -106,7 +105,7 @@ func deploy(ctx context.Context, args []string) error {

// Parse and validate the kube section of the config.
config := &impl.KubeConfig{}
if err := runtime.ParseConfigSection(configKey, shortConfigKey, app.Sections, config); err != nil {
if err := swruntime.ParseConfigSection(configKey, shortConfigKey, app.Sections, config); err != nil {
return fmt.Errorf("parse kube config: %w", err)
}
if config.Image == "" {
Expand Down
27 changes: 13 additions & 14 deletions internal/impl/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import (
"github.com/ServiceWeaver/weaver/runtime/protos"
"golang.org/x/exp/maps"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/apps/v1"
v2 "k8s.io/api/autoscaling/v2"
autoscalingv2 "k8s.io/api/autoscaling/v2"
_ "k8s.io/api/autoscaling/v2beta2"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
Expand Down Expand Up @@ -170,7 +169,7 @@ func (r *replicaSetInfo) deploymentName() string {
// TODO(rgrandl): test to see if it works with an app where a component foo is
// collocated with main, and a component bar that is not collocated with main
// calls foo.
func (r *replicaSetInfo) buildDeployment() (*v1.Deployment, error) {
func (r *replicaSetInfo) buildDeployment() (*appsv1.Deployment, error) {
matchLabels := map[string]string{}
podLabels := map[string]string{
"appName": r.dep.App.Name,
Expand Down Expand Up @@ -215,9 +214,9 @@ func (r *replicaSetInfo) buildDeployment() (*v1.Deployment, error) {
Containers: []corev1.Container{container},
},
},
Strategy: v1.DeploymentStrategy{
Strategy: appsv1.DeploymentStrategy{
Type: "RollingUpdate",
RollingUpdate: &v1.RollingUpdateDeployment{},
RollingUpdate: &appsv1.RollingUpdateDeployment{},
},
// Number of old ReplicaSets to retain to allow rollback.
RevisionHistoryLimit: ptrOf(int32(1)),
Expand Down Expand Up @@ -272,7 +271,7 @@ func (r *replicaSetInfo) buildListenerService(lis *ReplicaSetConfig_Listener) (*
}

// buildAutoscaler generates a kubernetes horizontal pod autoscaler for a replica set.
func (r *replicaSetInfo) buildAutoscaler() (*v2.HorizontalPodAutoscaler, error) {
func (r *replicaSetInfo) buildAutoscaler() (*autoscalingv2.HorizontalPodAutoscaler, error) {
// Per deployment name that is app version specific.
aname := name{r.dep.App.Name, "hpa", r.name, r.dep.Id[:8]}.DNSLabel()

Expand All @@ -282,7 +281,7 @@ func (r *replicaSetInfo) buildAutoscaler() (*v2.HorizontalPodAutoscaler, error)
} else {
depName = r.deploymentName()
}
return &v2.HorizontalPodAutoscaler{
return &autoscalingv2.HorizontalPodAutoscaler{
TypeMeta: metav1.TypeMeta{
APIVersion: "autoscaling/v2",
Kind: "HorizontalPodAutoscaler",
Expand All @@ -291,23 +290,23 @@ func (r *replicaSetInfo) buildAutoscaler() (*v2.HorizontalPodAutoscaler, error)
Name: aname,
Namespace: r.namespace,
},
Spec: v2.HorizontalPodAutoscalerSpec{
ScaleTargetRef: v2.CrossVersionObjectReference{
Spec: autoscalingv2.HorizontalPodAutoscalerSpec{
ScaleTargetRef: autoscalingv2.CrossVersionObjectReference{
APIVersion: "apps/v1",
Kind: "Deployment",
Name: depName,
},
MinReplicas: ptrOf(int32(1)),
MaxReplicas: 10,
Metrics: []v2.MetricSpec{
Metrics: []autoscalingv2.MetricSpec{
{
// The pods are scaled up/down when the average CPU
// utilization is above/below 80%.
Type: v2.ResourceMetricSourceType,
Resource: &v2.ResourceMetricSource{
Type: autoscalingv2.ResourceMetricSourceType,
Resource: &autoscalingv2.ResourceMetricSource{
Name: corev1.ResourceCPU,
Target: v2.MetricTarget{
Type: v2.UtilizationMetricType,
Target: autoscalingv2.MetricTarget{
Type: autoscalingv2.UtilizationMetricType,
AverageUtilization: ptrOf(int32(80)),
},
},
Expand Down
21 changes: 10 additions & 11 deletions internal/impl/observability.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

"github.com/ServiceWeaver/weaver/runtime/protos"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/apps/v1"
_ "k8s.io/api/autoscaling/v2beta2"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -252,9 +251,9 @@ func generateConfigsToExportTraces(dep *protos.Deployment, cfg *KubeConfig) ([]b
},
},
},
Strategy: v1.DeploymentStrategy{
Strategy: appsv1.DeploymentStrategy{
Type: "RollingUpdate",
RollingUpdate: &v1.RollingUpdateDeployment{},
RollingUpdate: &appsv1.RollingUpdateDeployment{},
},
},
}
Expand Down Expand Up @@ -525,9 +524,9 @@ func generatePrometheusServiceConfigs(dep *protos.Deployment, cfg *KubeConfig) (
},
},
},
Strategy: v1.DeploymentStrategy{
Strategy: appsv1.DeploymentStrategy{
Type: "RollingUpdate",
RollingUpdate: &v1.RollingUpdateDeployment{},
RollingUpdate: &appsv1.RollingUpdateDeployment{},
},
},
}
Expand Down Expand Up @@ -923,9 +922,9 @@ func generateLokiServiceConfigs(dep *protos.Deployment, cfg *KubeConfig) ([]byte
},
},
},
Strategy: v1.DeploymentStrategy{
Strategy: appsv1.DeploymentStrategy{
Type: "RollingUpdate",
RollingUpdate: &v1.RollingUpdateDeployment{},
RollingUpdate: &appsv1.RollingUpdateDeployment{},
},
},
}
Expand Down Expand Up @@ -1091,9 +1090,9 @@ func generatePromtailAgentConfigs(dep *protos.Deployment, cfg *KubeConfig) ([]by
},
},
},
UpdateStrategy: v1.DaemonSetUpdateStrategy{
UpdateStrategy: appsv1.DaemonSetUpdateStrategy{
Type: "RollingUpdate",
RollingUpdate: &v1.RollingUpdateDaemonSet{},
RollingUpdate: &appsv1.RollingUpdateDaemonSet{},
},
},
}
Expand Down Expand Up @@ -1438,9 +1437,9 @@ func generateGrafanaServiceConfigs(dep *protos.Deployment, cfg *KubeConfig) ([]b
},
},
},
Strategy: v1.DeploymentStrategy{
Strategy: appsv1.DeploymentStrategy{
Type: "RollingUpdate",
RollingUpdate: &v1.RollingUpdateDeployment{},
RollingUpdate: &appsv1.RollingUpdateDeployment{},
},
},
}
Expand Down

0 comments on commit 668da16

Please sign in to comment.