Skip to content

Commit

Permalink
remove usage of clusterName to upgrade k8s
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecutalo committed Jun 23, 2023
1 parent 0084ab4 commit 2ce836a
Show file tree
Hide file tree
Showing 27 changed files with 248 additions and 223 deletions.
27 changes: 17 additions & 10 deletions backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ require (
google.golang.org/protobuf v1.30.0
gopkg.in/square/go-jose.v2 v2.6.0
gopkg.in/yaml.v3 v3.0.1
k8s.io/api v0.23.6
k8s.io/apimachinery v0.23.6
k8s.io/client-go v0.23.6
k8s.io/metrics v0.23.6
k8s.io/api v0.27.3
k8s.io/apimachinery v0.27.3
k8s.io/client-go v0.27.3
k8s.io/metrics v0.27.3
k8s.io/utils v0.0.0-20230220204549-a5ecb0141aa5
)

Expand Down Expand Up @@ -89,37 +89,44 @@ require (
github.com/cloudflare/circl v1.1.0 // indirect
github.com/cncf/xds/go v0.0.0-20230105202645-06c439db220b // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
github.com/go-logr/logr v1.2.2 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.1 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/gofrs/uuid v4.0.0+incompatible // indirect
github.com/gogo/googleapis v1.4.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/glog v1.0.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/googleapis/gnostic v0.5.5 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
github.com/lyft/protoc-gen-star v0.6.1 // 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
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pjbgf/sha1cd v0.2.4-0.20230130103033-0066bacacbf6 // indirect
github.com/pkg/errors v0.9.1 // indirect
Expand Down Expand Up @@ -153,9 +160,9 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
k8s.io/klog/v2 v2.80.1 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
k8s.io/klog/v2 v2.90.1 // indirect
k8s.io/kube-openapi v0.0.0-20230501164219-8b0f38b5fd1f // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
)
140 changes: 39 additions & 101 deletions backend/go.sum

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions backend/service/k8s/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ func TestProcessInformerEvent(t *testing.T) {

pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
ClusterName: "cluster",
Name: "test-pod-1",
Namespace: "testing-namespace",
Name: "test-pod-1",
Namespace: "testing-namespace",
Labels: map[string]string{
clusterClutchNameLabel: "cluster",
},
},
}

