Don't remove ingress config on API call failure

This commit is contained in:
Daniel Tomcej 2021-07-19 12:06:07 -06:00 committed by GitHub
parent 8d4620dc53
commit c2c4dc9b58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 19 deletions

View file

@ -60,7 +60,7 @@ type Client interface {
GetSecret(namespace, name string) (*corev1.Secret, bool, error)
GetEndpoints(namespace, name string) (*corev1.Endpoints, bool, error)
UpdateIngressStatus(ing *networkingv1beta1.Ingress, ingStatus []corev1.LoadBalancerIngress) error
GetServerVersion() (*version.Version, error)
GetServerVersion() *version.Version
}
type clientWrapper struct {
@ -72,6 +72,7 @@ type clientWrapper struct {
ingressLabelSelector string
isNamespaceAll bool
watchedNamespaces []string
serverVersion *version.Version
}
// newInClusterClient returns a new Provider client that is expected to run
@ -208,12 +209,18 @@ func (c *clientWrapper) WatchAll(namespaces []string, stopCh <-chan struct{}) (<
}
}
serverVersion, err := c.GetServerVersion()
// Get and store the serverVersion for future use.
serverVersionInfo, err := c.clientset.Discovery().ServerVersion()
if err != nil {
log.WithoutContext().Errorf("Failed to get server version: %v", err)
return eventCh, nil
return eventCh, fmt.Errorf("could not retrieve server version: %w", err)
}
serverVersion, err := version.NewVersion(serverVersionInfo.GitVersion)
if err != nil {
return eventCh, fmt.Errorf("could not parse server version: %w", err)
}
c.serverVersion = serverVersion
if supportsIngressClass(serverVersion) {
c.clusterFactory = informers.NewSharedInformerFactoryWithOptions(c.clientset, resyncPeriod)
c.clusterFactory.Networking().V1beta1().IngressClasses().Informer().AddEventHandler(eventHandler)
@ -426,13 +433,8 @@ func (c *clientWrapper) lookupNamespace(ns string) string {
}
// GetServerVersion returns the cluster server version, or an error.
func (c *clientWrapper) GetServerVersion() (*version.Version, error) {
serverVersion, err := c.clientset.Discovery().ServerVersion()
if err != nil {
return nil, fmt.Errorf("could not retrieve server version: %w", err)
}
return version.NewVersion(serverVersion.GitVersion)
func (c *clientWrapper) GetServerVersion() *version.Version {
return c.serverVersion
}
// eventHandlerFunc will pass the obj on to the events channel or drop it.

View file

@ -73,8 +73,8 @@ func (c clientMock) GetIngresses() []*networkingv1beta1.Ingress {
return c.ingresses
}
func (c clientMock) GetServerVersion() (*version.Version, error) {
return c.serverVersion, nil
func (c clientMock) GetServerVersion() *version.Version {
return c.serverVersion
}
func (c clientMock) GetService(namespace, name string) (*corev1.Service, bool, error) {

View file

@ -1,6 +1,7 @@
package ingress
import (
"errors"
"fmt"
"testing"
"time"
@ -154,7 +155,8 @@ func TestClientIgnoresHelmOwnedSecrets(t *testing.T) {
stopCh := make(chan struct{})
eventCh, err := client.WatchAll(nil, stopCh)
require.NoError(t, err)
// Fake clientset always returns this exact serverVersion that fails our validation.
require.Error(t, errors.New(`could not parse server version: Malformed version: v0.0.0-master+$Format:%h$`), err)
select {
case event := <-eventCh:

View file

@ -189,11 +189,7 @@ func (p *Provider) loadConfigurationFromIngresses(ctx context.Context, client Cl
TCP: &dynamic.TCPConfiguration{},
}
serverVersion, err := client.GetServerVersion()
if err != nil {
log.FromContext(ctx).Errorf("Failed to get server version: %v", err)
return conf
}
serverVersion := client.GetServerVersion()
var ingressClasses []*networkingv1beta1.IngressClass