diff --git a/api/v1/externalservice_types.go b/api/v1/externalservice_types.go index afb58ed..db35bc6 100644 --- a/api/v1/externalservice_types.go +++ b/api/v1/externalservice_types.go @@ -16,7 +16,6 @@ limitations under the License. package v1 import ( - "github.com/golang/protobuf/ptypes/duration" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -67,10 +66,10 @@ type ExternalServiceSpec struct { // Input to the --log-level command line option. See the help text for the available log levels and the default. EnvoyLogLevel string `json:"envoyArguments,omitempty"` - // Corresponds to Envoy's dns_refresh_rate config field for this cluster. + // Corresponds to Envoy's dns_refresh_rate config field for this cluster, in seconds // See https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/cluster/v3/cluster.proto // +optional - EnvoyDnsRefreshRate *duration.Duration `json:"envoy_dns_refresh_rate,omitempty"` + EnvoyDnsRefreshRateS int64 `json:"envoy_dns_refresh_rate,omitempty"` // Corresponds to Envoy's respect_dns_ttl config field for this cluster. // See https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/cluster/v3/cluster.proto diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 3c597f3..9e690a8 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -1,5 +1,4 @@ //go:build !ignore_autogenerated -// +build !ignore_autogenerated /* @@ -21,6 +20,7 @@ limitations under the License. package v1 import ( + durationpb "google.golang.org/protobuf/types/known/durationpb" corev1 "k8s.io/api/core/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -144,6 +144,11 @@ func (in *ExternalServiceSpec) DeepCopyInto(out *ExternalServiceSpec) { *out = new(uint32) **out = **in } + if in.EnvoyDnsRefreshRate != nil { + in, out := &in.EnvoyDnsRefreshRate, &out.EnvoyDnsRefreshRate + *out = new(durationpb.Duration) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalServiceSpec. diff --git a/config/crd/bases/egress.monzo.com_externalservices.yaml b/config/crd/bases/egress.monzo.com_externalservices.yaml index 3d614b1..d6300c7 100644 --- a/config/crd/bases/egress.monzo.com_externalservices.yaml +++ b/config/crd/bases/egress.monzo.com_externalservices.yaml @@ -42,11 +42,11 @@ spec: envoyLogLevel: description: Input to the --log-level command line option. See the help text for the available log levels and the default. type: string - envoyDnsRefreshRate: + envoyDnsRefreshRateS: description: | - Corresponds to Envoy's dns_refresh_rate config field for this cluster. + Corresponds to Envoy's dns_refresh_rate config field for this cluster, in seconds See https://www.envoyproxy.io/docs/envoy/latest/api-v3/config/cluster/v3/cluster.proto - type: string + type: number envoyRespectDnsTTL: description: | Corresponds to Envoy's respect_dns_ttl config field for this cluster. diff --git a/controllers/configmap.go b/controllers/configmap.go index 6dda795..9725d64 100644 --- a/controllers/configmap.go +++ b/controllers/configmap.go @@ -3,6 +3,7 @@ package controllers import ( "context" "fmt" + "google.golang.org/protobuf/types/known/durationpb" "hash/fnv" "strconv" @@ -298,6 +299,10 @@ func configmap(es *egressv1.ExternalService) (*corev1.ConfigMap, string, error) func generateOverrideCluster(name string, spec egressv1.ExternalServiceSpec, port egressv1.ExternalServicePort, protocol envoycorev3.SocketAddress_Protocol) *envoyv3.Cluster { overrideClusterName := fmt.Sprintf("%v-override", name) + var dnsRefreshRate *duration.Duration + if spec.EnvoyDnsRefreshRateS != 0 { + dnsRefreshRate = &durationpb.Duration{Seconds: spec.EnvoyDnsRefreshRateS} + } var endpoints []*envoyendpoint.LocalityLbEndpoints for _, ip := range spec.IpOverride { @@ -357,7 +362,7 @@ func generateOverrideCluster(name string, spec egressv1.ExternalServiceSpec, por Endpoints: endpoints, }, - DnsRefreshRate: spec.EnvoyDnsRefreshRate, + DnsRefreshRate: dnsRefreshRate, RespectDnsTtl: spec.EnvoyRespectDnsTTL, } }