1
0
Fork 0
mirror of https://github.com/prometheus-operator/prometheus-operator.git synced 2025-04-16 09:16:38 +00:00

*: remove Kube API versions dropped in v1.22

Kubernetes v1.22 will stop serving API versions that were deprecated a
while ago. This change cleans up any reference to these API versions in
the operator's code and documentation.

[1] https://kubernetes.io/docs/reference/using-api/deprecation-guide/#v1-22

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
Simon Pasquier 2021-07-16 11:39:09 +02:00
parent 63b3840645
commit e785105f35
15 changed files with 106 additions and 98 deletions

View file

@ -135,7 +135,7 @@ In addition to the resources Prometheus itself needs to access, the Prometheus s
[embedmd]:# (../example/rbac/prometheus/prometheus-cluster-role.yaml) [embedmd]:# (../example/rbac/prometheus/prometheus-cluster-role.yaml)
```yaml ```yaml
apiVersion: rbac.authorization.k8s.io/v1beta1 apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole kind: ClusterRole
metadata: metadata:
name: prometheus name: prometheus
@ -222,7 +222,7 @@ And then because the `ClusterRole` named `prometheus`, as described above, is li
[embedmd]:# (../example/rbac/prometheus/prometheus-cluster-role-binding.yaml) [embedmd]:# (../example/rbac/prometheus/prometheus-cluster-role-binding.yaml)
```yaml ```yaml
apiVersion: rbac.authorization.k8s.io/v1beta1 apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding kind: ClusterRoleBinding
metadata: metadata:
name: prometheus name: prometheus

View file

@ -208,7 +208,7 @@ spec:
A corresponding Ingress object would be: A corresponding Ingress object would be:
```yaml ```yaml
apiVersion: extensions/v1beta1 apiVersion: extensions/v1
kind: Ingress kind: Ingress
metadata: metadata:
name: monitoring name: monitoring

View file

@ -108,7 +108,7 @@ metadata:
[embedmd]:# (../../example/rbac/prometheus/prometheus-cluster-role.yaml) [embedmd]:# (../../example/rbac/prometheus/prometheus-cluster-role.yaml)
```yaml ```yaml
apiVersion: rbac.authorization.k8s.io/v1beta1 apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole kind: ClusterRole
metadata: metadata:
name: prometheus name: prometheus
@ -136,7 +136,7 @@ rules:
[embedmd]:# (../../example/rbac/prometheus/prometheus-cluster-role-binding.yaml) [embedmd]:# (../../example/rbac/prometheus/prometheus-cluster-role-binding.yaml)
```yaml ```yaml
apiVersion: rbac.authorization.k8s.io/v1beta1 apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding kind: ClusterRoleBinding
metadata: metadata:
name: prometheus name: prometheus

View file

@ -1,4 +1,4 @@
apiVersion: rbac.authorization.k8s.io/v1beta1 apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding kind: ClusterRoleBinding
metadata: metadata:
name: prometheus name: prometheus

View file

@ -1,4 +1,4 @@
apiVersion: rbac.authorization.k8s.io/v1beta1 apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole kind: ClusterRole
metadata: metadata:
name: prometheus name: prometheus

View file

@ -1,4 +1,4 @@
apiVersion: rbac.authorization.k8s.io/v1beta1 apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding kind: ClusterRoleBinding
metadata: metadata:
name: prometheus name: prometheus

View file

@ -1,4 +1,4 @@
apiVersion: rbac.authorization.k8s.io/v1beta1 apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole kind: ClusterRole
metadata: metadata:
name: prometheus name: prometheus

View file

@ -1,4 +1,4 @@
apiVersion: storage.k8s.io/v1beta1 apiVersion: storage.k8s.io/v1
kind: StorageClass kind: StorageClass
metadata: metadata:
name: ssd name: ssd

View file

