Skip to content

Commit

Permalink
Merge pull request #2466 from mrueg/drop-dynamic-client
Browse files Browse the repository at this point in the history
chore: Add unused linter
  • Loading branch information
k8s-ci-robot authored Aug 6, 2024
2 parents b1c2e0c + ab06f81 commit f8aa7d9
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 44 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ linters:
- revive
- staticcheck
- unconvert
- unused

linters-settings:
goimports:
Expand Down
21 changes: 10 additions & 11 deletions internal/discovery/discovery_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/*
Copyright 2023 The Kubernetes Authors All rights reserved.
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
http://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.
Copyright 2023 The Kubernetes Authors All rights reserved.
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
http://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 discovery
Expand All @@ -26,7 +26,6 @@ func TestGVKMapsResolveGVK(t *testing.T) {
desc string
gvkmaps *CRDiscoverer
gvk schema.GroupVersionKind
got []groupVersionKindPlural
want []groupVersionKindPlural
}
testcases := []testcase{
Expand Down
4 changes: 0 additions & 4 deletions internal/store/networkpolicy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ func TestNetworkPolicyStore(t *testing.T) {
startTime := 1501569018
metav1StartTime := metav1.Unix(int64(startTime), 0)

const metadata = `
# HELP kube_verticalpodautoscaler_labels Kubernetes labels converted to Prometheus labels.
# TYPE kube_verticalpodautoscaler_labels gauge
`
cases := []generateMetricsTestCase{
{
Obj: &networkingv1.NetworkPolicy{
Expand Down
11 changes: 0 additions & 11 deletions pkg/metrics_store/metrics_store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ import (
"k8s.io/kube-state-metrics/v2/pkg/metric"
)

// Mock metricFamily instead of importing /pkg/metric to prevent cyclic
// dependency.
type metricFamily struct {
value []byte
}

// Implement FamilyByteSlicer interface.
func (f *metricFamily) ByteSlice() []byte {
return f.value
}

func TestObjectsSameNameDifferentNamespaces(t *testing.T) {
serviceIDs := []string{"a", "b"}

Expand Down
18 changes: 0 additions & 18 deletions pkg/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/discovery"
"k8s.io/client-go/dynamic"
clientset "k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
Expand All @@ -40,7 +39,6 @@ import (
var config *rest.Config
var currentKubeClient clientset.Interface
var currentDiscoveryClient *discovery.DiscoveryClient
var currentDynamicClient *dynamic.DynamicClient

// CreateKubeClient creates a Kubernetes clientset and a custom resource clientset.
func CreateKubeClient(apiserver string, kubeconfig string) (clientset.Interface, error) {
Expand Down Expand Up @@ -120,22 +118,6 @@ func CreateDiscoveryClient(apiserver string, kubeconfig string) (*discovery.Disc
return currentDiscoveryClient, err
}

// CreateDynamicClient creates a Kubernetes dynamic client.
func CreateDynamicClient(apiserver string, kubeconfig string) (*dynamic.DynamicClient, error) {
if currentDynamicClient != nil {
return currentDynamicClient, nil
}
var err error
if config == nil {
config, err = clientcmd.BuildConfigFromFlags(apiserver, kubeconfig)
if err != nil {
return nil, err
}
}
currentDynamicClient, err = dynamic.NewForConfig(config)
return currentDynamicClient, err
}

// GVRFromType returns the GroupVersionResource for a given type.
func GVRFromType(resourceName string, expectedType interface{}) *schema.GroupVersionResource {
if _, ok := expectedType.(*testUnstructuredMock.Foo); ok {
Expand Down

0 comments on commit f8aa7d9

Please sign in to comment.