Skip to content

Commit

Permalink
When inspecting another changeset I found our internal template to be…
Browse files Browse the repository at this point in the history
… very old and was suprised it still worked. (#510)

Signed-off-by: Timothy St. Clair <[email protected]>
  • Loading branch information
timothysc authored Jul 27, 2018
1 parent 7b18b7a commit 606034d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 106 deletions.
103 changes: 11 additions & 92 deletions pkg/discovery/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/conversion"
Expand Down Expand Up @@ -118,41 +117,13 @@ func queryNsResource(ns string, resourceKind string, opts metav1.ListOptions, ku
case "ConfigMaps":
return kubeClient.CoreV1().ConfigMaps(ns).List(opts)
case "ControllerRevisions":
lst, err := kubeClient.AppsV1().ControllerRevisions(ns).List(opts)
if apierrors.IsNotFound(err) {
lst, err := kubeClient.AppsV1beta2().ControllerRevisions(ns).List(opts)
if apierrors.IsNotFound(err) {
return kubeClient.AppsV1beta1().ControllerRevisions(ns).List(opts)
}
return lst, err
}
return lst, err
return kubeClient.AppsV1().ControllerRevisions(ns).List(opts)
case "CronJobs":
lst, err := kubeClient.BatchV1beta1().CronJobs(ns).List(opts)
if apierrors.IsNotFound(err) {
return kubeClient.BatchV2alpha1().CronJobs(ns).List(opts)
}
return lst, err
return kubeClient.BatchV1beta1().CronJobs(ns).List(opts)
case "DaemonSets":
lst, err := kubeClient.AppsV1().DaemonSets(ns).List(opts)
if apierrors.IsNotFound(err) {
lst, err := kubeClient.AppsV1beta2().DaemonSets(ns).List(opts)
if apierrors.IsNotFound(err) {
return kubeClient.ExtensionsV1beta1().DaemonSets(ns).List(opts)
}
return lst, err
}
return lst, err
return kubeClient.AppsV1().DaemonSets(ns).List(opts)
case "Deployments":
lst, err := kubeClient.AppsV1().Deployments(ns).List(opts)
if apierrors.IsNotFound(err) {
lst, err := kubeClient.AppsV1beta2().Deployments(ns).List(opts)
if apierrors.IsNotFound(err) {
return kubeClient.AppsV1beta1().Deployments(ns).List(opts)
}
return lst, err
}
return lst, err
return kubeClient.AppsV1().Deployments(ns).List(opts)
case "Endpoints":
return kubeClient.CoreV1().Endpoints(ns).List(opts)
case "Events":
Expand All @@ -176,53 +147,21 @@ func queryNsResource(ns string, resourceKind string, opts metav1.ListOptions, ku
case "PodTemplates":
return kubeClient.CoreV1().PodTemplates(ns).List(opts)
case "ReplicaSets":
lst, err := kubeClient.AppsV1().ReplicaSets(ns).List(opts)
if apierrors.IsNotFound(err) {
lst, err := kubeClient.AppsV1beta2().ReplicaSets(ns).List(opts)
if apierrors.IsNotFound(err) {
return kubeClient.ExtensionsV1beta1().ReplicaSets(ns).List(opts)
}
return lst, err
}
return lst, err
return kubeClient.AppsV1().ReplicaSets(ns).List(opts)
case "ReplicationControllers":
return kubeClient.CoreV1().ReplicationControllers(ns).List(opts)
case "ResourceQuotas":
return kubeClient.CoreV1().ResourceQuotas(ns).List(opts)
case "RoleBindings":
lst, err := kubeClient.RbacV1().RoleBindings(ns).List(opts)
if apierrors.IsNotFound(err) {
lst, err := kubeClient.RbacV1beta1().RoleBindings(ns).List(opts)
if apierrors.IsNotFound(err) {
return kubeClient.RbacV1alpha1().RoleBindings(ns).List(opts)
}
return lst, err
}
return lst, err
return kubeClient.RbacV1().RoleBindings(ns).List(opts)
case "Roles":
lst, err := kubeClient.RbacV1().Roles(ns).List(opts)
if apierrors.IsNotFound(err) {
lst, err := kubeClient.RbacV1beta1().Roles(ns).List(opts)
if apierrors.IsNotFound(err) {
return kubeClient.RbacV1alpha1().Roles(ns).List(opts)
}
return lst, err
}
return lst, err
return kubeClient.RbacV1().Roles(ns).List(opts)
case "ServiceAccounts":
return kubeClient.CoreV1().ServiceAccounts(ns).List(opts)
case "Services":
return kubeClient.CoreV1().Services(ns).List(opts)
case "StatefulSets":
lst, err := kubeClient.AppsV1().StatefulSets(ns).List(opts)
if apierrors.IsNotFound(err) {
lst, err := kubeClient.AppsV1beta2().StatefulSets(ns).List(opts)
if apierrors.IsNotFound(err) {
return kubeClient.AppsV1beta1().StatefulSets(ns).List(opts)
}
return lst, err
}
return lst, err
return kubeClient.AppsV1().StatefulSets(ns).List(opts)
default:
return nil, errors.Errorf("Unsupported resource %v", resourceKind)
}
Expand All @@ -234,25 +173,9 @@ func queryNonNsResource(resourceKind string, kubeClient kubernetes.Interface) (r
case "CertificateSigningRequests":
return kubeClient.CertificatesV1beta1().CertificateSigningRequests().List(metav1.ListOptions{})
case "ClusterRoleBindings":
lst, err := kubeClient.RbacV1().ClusterRoleBindings().List(metav1.ListOptions{})
if apierrors.IsNotFound(err) {
lst, err := kubeClient.RbacV1beta1().ClusterRoleBindings().List(metav1.ListOptions{})
if apierrors.IsNotFound(err) {
return kubeClient.RbacV1alpha1().ClusterRoleBindings().List(metav1.ListOptions{})
}
return lst, err
}
return lst, err
return kubeClient.RbacV1().ClusterRoleBindings().List(metav1.ListOptions{})
case "ClusterRoles":
lst, err := kubeClient.RbacV1().ClusterRoles().List(metav1.ListOptions{})
if apierrors.IsNotFound(err) {
lst, err := kubeClient.RbacV1beta1().ClusterRoles().List(metav1.ListOptions{})
if apierrors.IsNotFound(err) {
return kubeClient.RbacV1alpha1().ClusterRoles().List(metav1.ListOptions{})
}
return lst, err
}
return lst, err
return kubeClient.RbacV1().ClusterRoles().List(metav1.ListOptions{})
case "ComponentStatuses":
return kubeClient.CoreV1().ComponentStatuses().List(metav1.ListOptions{})
case "CustomResourceDefinitions":
Expand All @@ -269,11 +192,7 @@ func queryNonNsResource(resourceKind string, kubeClient kubernetes.Interface) (r
case "PodSecurityPolicies":
return kubeClient.ExtensionsV1beta1().PodSecurityPolicies().List(metav1.ListOptions{})
case "StorageClasses":
lst, err := kubeClient.StorageV1().StorageClasses().List(metav1.ListOptions{})
if apierrors.IsNotFound(err) {
return kubeClient.StorageV1beta1().StorageClasses().List(metav1.ListOptions{})
}
return lst, err
return kubeClient.StorageV1().StorageClasses().List(metav1.ListOptions{})
default:
return nil, errors.Errorf("don't know how to handle non-namespaced resource %v", resourceKind)
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/plugin/driver/daemonset/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"fmt"
"time"

appsv1beta2 "k8s.io/api/apps/v1beta2"
appsv1 "k8s.io/api/apps/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kuberuntime "k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -95,7 +95,7 @@ func (p *Plugin) FillTemplate(hostname string, cert *tls.Certificate) ([]byte, e

// Run dispatches worker pods according to the DaemonSet's configuration.
func (p *Plugin) Run(kubeclient kubernetes.Interface, hostname string, cert *tls.Certificate) error {
var daemonSet appsv1beta2.DaemonSet
var daemonSet appsv1.DaemonSet

b, err := p.FillTemplate(hostname, cert)
if err != nil {
Expand All @@ -115,7 +115,7 @@ func (p *Plugin) Run(kubeclient kubernetes.Interface, hostname string, cert *tls
}

// TODO(EKF): Move to v1 in 1.11
if _, err := kubeclient.AppsV1beta2().DaemonSets(p.Namespace).Create(&daemonSet); err != nil {
if _, err := kubeclient.AppsV1().DaemonSets(p.Namespace).Create(&daemonSet); err != nil {
return errors.Wrapf(err, "could not create DaemonSet for daemonset plugin %v", p.GetName())
}

Expand All @@ -136,7 +136,7 @@ func (p *Plugin) Cleanup(kubeclient kubernetes.Interface) {

// Delete the DaemonSet created by this plugin
// TODO(EKF): Move to v1 in 1.11
err := kubeclient.AppsV1beta2().DaemonSets(p.Namespace).DeleteCollection(
err := kubeclient.AppsV1().DaemonSets(p.Namespace).DeleteCollection(
&deleteOptions,
listOptions,
)
Expand All @@ -152,9 +152,9 @@ func (p *Plugin) listOptions() metav1.ListOptions {
}

// findDaemonSet gets the daemonset that we created, using a kubernetes label search.
func (p *Plugin) findDaemonSet(kubeclient kubernetes.Interface) (*appsv1beta2.DaemonSet, error) {
func (p *Plugin) findDaemonSet(kubeclient kubernetes.Interface) (*appsv1.DaemonSet, error) {
// TODO(EKF): Move to v1 in 1.11
dsets, err := kubeclient.AppsV1beta2().DaemonSets(p.Namespace).List(p.listOptions())
dsets, err := kubeclient.AppsV1().DaemonSets(p.Namespace).List(p.listOptions())
if err != nil {
return nil, errors.WithStack(err)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugin/driver/daemonset/daemonset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
"github.com/heptio/sonobuoy/pkg/plugin"
"github.com/heptio/sonobuoy/pkg/plugin/manifest"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
kuberuntime "k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"
)
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestFillTemplate(t *testing.T) {
t.Fatalf("couldn't make client certificate %v", err)
}

var daemonSet v1beta1.DaemonSet
var daemonSet appsv1.DaemonSet
b, err := testDaemonSet.FillTemplate("", clientCert)
if err != nil {
t.Fatalf("Failed to fill template: %v", err)
Expand Down
8 changes: 2 additions & 6 deletions pkg/plugin/driver/daemonset/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

var daemonSetTemplate = templates.NewTemplate("daemonTemplate", `
---
apiVersion: extensions/v1beta1
apiVersion: apps/v1
kind: DaemonSet
metadata:
annotations:
Expand Down Expand Up @@ -86,11 +86,7 @@ spec:
hostNetwork: true
hostPID: true
tolerations:
- effect: NoSchedule
key: node-role.kubernetes.io/master
operator: Exists
- key: CriticalAddonsOnly
operator: Exists
- operator: Exists
volumes:
- emptyDir: {}
name: results
Expand Down

0 comments on commit 606034d

Please sign in to comment.