Expand Down
3 changes: 1 addition & 2 deletions backend/service/k8s/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ func (s *svc) DescribeConfigMap(ctx context.Context, clientset, cluster, namespa
configMapList, err := cs.CoreV1().ConfigMaps(cs.Namespace()).List(ctx, metav1.ListOptions{
FieldSelector: "metadata.name=" + name,
})

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -70,7 +69,7 @@ func (s *svc) ListConfigMaps(ctx context.Context, clientset, cluster, namespace
}

func protoForConfigMap(cluster string, k8sconfigMap *v1.ConfigMap) *k8sapiv1.ConfigMap {
clusterName := k8sconfigMap.ClusterName
clusterName := GetKubeCluster(k8sconfigMap)
if clusterName == "" {
clusterName = cluster
}
Expand Down
14 changes: 10 additions & 4 deletions backend/service/k8s/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func TestDeleteConfigMap(t *testing.T) {
func TestProtoForConfigMap(t *testing.T) {
t.Parallel()

var configMapTestCases = []struct {
configMapTestCases := []struct {
id string
inputClusterName string
expectedClusterName string
Expand All @@ -170,7 +170,9 @@ func TestProtoForConfigMap(t *testing.T) {
expectedClusterName: "production",
configMap: &v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
ClusterName: "production",
Labels: map[string]string{
"cluster.clutch.sh/name": "production",
},
},
},
},
Expand All @@ -180,7 +182,9 @@ func TestProtoForConfigMap(t *testing.T) {
expectedClusterName: "staging",
configMap: &v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
ClusterName: "",
Labels: map[string]string{
"cluster.clutch.sh/name": "production",
},
},
},
},
Expand All @@ -190,7 +194,9 @@ func TestProtoForConfigMap(t *testing.T) {
expectedClusterName: "test",
configMap: &v1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
ClusterName: "",
Labels: map[string]string{
"cluster.clutch.sh/name": "production",
},
},
Data: map[string]string{
"key1": "value1",
Expand Down
2 changes: 1 addition & 1 deletion backend/service/k8s/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (s *svc) DeleteCronJob(ctx context.Context, clientset, cluster, namespace,
}

func ProtoForCronJob(cluster string, k8scronJob *v1beta1.CronJob) *k8sapiv1.CronJob {
clusterName := k8scronJob.ClusterName
clusterName := GetKubeCluster(k8scronJob)
if clusterName == "" {
clusterName = cluster
}
Expand Down
14 changes: 9 additions & 5 deletions backend/service/k8s/cronjob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestDeleteCron(t *testing.T) {
func TestProtoForCron(t *testing.T) {
t.Parallel()

var cronTestCases = []struct {
cronTestCases := []struct {
id string
inputClusterName string
expectedClusterName string
Expand All @@ -87,8 +87,10 @@ func TestProtoForCron(t *testing.T) {
expectedName: "test1",
cron: &v1beta1.CronJob{
ObjectMeta: metav1.ObjectMeta{
ClusterName: "production",
Name: "test1",
Labels: map[string]string{
clusterClutchNameLabel: "production",
},
Name: "test1",
},
},
},
Expand All @@ -99,8 +101,10 @@ func TestProtoForCron(t *testing.T) {
expectedName: "test2",
cron: &v1beta1.CronJob{
ObjectMeta: metav1.ObjectMeta{
ClusterName: "",
Name: "test2",
Labels: map[string]string{
clusterClutchNameLabel: "",
},
Name: "test2",
},
Spec: v1beta1.CronJobSpec{
ConcurrencyPolicy: v1beta1.AllowConcurrent,
Expand Down
2 changes: 1 addition & 1 deletion backend/service/k8s/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (s *svc) ListDeployments(ctx context.Context, clientset, cluster, namespace
}

func ProtoForDeployment(cluster string, deployment *appsv1.Deployment) *k8sapiv1.Deployment {
clusterName := deployment.ClusterName
clusterName := GetKubeCluster(deployment)
if clusterName == "" {
clusterName = cluster
}
Expand Down
20 changes: 11 additions & 9 deletions backend/service/k8s/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ import (
k8sapiv1 "github.com/lyft/clutch/backend/api/k8s/v1"
)

var (
t1 = time.Date(2021, time.May, 4, 0, 0, 0, 0, time.UTC)
)
var t1 = time.Date(2021, time.May, 4, 0, 0, 0, 0, time.UTC)

func testDeploymentClientset() k8s.Interface {
deployment := &appsv1.Deployment{
Expand Down Expand Up @@ -125,7 +123,7 @@ func TestDeleteDeployment(t *testing.T) {
func TestMergeDeploymentLabelsAndAnnotations(t *testing.T) {
t.Parallel()

var mergeDeploymentLabelAnnotationsTestCases = []struct {
mergeDeploymentLabelAnnotationsTestCases := []struct {
id string
fields *k8sapiv1.UpdateDeploymentRequest_Fields
expect *appsv1.Deployment
Expand Down Expand Up @@ -216,7 +214,7 @@ func TestMergeDeploymentLabelsAndAnnotations(t *testing.T) {
func TestProtoForDeploymentClusterName(t *testing.T) {
t.Parallel()

var deploymentTestCases = []struct {
deploymentTestCases := []struct {
id string
inputClusterName string
expectedClusterName string
Expand All @@ -228,7 +226,9 @@ func TestProtoForDeploymentClusterName(t *testing.T) {
expectedClusterName: "production",
deployment: &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
ClusterName: "production",
Labels: map[string]string{
clusterClutchNameLabel: "production",
},
},
},
},
Expand All @@ -238,7 +238,9 @@ func TestProtoForDeploymentClusterName(t *testing.T) {
expectedClusterName: "staging",
deployment: &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
ClusterName: "",
Labels: map[string]string{
clusterClutchNameLabel: "",
},
},
},
},
Expand All @@ -258,7 +260,7 @@ func TestProtoForDeploymentClusterName(t *testing.T) {
func TestProtoForDeploymentSpec(t *testing.T) {
t.Parallel()

var deploymentTestCases = []struct {
deploymentTestCases := []struct {
id string
deployment *appsv1.Deployment
}{
Expand Down Expand Up @@ -306,7 +308,7 @@ func TestProtoForDeploymentSpec(t *testing.T) {
func TestProtoForDeploymentStatus(t *testing.T) {
t.Parallel()

var deploymentTestCases = []struct {
deploymentTestCases := []struct {
id string
deployment *appsv1.Deployment
}{
Expand Down
2 changes: 1 addition & 1 deletion backend/service/k8s/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (s *svc) ListEvents(ctx context.Context, clientset, cluster, namespace, obj
}

func ProtoForEvent(cluster string, k8sEvent *corev1.Event) *k8sapiv1.Event {
clusterName := k8sEvent.ClusterName
clusterName := GetKubeCluster(k8sEvent)
if clusterName == "" {
clusterName = cluster
}
Expand Down
2 changes: 1 addition & 1 deletion backend/service/k8s/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (s *svc) DescribeHPA(ctx context.Context, clientset, cluster, namespace, na
}

func ProtoForHPA(cluster string, autoscaler *autoscalingv1.HorizontalPodAutoscaler) *k8sapiv1.HPA {
clusterName := autoscaler.ClusterName
clusterName := GetKubeCluster(autoscaler)
if clusterName == "" {
clusterName = cluster
}
Expand Down
16 changes: 9 additions & 7 deletions backend/service/k8s/hpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ import (
k8sapiv1 "github.com/lyft/clutch/backend/api/k8s/v1"
)

var (
newInt32 = func(n int32) *int32 { return &n }
)
var newInt32 = func(n int32) *int32 { return &n }

func testHPAClientset() k8s.Interface {
hpa := &autoscalingv1.HorizontalPodAutoscaler{
Expand All @@ -33,7 +31,7 @@ func testHPAClientset() k8s.Interface {
func TestNormalizeChanges(t *testing.T) {
t.Parallel()

var applyScalingTestCases = []struct {
applyScalingTestCases := []struct {
id string
sizing *k8sapiv1.ResizeHPARequest_Sizing
resultSpec autoscalingv1.HorizontalPodAutoscalerSpec
Expand Down Expand Up @@ -124,7 +122,7 @@ func TestResizeHPA(t *testing.T) {
func TestProtoForHPAClusterName(t *testing.T) {
t.Parallel()

var hpaTestCases = []struct {
hpaTestCases := []struct {
id string
inputClusterName string
expectedClusterName string
Expand All @@ -136,7 +134,9 @@ func TestProtoForHPAClusterName(t *testing.T) {
expectedClusterName: "production",
hpa: &autoscalingv1.HorizontalPodAutoscaler{
ObjectMeta: metav1.ObjectMeta{
ClusterName: "production",
Labels: map[string]string{
clusterClutchNameLabel: "production",
},
},
Spec: autoscalingv1.HorizontalPodAutoscalerSpec{
MinReplicas: newInt32(1),
Expand All @@ -150,7 +150,9 @@ func TestProtoForHPAClusterName(t *testing.T) {
expectedClusterName: "staging",
hpa: &autoscalingv1.HorizontalPodAutoscaler{
ObjectMeta: metav1.ObjectMeta{
ClusterName: "",
Labels: map[string]string{
clusterClutchNameLabel: "",
},
},
Spec: autoscalingv1.HorizontalPodAutoscalerSpec{
MinReplicas: newInt32(1),
Expand Down
2 changes: 1 addition & 1 deletion backend/service/k8s/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (s *svc) ListJobs(ctx context.Context, clientset, cluster, namespace string
}

func protoForJob(cluster string, k8sJob *v1.Job) *k8sapiv1.Job {
clusterName := k8sJob.ClusterName
clusterName := GetKubeCluster(k8sJob)
if clusterName == "" {
clusterName = cluster
}
Expand Down
10 changes: 7 additions & 3 deletions backend/service/k8s/job_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func TestCreateJob(t *testing.T) {
func TestProtoForJob(t *testing.T) {
t.Parallel()

var jobTestCases = []struct {
jobTestCases := []struct {
id string
inputClusterName string
expectedClusterName string
Expand All @@ -184,7 +184,9 @@ func TestProtoForJob(t *testing.T) {
expectedClusterName: "production",
job: &v1.Job{
ObjectMeta: metav1.ObjectMeta{
ClusterName: "production",
Labels: map[string]string{
clusterClutchNameLabel: "production",
},
},
},
},
Expand All @@ -194,7 +196,9 @@ func TestProtoForJob(t *testing.T) {
expectedClusterName: "staging",
job: &v1.Job{
ObjectMeta: metav1.ObjectMeta{
ClusterName: "",
Labels: map[string]string{
clusterClutchNameLabel: "production",
},
},
},
},
Expand Down
Loading

0 comments on commit 2ce836a

Please sign in to comment.