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)
```yaml
apiVersion: rbac.authorization.k8s.io/v1beta1
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
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)
```yaml
apiVersion: rbac.authorization.k8s.io/v1beta1
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: prometheus

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -18,19 +18,18 @@ import (
"bytes"
"encoding/json"
"fmt"
jsonpatch "github.com/evanphx/json-patch/v5"
"io/ioutil"
v1 "k8s.io/api/admission/v1"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
jsonpatch "github.com/evanphx/json-patch/v5"
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/prometheus/client_golang/prometheus"
"k8s.io/api/admission/v1beta1"
"k8s.io/api/admission/v1"
)
func TestMutateRule(t *testing.T) {
@ -182,7 +181,7 @@ func server(s serveFunc) *httptest.Server {
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))
if err != nil {
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)
}
rev := &v1beta1.AdmissionReview{}
rev := &v1.AdmissionReview{}
if err := json.Unmarshal(body, rev); err != nil {
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(`
{
"kind": "AdmissionReview",
"apiVersion": "admission.k8s.io/v1beta1",
"apiVersion": "admission.k8s.io/v1",
"request": {
"uid": "87c5df7f-5090-11e9-b9b4-02425473f309",
"kind": {
@ -270,7 +269,7 @@ var goodRulesWithAnnotations = []byte(`
var goodRulesWithExternalLabelsInAnnotations = []byte(`
{
"kind": "AdmissionReview",
"apiVersion": "admission.k8s.io/v1beta1",
"apiVersion": "admission.k8s.io/v1",
"request": {
"uid": "87c5df7f-5090-11e9-b9b4-02425473f309",
"kind": {
@ -335,7 +334,7 @@ var goodRulesWithExternalLabelsInAnnotations = []byte(`
var badRulesNoAnnotations = []byte(`
{
"kind": "AdmissionReview",
"apiVersion": "admission.k8s.io/v1beta1",
"apiVersion": "admission.k8s.io/v1",
"request": {
"uid": "87c5df7f-5090-11e9-b9b4-02425473f309",
"kind": {
@ -398,7 +397,7 @@ var badRulesNoAnnotations = []byte(`
var badRulesWithBooleanInAnnotations = []byte(`
{
"kind": "AdmissionReview",
"apiVersion": "admission.k8s.io/v1beta1",
"apiVersion": "admission.k8s.io/v1",
"request": {
"uid": "87c5df7f-5090-11e9-b9b4-02425473f309",
"kind": {
@ -465,7 +464,7 @@ var badRulesWithBooleanInAnnotations = []byte(`
var nonStringsInLabelsAnnotations = []byte(`
{
"kind": "AdmissionReview",
"apiVersion": "admission.k8s.io/v1beta1",
"apiVersion": "admission.k8s.io/v1",
"request": {
"uid": "87c5df7f-5090-11e9-b9b4-02425473f309",
"kind": {

View file

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

View file

@ -16,7 +16,7 @@ package framework
import (
"github.com/pkg/errors"
"k8s.io/api/admissionregistration/v1beta1"
"k8s.io/api/admissionregistration/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"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.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 {
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.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 {
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 {
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 {
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)
if err != nil {
return nil, err
}
resource := v1beta1.ValidatingWebhookConfiguration{}
resource := v1.ValidatingWebhookConfiguration{}
if err := yaml.NewYAMLOrJSONDecoder(manifest, 100).Decode(&resource); err != nil {
return nil, errors.Wrapf(err, "failed to decode file %s", pathToYaml)
}
@ -81,13 +81,13 @@ func parseValidatingHookYaml(pathToYaml string) (*v1beta1.ValidatingWebhookConfi
return &resource, nil
}
func parseMutatingHookYaml(pathToYaml string) (*v1beta1.MutatingWebhookConfiguration, error) {
func parseMutatingHookYaml(pathToYaml string) (*v1.MutatingWebhookConfiguration, error) {
manifest, err := PathToOSFile(pathToYaml)
if err != nil {
return nil, err
}
resource := v1beta1.MutatingWebhookConfiguration{}
resource := v1.MutatingWebhookConfiguration{}
if err := yaml.NewYAMLOrJSONDecoder(manifest, 100).Decode(&resource); err != nil {
return nil, errors.Wrapf(err, "failed to decode file %s", pathToYaml)
}

View file

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

View file

@ -22,3 +22,6 @@ webhooks:
- UPDATE
resources:
- prometheusrules
sideEffects: None
admissionReviewVersions:
- v1

View file

@ -21,3 +21,6 @@ webhooks:
- UPDATE
resources:
- 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
metadata:
name: prometheus