@ -18,19 +18,18 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
jsonpatch "github.com/evanphx/json-patch/v5"
"io/ioutil" "io/ioutil"
v1 "k8s.io/api/admission/v1"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os" "os"
"strings" "strings"
"testing" "testing"
jsonpatch "github.com/evanphx/json-patch/v5"
"github.com/go-kit/kit/log" "github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level" "github.com/go-kit/kit/log/level"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"k8s.io/api/admission/v1beta1" "k8s.io/api/admission/v1"
) )
func TestMutateRule(t *testing.T) { func TestMutateRule(t *testing.T) {
@ -182,7 +181,7 @@ func server(s serveFunc) *httptest.Server {
return httptest.NewServer(http.HandlerFunc(s)) return httptest.NewServer(http.HandlerFunc(s))
} }
func send(t *testing.T, ts *httptest.Server, rules []byte) *v1beta1.AdmissionReview { func send(t *testing.T, ts *httptest.Server, rules []byte) *v1.AdmissionReview {
resp, err := http.Post(ts.URL, "application/json", bytes.NewReader(rules)) resp, err := http.Post(ts.URL, "application/json", bytes.NewReader(rules))
if err != nil { if err != nil {
t.Errorf("Publish() returned an error: %s", err) t.Errorf("Publish() returned an error: %s", err)
@ -193,7 +192,7 @@ func send(t *testing.T, ts *httptest.Server, rules []byte) *v1beta1.AdmissionRev
t.Errorf("ioutil.ReadAll(resp.Body) returned an error: %s", err) t.Errorf("ioutil.ReadAll(resp.Body) returned an error: %s", err)
} }
rev := &v1beta1.AdmissionReview{} rev := &v1.AdmissionReview{}
if err := json.Unmarshal(body, rev); err != nil { if err := json.Unmarshal(body, rev); err != nil {
t.Errorf("unable to parse webhook response: %s", err) t.Errorf("unable to parse webhook response: %s", err)
} }
@ -204,7 +203,7 @@ func send(t *testing.T, ts *httptest.Server, rules []byte) *v1beta1.AdmissionRev
var goodRulesWithAnnotations = []byte(` var goodRulesWithAnnotations = []byte(`
{ {
"kind": "AdmissionReview", "kind": "AdmissionReview",
"apiVersion": "admission.k8s.io/v1beta1", "apiVersion": "admission.k8s.io/v1",
"request": { "request": {
"uid": "87c5df7f-5090-11e9-b9b4-02425473f309", "uid": "87c5df7f-5090-11e9-b9b4-02425473f309",
"kind": { "kind": {
@ -270,7 +269,7 @@ var goodRulesWithAnnotations = []byte(`
var goodRulesWithExternalLabelsInAnnotations = []byte(` var goodRulesWithExternalLabelsInAnnotations = []byte(`
{ {
"kind": "AdmissionReview", "kind": "AdmissionReview",
"apiVersion": "admission.k8s.io/v1beta1", "apiVersion": "admission.k8s.io/v1",
"request": { "request": {
"uid": "87c5df7f-5090-11e9-b9b4-02425473f309", "uid": "87c5df7f-5090-11e9-b9b4-02425473f309",
"kind": { "kind": {
@ -335,7 +334,7 @@ var goodRulesWithExternalLabelsInAnnotations = []byte(`
var badRulesNoAnnotations = []byte(` var badRulesNoAnnotations = []byte(`
{ {
"kind": "AdmissionReview", "kind": "AdmissionReview",
"apiVersion": "admission.k8s.io/v1beta1", "apiVersion": "admission.k8s.io/v1",
"request": { "request": {
"uid": "87c5df7f-5090-11e9-b9b4-02425473f309", "uid": "87c5df7f-5090-11e9-b9b4-02425473f309",
"kind": { "kind": {
@ -398,7 +397,7 @@ var badRulesNoAnnotations = []byte(`
var badRulesWithBooleanInAnnotations = []byte(` var badRulesWithBooleanInAnnotations = []byte(`
{ {
"kind": "AdmissionReview", "kind": "AdmissionReview",
"apiVersion": "admission.k8s.io/v1beta1", "apiVersion": "admission.k8s.io/v1",
"request": { "request": {
"uid": "87c5df7f-5090-11e9-b9b4-02425473f309", "uid": "87c5df7f-5090-11e9-b9b4-02425473f309",
"kind": { "kind": {
@ -465,7 +464,7 @@ var badRulesWithBooleanInAnnotations = []byte(`
var nonStringsInLabelsAnnotations = []byte(` var nonStringsInLabelsAnnotations = []byte(`
{ {
"kind": "AdmissionReview", "kind": "AdmissionReview",
"apiVersion": "admission.k8s.io/v1beta1", "apiVersion": "admission.k8s.io/v1",
"request": { "request": {
"uid": "87c5df7f-5090-11e9-b9b4-02425473f309", "uid": "87c5df7f-5090-11e9-b9b4-02425473f309",
"kind": { "kind": {

View file

@ -1,6 +1,6 @@
# Wide open access to the cluster (mostly for kubelet) # Wide open access to the cluster (mostly for kubelet)
kind: ClusterRole kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1 apiVersion: rbac.authorization.k8s.io/v1
metadata: metadata:
name: cluster-writer name: cluster-writer
rules: rules:
@ -14,7 +14,7 @@ rules:
# Full read access to the api and resources # Full read access to the api and resources
kind: ClusterRole kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1 apiVersion: rbac.authorization.k8s.io/v1
metadata: metadata:
name: cluster-reader name: cluster-reader
rules: rules:
@ -26,7 +26,7 @@ rules:
--- ---
# Give admin, kubelet, kube-system, kube-proxy god access # Give admin, kubelet, kube-system, kube-proxy god access
kind: ClusterRoleBinding kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1 apiVersion: rbac.authorization.k8s.io/v1
metadata: metadata:
name: cluster-write name: cluster-write
subjects: subjects:
@ -49,7 +49,7 @@ roleRef:
# Setup sd-build as a reader. This has to be a # Setup sd-build as a reader. This has to be a
# ClusterRoleBinding to get access to non-resource URLs # ClusterRoleBinding to get access to non-resource URLs
kind: ClusterRoleBinding kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1 apiVersion: rbac.authorization.k8s.io/v1
metadata: metadata:
name: cluster-read name: cluster-read
subjects: subjects:
@ -65,7 +65,7 @@ roleRef:
# Setup sd-build as a writer in its namespace # Setup sd-build as a writer in its namespace
kind: RoleBinding kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1 apiVersion: rbac.authorization.k8s.io/v1
metadata: metadata:
name: sd-build-write name: sd-build-write
subjects: subjects:

View file

@ -16,7 +16,7 @@ package framework
import ( import (
"github.com/pkg/errors" "github.com/pkg/errors"
"k8s.io/api/admissionregistration/v1beta1" "k8s.io/api/admissionregistration/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/yaml" "k8s.io/apimachinery/pkg/util/yaml"
) )
@ -30,7 +30,7 @@ func (f *Framework) createMutatingHook(certBytes []byte, namespace, yamlPath str
h.Webhooks[0].ClientConfig.Service.Namespace = namespace h.Webhooks[0].ClientConfig.Service.Namespace = namespace
h.Webhooks[0].ClientConfig.CABundle = certBytes h.Webhooks[0].ClientConfig.CABundle = certBytes
_, err = f.KubeClient.AdmissionregistrationV1beta1().MutatingWebhookConfigurations().Create(f.Ctx, h, metav1.CreateOptions{}) _, err = f.KubeClient.AdmissionregistrationV1().MutatingWebhookConfigurations().Create(f.Ctx, h, metav1.CreateOptions{})
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to create mutating webhook %s", h.Name) return nil, errors.Wrapf(err, "failed to create mutating webhook %s", h.Name)
} }
@ -49,7 +49,7 @@ func (f *Framework) createValidatingHook(certBytes []byte, namespace, yamlPath s
h.Webhooks[0].ClientConfig.Service.Namespace = namespace h.Webhooks[0].ClientConfig.Service.Namespace = namespace
h.Webhooks[0].ClientConfig.CABundle = certBytes h.Webhooks[0].ClientConfig.CABundle = certBytes
_, err = f.KubeClient.AdmissionregistrationV1beta1().ValidatingWebhookConfigurations().Create(f.Ctx, h, metav1.CreateOptions{}) _, err = f.KubeClient.AdmissionregistrationV1().ValidatingWebhookConfigurations().Create(f.Ctx, h, metav1.CreateOptions{})
if err != nil { if err != nil {
return nil, errors.Wrapf(err, "failed to create validating webhook %s", h.Name) return nil, errors.Wrapf(err, "failed to create validating webhook %s", h.Name)
} }
@ -60,20 +60,20 @@ func (f *Framework) createValidatingHook(certBytes []byte, namespace, yamlPath s
} }
func (f *Framework) deleteMutatingWebhook(name string) error { func (f *Framework) deleteMutatingWebhook(name string) error {
return f.KubeClient.AdmissionregistrationV1beta1().MutatingWebhookConfigurations().Delete(f.Ctx, name, metav1.DeleteOptions{}) return f.KubeClient.AdmissionregistrationV1().MutatingWebhookConfigurations().Delete(f.Ctx, name, metav1.DeleteOptions{})
} }
func (f *Framework) deleteValidatingWebhook(name string) error { func (f *Framework) deleteValidatingWebhook(name string) error {
return f.KubeClient.AdmissionregistrationV1beta1().ValidatingWebhookConfigurations().Delete(f.Ctx, name, metav1.DeleteOptions{}) return f.KubeClient.AdmissionregistrationV1().ValidatingWebhookConfigurations().Delete(f.Ctx, name, metav1.DeleteOptions{})
} }
func parseValidatingHookYaml(pathToYaml string) (*v1beta1.ValidatingWebhookConfiguration, error) { func parseValidatingHookYaml(pathToYaml string) (*v1.ValidatingWebhookConfiguration, error) {
manifest, err := PathToOSFile(pathToYaml) manifest, err := PathToOSFile(pathToYaml)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resource := v1beta1.ValidatingWebhookConfiguration{} resource := v1.ValidatingWebhookConfiguration{}
if err := yaml.NewYAMLOrJSONDecoder(manifest, 100).Decode(&resource); err != nil { if err := yaml.NewYAMLOrJSONDecoder(manifest, 100).Decode(&resource); err != nil {
return nil, errors.Wrapf(err, "failed to decode file %s", pathToYaml) return nil, errors.Wrapf(err, "failed to decode file %s", pathToYaml)
} }
@ -81,13 +81,13 @@ func parseValidatingHookYaml(pathToYaml string) (*v1beta1.ValidatingWebhookConfi
return &resource, nil return &resource, nil
} }
func parseMutatingHookYaml(pathToYaml string) (*v1beta1.MutatingWebhookConfiguration, error) { func parseMutatingHookYaml(pathToYaml string) (*v1.MutatingWebhookConfiguration, error) {
manifest, err := PathToOSFile(pathToYaml) manifest, err := PathToOSFile(pathToYaml)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resource := v1beta1.MutatingWebhookConfiguration{} resource := v1.MutatingWebhookConfiguration{}
if err := yaml.NewYAMLOrJSONDecoder(manifest, 100).Decode(&resource); err != nil { if err := yaml.NewYAMLOrJSONDecoder(manifest, 100).Decode(&resource); err != nil {
return nil, errors.Wrapf(err, "failed to decode file %s", pathToYaml) return nil, errors.Wrapf(err, "failed to decode file %s", pathToYaml)
} }

View file

@ -21,28 +21,31 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1" networkv1 "k8s.io/api/networking/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/util/yaml" "k8s.io/apimachinery/pkg/util/yaml"
) )
func MakeBasicIngress(serviceName string, servicePort int) *v1beta1.Ingress { func MakeBasicIngress(serviceName string, servicePort int) *networkv1.Ingress {
return &v1beta1.Ingress{ return &networkv1.Ingress{
ObjectMeta: metav1.ObjectMeta{ ObjectMeta: metav1.ObjectMeta{
Name: "monitoring", Name: "monitoring",
}, },
Spec: v1beta1.IngressSpec{ Spec: networkv1.IngressSpec{
Rules: []v1beta1.IngressRule{ Rules: []networkv1.IngressRule{
{ {
IngressRuleValue: v1beta1.IngressRuleValue{ IngressRuleValue: networkv1.IngressRuleValue{
HTTP: &v1beta1.HTTPIngressRuleValue{ HTTP: &networkv1.HTTPIngressRuleValue{
Paths: []v1beta1.HTTPIngressPath{ Paths: []networkv1.HTTPIngressPath{
{ {
Backend: v1beta1.IngressBackend{ Backend: networkv1.IngressBackend{
ServiceName: serviceName, Service: &networkv1.IngressServiceBackend{
ServicePort: intstr.FromInt(servicePort), Name: serviceName,
Port: networkv1.ServiceBackendPort{
Number: int32(servicePort),
},
},
}, },
Path: "/metrics", Path: "/metrics",
}, },
@ -55,8 +58,8 @@ func MakeBasicIngress(serviceName string, servicePort int) *v1beta1.Ingress {
} }
} }
func (f *Framework) CreateIngress(namespace string, i *v1beta1.Ingress) error { func (f *Framework) CreateIngress(namespace string, i *networkv1.Ingress) error {
_, err := f.KubeClient.ExtensionsV1beta1().Ingresses(namespace).Create(f.Ctx, i, metav1.CreateOptions{}) _, err := f.KubeClient.NetworkingV1().Ingresses(namespace).Create(f.Ctx, i, metav1.CreateOptions{})
return errors.Wrap(err, fmt.Sprintf("creating ingress %v failed", i.Name)) return errors.Wrap(err, fmt.Sprintf("creating ingress %v failed", i.Name))
} }
@ -125,10 +128,10 @@ func (f *Framework) DeleteNginxIngressControllerIncDefaultBackend(namespace stri
} }
func (f *Framework) GetIngressIP(namespace string, ingressName string) (*string, error) { func (f *Framework) GetIngressIP(namespace string, ingressName string) (*string, error) {
var ingress *v1beta1.Ingress var ingress *networkv1.Ingress
err := wait.Poll(time.Millisecond*500, time.Minute*5, func() (bool, error) { err := wait.Poll(time.Millisecond*500, time.Minute*5, func() (bool, error) {
var err error var err error
ingress, err = f.KubeClient.ExtensionsV1beta1().Ingresses(namespace).Get(f.Ctx, ingressName, metav1.GetOptions{}) ingress, err = f.KubeClient.NetworkingV1().Ingresses(namespace).Get(f.Ctx, ingressName, metav1.GetOptions{})
if err != nil { if err != nil {
return false, errors.Wrap(err, fmt.Sprintf("requesting the ingress %v failed", ingressName)) return false, errors.Wrap(err, fmt.Sprintf("requesting the ingress %v failed", ingressName))
} }

View file

@ -1,24 +1,27 @@
apiVersion: admissionregistration.k8s.io/v1 apiVersion: admissionregistration.k8s.io/v1
kind: MutatingWebhookConfiguration kind: MutatingWebhookConfiguration
metadata: metadata:
name: prometheus-operator-rulesvalidation name: prometheus-operator-rulesvalidation
webhooks: webhooks:
- clientConfig: - clientConfig:
service: service:
name: prometheus-operator name: prometheus-operator
namespace: default namespace: default
path: /admission-prometheusrules/mutate path: /admission-prometheusrules/mutate
failurePolicy: Fail failurePolicy: Fail
name: prometheusrulemutate.monitoring.coreos.com name: prometheusrulemutate.monitoring.coreos.com
namespaceSelector: {} namespaceSelector: {}
rules: rules:
- apiGroups: - apiGroups:
- monitoring.coreos.com - monitoring.coreos.com
apiVersions: apiVersions:
- '*' - '*'
operations: operations:
- CREATE - CREATE
- UPDATE - UPDATE
resources: resources:
- prometheusrules - prometheusrules
sideEffects: None
admissionReviewVersions:
- v1

View file

@ -1,23 +1,26 @@
apiVersion: admissionregistration.k8s.io/v1 apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingWebhookConfiguration kind: ValidatingWebhookConfiguration
metadata: metadata:
name: prometheus-operator-rulesvalidation name: prometheus-operator-rulesvalidation
webhooks: webhooks:
- clientConfig: - clientConfig:
service: service:
name: prometheus-operator name: prometheus-operator
namespace: default namespace: default
path: /admission-prometheusrules/validate path: /admission-prometheusrules/validate
failurePolicy: Fail failurePolicy: Fail
name: prometheusrulemutate.monitoring.coreos.com name: prometheusrulemutate.monitoring.coreos.com
namespaceSelector: {} namespaceSelector: {}
rules: rules:
- apiGroups: - apiGroups:
- monitoring.coreos.com - monitoring.coreos.com
apiVersions: apiVersions:
- '*' - '*'
operations: operations:
- CREATE - CREATE
- UPDATE - UPDATE
resources: resources:
- prometheusrules - prometheusrules
sideEffects: None
admissionReviewVersions:
- v1

View file

@ -1,4 +1,4 @@
apiVersion: rbac.authorization.k8s.io/v1beta1 apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding kind: RoleBinding
metadata: metadata:
name: prometheus name: prometheus