Skip to content
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

Migrate ingress and certificates away from deprecated APIs #1260

Merged
merged 6 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/autosharding/cluster-role-binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: ClusterRoleBinding
metadata:
labels:
app.kubernetes.io/name: kube-state-metrics
app.kubernetes.io/version: 2.0.0-alpha
app.kubernetes.io/version: 2.0.0-alpha.1
name: kube-state-metrics
roleRef:
apiGroup: rbac.authorization.k8s.io
Expand Down
4 changes: 2 additions & 2 deletions examples/autosharding/cluster-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: ClusterRole
metadata:
labels:
app.kubernetes.io/name: kube-state-metrics
app.kubernetes.io/version: 2.0.0-alpha
app.kubernetes.io/version: 2.0.0-alpha.1
name: kube-state-metrics
rules:
- apiGroups:
Expand All @@ -30,7 +30,6 @@ rules:
- daemonsets
- deployments
- replicasets
- ingresses
verbs:
- list
- watch
Expand Down Expand Up @@ -105,6 +104,7 @@ rules:
- networking.k8s.io
resources:
- networkpolicies
- ingresses
verbs:
- list
- watch
Expand Down
3 changes: 2 additions & 1 deletion examples/autosharding/role-binding.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ kind: RoleBinding
metadata:
labels:
app.kubernetes.io/name: kube-state-metrics
app.kubernetes.io/version: 2.0.0-alpha
app.kubernetes.io/version: 2.0.0-alpha.1
name: kube-state-metrics
namespace: kube-system
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
Expand Down
2 changes: 1 addition & 1 deletion examples/autosharding/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Role
metadata:
labels:
app.kubernetes.io/name: kube-state-metrics
app.kubernetes.io/version: 2.0.0-alpha
app.kubernetes.io/version: 2.0.0-alpha.1
name: kube-state-metrics
namespace: kube-system
rules:
Expand Down
2 changes: 1 addition & 1 deletion examples/autosharding/service-account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ kind: ServiceAccount
metadata:
labels:
app.kubernetes.io/name: kube-state-metrics
app.kubernetes.io/version: 2.0.0-alpha
app.kubernetes.io/version: 2.0.0-alpha.1
name: kube-state-metrics
namespace: kube-system
2 changes: 1 addition & 1 deletion examples/autosharding/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: Service
metadata:
labels:
app.kubernetes.io/name: kube-state-metrics
app.kubernetes.io/version: 2.0.0-alpha
app.kubernetes.io/version: 2.0.0-alpha.1
name: kube-state-metrics
namespace: kube-system
spec:
Expand Down
6 changes: 3 additions & 3 deletions examples/autosharding/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kind: StatefulSet
metadata:
labels:
app.kubernetes.io/name: kube-state-metrics
app.kubernetes.io/version: 2.0.0-alpha
app.kubernetes.io/version: 2.0.0-alpha.1
name: kube-state-metrics
namespace: kube-system
spec:
Expand All @@ -16,7 +16,7 @@ spec:
metadata:
labels:
app.kubernetes.io/name: kube-state-metrics
app.kubernetes.io/version: 2.0.0-alpha
app.kubernetes.io/version: 2.0.0-alpha.1
spec:
containers:
- args:
Expand All @@ -33,7 +33,7 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: quay.io/coreos/kube-state-metrics:v2.0.0-alpha
image: quay.io/coreos/kube-state-metrics:v2.0.0-alpha.1
livenessProbe:
httpGet:
path: /healthz
Expand Down
2 changes: 1 addition & 1 deletion examples/standard/cluster-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ rules:
- daemonsets
- deployments
- replicasets
- ingresses
verbs:
- list
- watch
Expand Down Expand Up @@ -105,6 +104,7 @@ rules:
- networking.k8s.io
resources:
- networkpolicies
- ingresses
verbs:
- list
- watch
Expand Down
7 changes: 3 additions & 4 deletions internal/store/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ import (
autoscaling "k8s.io/api/autoscaling/v2beta1"
batchv1 "k8s.io/api/batch/v1"
batchv1beta1 "k8s.io/api/batch/v1beta1"
certv1beta1 "k8s.io/api/certificates/v1beta1"
certv1 "k8s.io/api/certificates/v1"
coordinationv1 "k8s.io/api/coordination/v1"
v1 "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
networkingv1 "k8s.io/api/networking/v1"
policy "k8s.io/api/policy/v1beta1"
storagev1 "k8s.io/api/storage/v1"
Expand Down Expand Up @@ -235,7 +234,7 @@ func (b *Builder) buildHPAStore() cache.Store {
}

func (b *Builder) buildIngressStore() cache.Store {
return b.buildStoreFunc(ingressMetricFamilies, &extensions.Ingress{}, createIngressListWatch)
return b.buildStoreFunc(ingressMetricFamilies, &networkingv1.Ingress{}, createIngressListWatch)
}

func (b *Builder) buildJobStore() cache.Store {
Expand Down Expand Up @@ -307,7 +306,7 @@ func (b *Builder) buildPodStore() cache.Store {
}

func (b *Builder) buildCsrStore() cache.Store {
return b.buildStoreFunc(csrMetricFamilies, &certv1beta1.CertificateSigningRequest{}, createCSRListWatch)
return b.buildStoreFunc(csrMetricFamilies, &certv1.CertificateSigningRequest{}, createCSRListWatch)
}

func (b *Builder) buildValidatingWebhookConfigurationStore() cache.Store {
Expand Down
25 changes: 12 additions & 13 deletions internal/store/certificatesigningrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"k8s.io/kube-state-metrics/v2/pkg/metric"
generator "k8s.io/kube-state-metrics/v2/pkg/metric_generator"

certv1beta1 "k8s.io/api/certificates/v1beta1"
certv1 "k8s.io/api/certificates/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/watch"
Expand All @@ -41,7 +41,7 @@ var (
descCSRLabelsHelp,
metric.Gauge,
"",
wrapCSRFunc(func(j *certv1beta1.CertificateSigningRequest) *metric.Family {
wrapCSRFunc(func(j *certv1.CertificateSigningRequest) *metric.Family {
labelKeys, labelValues := kubeLabelsToPrometheusLabels(j.Labels)
return &metric.Family{
Metrics: []*metric.Metric{
Expand All @@ -59,7 +59,7 @@ var (
"Unix creation timestamp",
metric.Gauge,
"",
wrapCSRFunc(func(csr *certv1beta1.CertificateSigningRequest) *metric.Family {
wrapCSRFunc(func(csr *certv1.CertificateSigningRequest) *metric.Family {
ms := []*metric.Metric{}
if !csr.CreationTimestamp.IsZero() {
ms = append(ms, &metric.Metric{
Expand All @@ -79,7 +79,7 @@ var (
"The number of each certificatesigningrequest condition",
metric.Gauge,
"",
wrapCSRFunc(func(csr *certv1beta1.CertificateSigningRequest) *metric.Family {
wrapCSRFunc(func(csr *certv1.CertificateSigningRequest) *metric.Family {
return &metric.Family{
Metrics: addCSRConditionMetrics(csr.Status),
}
Expand All @@ -90,7 +90,7 @@ var (
"Length of the issued cert",
metric.Gauge,
"",
wrapCSRFunc(func(csr *certv1beta1.CertificateSigningRequest) *metric.Family {
wrapCSRFunc(func(csr *certv1.CertificateSigningRequest) *metric.Family {
return &metric.Family{
Metrics: []*metric.Metric{
{
Expand All @@ -105,10 +105,9 @@ var (
}
)

func wrapCSRFunc(f func(*certv1beta1.CertificateSigningRequest) *metric.Family) func(interface{}) *metric.Family {
func wrapCSRFunc(f func(*certv1.CertificateSigningRequest) *metric.Family) func(interface{}) *metric.Family {
return func(obj interface{}) *metric.Family {
csr := obj.(*certv1beta1.CertificateSigningRequest)

csr := obj.(*certv1.CertificateSigningRequest)
metricFamily := f(csr)

for _, m := range metricFamily.Metrics {
Expand All @@ -123,23 +122,23 @@ func wrapCSRFunc(f func(*certv1beta1.CertificateSigningRequest) *metric.Family)
func createCSRListWatch(kubeClient clientset.Interface, ns string) cache.ListerWatcher {
return &cache.ListWatch{
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
return kubeClient.CertificatesV1beta1().CertificateSigningRequests().List(context.TODO(), opts)
return kubeClient.CertificatesV1().CertificateSigningRequests().List(context.TODO(), opts)
},
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
return kubeClient.CertificatesV1beta1().CertificateSigningRequests().Watch(context.TODO(), opts)
return kubeClient.CertificatesV1().CertificateSigningRequests().Watch(context.TODO(), opts)
},
}
}

// addCSRConditionMetrics generates one metric for each possible csr condition status
func addCSRConditionMetrics(cs certv1beta1.CertificateSigningRequestStatus) []*metric.Metric {
func addCSRConditionMetrics(cs certv1.CertificateSigningRequestStatus) []*metric.Metric {
cApproved := 0
cDenied := 0
for _, s := range cs.Conditions {
if s.Type == certv1beta1.CertificateApproved {
if s.Type == certv1.CertificateApproved {
cApproved++
}
if s.Type == certv1beta1.CertificateDenied {
if s.Type == certv1.CertificateDenied {
cDenied++
}
}
Expand Down
Loading