-
Notifications
You must be signed in to change notification settings - Fork 689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ingress status #1976
Ingress status #1976
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -99,7 +99,17 @@ func main() { | |
} | ||
} | ||
|
||
func newClient(kubeconfig string, inCluster bool) (*kubernetes.Clientset, *clientset.Clientset, *coordinationv1.CoordinationV1Client) { | ||
// Returns the current namespace in which the controller is running | ||
// If error returns empty string | ||
func getCurrentNamespace() string { | ||
ns, _, err := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(clientcmd.NewDefaultClientConfigLoadingRules(), &clientcmd.ConfigOverrides{}).Namespace() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wow, that's a function name and a half :) How does this determine where its loading the kubeconfig from? If its magic, can we use the same magic for contour's --kubeconfig flag? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's using client-go to determine which namespace Contour is deployed into. I was trying to avoid folks having to add extra args to deployments by automatically finding this information. It can still be overridden by args if the user would like. I also didn't want to read the |
||
if err != nil { | ||
return "projectcontour" | ||
} | ||
return ns | ||
} | ||
|
||
func newClient(kubeconfig string, inCluster bool) (kubernetes.Interface, *clientset.Clientset, *coordinationv1.CoordinationV1Client) { | ||
var err error | ||
var config *rest.Config | ||
if kubeconfig != "" && !inCluster { | ||
|
@@ -112,6 +122,7 @@ func newClient(kubeconfig string, inCluster bool) (*kubernetes.Clientset, *clien | |
|
||
client, err := kubernetes.NewForConfig(config) | ||
check(err) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: maybe use \n on line 127 and onwards for consistency? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I don't follow your comment. I didn't change any of this short of moving from |
||
contourClient, err := clientset.NewForConfig(config) | ||
check(err) | ||
coordinationClient, err := coordinationv1.NewForConfig(config) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ import ( | |
|
||
// newLeaderElector creates a new leaderelection.LeaderElector and associated | ||
// channels by which to observe elections and depositions. | ||
func newLeaderElector(log logrus.FieldLogger, ctx *serveContext, client *kubernetes.Clientset, coordinationClient *coordinationv1.CoordinationV1Client) (*leaderelection.LeaderElector, chan struct{}, chan struct{}) { | ||
func newLeaderElector(log logrus.FieldLogger, ctx *serveContext, client kubernetes.Interface, coordinationClient *coordinationv1.CoordinationV1Client) (*leaderelection.LeaderElector, chan struct{}, chan struct{}) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like an unrelated change, maybe pull it out into its own PR to make this easier to review. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wanted to add a test which actually tested that I could set the status of an Ingress object. In doing that I can use the client-go |
||
|
||
// leaderOK will block gRPC startup until it's closed. | ||
leaderOK := make(chan struct{}) | ||
|
@@ -64,7 +64,7 @@ func newLeaderElector(log logrus.FieldLogger, ctx *serveContext, client *kuberne | |
|
||
// newResourceLock creates a new resourcelock.Interface based on the Pod's name, | ||
// or a uuid if the name cannot be determined. | ||
func newResourceLock(ctx *serveContext, client *kubernetes.Clientset, coordinationClient *coordinationv1.CoordinationV1Client) resourcelock.Interface { | ||
func newResourceLock(ctx *serveContext, client kubernetes.Interface, coordinationClient *coordinationv1.CoordinationV1Client) resourcelock.Interface { | ||
resourceLockID, found := os.LookupEnv("POD_NAME") | ||
if !found { | ||
resourceLockID = uuid.New().String() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,8 @@ func registerServe(app *kingpin.Application) (*kingpin.CmdClause, *serveContext) | |
serve.Flag("root-namespaces", "Restrict contour to searching these namespaces for root ingress routes").StringVar(&ctx.rootNamespaces) | ||
|
||
serve.Flag("ingress-class-name", "Contour IngressClass name").StringVar(&ctx.ingressClass) | ||
serve.Flag("envoy-service-name", "Defines which Envoy service name handles ingress traffic for this instance of Contour").StringVar(&ctx.envoyServiceName) | ||
serve.Flag("envoy-service-namespace", "Defines which Envoy service namespace handles ingress traffic for this instance of Contour").StringVar(&ctx.envoyServiceNamespace) | ||
|
||
serve.Flag("envoy-http-access-log", "Envoy HTTP access log").StringVar(&ctx.httpAccessLog) | ||
serve.Flag("envoy-https-access-log", "Envoy HTTPS access log").StringVar(&ctx.httpsAccessLog) | ||
|
@@ -125,6 +127,11 @@ func doServe(log logrus.FieldLogger, ctx *serveContext) error { | |
// step 1. establish k8s client connection | ||
client, contourClient, coordinationClient := newClient(ctx.Kubeconfig, ctx.InCluster) | ||
|
||
// step 1b. get current namespace that Contour is running inside if not defined | ||
if ctx.envoyServiceNamespace == "" { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. setting ctx.envoyServiceName and ctx.envoyServiceNamespace are handled differently, is there a way to make them more similar? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name come from a namespace, I'm using the check for empty to determine if a user hasn't already set the flag. If they haven't then I look up what namespace Contour is running in. |
||
ctx.envoyServiceNamespace = getCurrentNamespace() | ||
} | ||
|
||
// step 2. create informers | ||
// note: 0 means resync timers are disabled | ||
coreInformers := coreinformers.NewSharedInformerFactory(client, 0) | ||
|
@@ -158,8 +165,9 @@ func doServe(log logrus.FieldLogger, ctx *serveContext) error { | |
}, | ||
HoldoffDelay: 100 * time.Millisecond, | ||
HoldoffMaxDelay: 500 * time.Millisecond, | ||
CRDStatus: &k8s.CRDStatus{ | ||
Client: contourClient, | ||
CRDStatus: &k8s.Status{ | ||
CRDClient: contourClient, | ||
K8sClient: client, | ||
}, | ||
Builder: dag.Builder{ | ||
Source: dag.KubernetesCache{ | ||
|
@@ -168,6 +176,7 @@ func doServe(log logrus.FieldLogger, ctx *serveContext) error { | |
FieldLogger: log.WithField("context", "KubernetesCache"), | ||
}, | ||
DisablePermitInsecure: ctx.DisablePermitInsecure, | ||
EnvoyNamespaceName: ctx.envoyServiceNamespace, | ||
}, | ||
FieldLogger: log.WithField("context", "contourEventHandler"), | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,6 +55,12 @@ type serveContext struct { | |
// ingress class | ||
ingressClass string | ||
|
||
// envoyServiceName | ||
envoyServiceName string | ||
|
||
// envoyServiceNamespace | ||
envoyServiceNamespace string | ||
|
||
// envoy's stats listener parameters | ||
statsAddr string | ||
statsPort int | ||
|
@@ -164,6 +170,7 @@ func newServeContext() *serveContext { | |
Name: "leader-elect", | ||
}, | ||
UseExtensionsV1beta1Ingress: false, | ||
envoyServiceName: "envoy", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does if it cannot be looked up. I like the idea of requiring fewer flags to set on Contour, so I opted to look up the namespace which Contour is running in. If we take that out, we force users to set these flags and I can remove the lookup. |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,7 @@ func WriteSecretsYAML(outputDir, namespace string, certdata map[string][]byte) e | |
|
||
// WriteSecretsKube writes all the keypairs out to Kube Secrets in the | ||
// passed Kube context. | ||
func WriteSecretsKube(client *kubernetes.Clientset, namespace string, certdata map[string][]byte) error { | ||
func WriteSecretsKube(client kubernetes.Interface, namespace string, certdata map[string][]byte) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like an unrelated change, I think this file and the one above can be pulled out into their own PR to make this simpler to review. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See the previous comment about testing with fakes. |
||
err := writeCACertKube(client, namespace, certdata["cacert.pem"]) | ||
if err != nil { | ||
return err | ||
|
@@ -99,7 +99,7 @@ func writeCACertSecret(outputDir, namespace string, cert []byte) error { | |
return checkFile(filename, writeSecret(f, secret)) | ||
} | ||
|
||
func writeCACertKube(client *kubernetes.Clientset, namespace string, cert []byte) error { | ||
func writeCACertKube(client kubernetes.Interface, namespace string, cert []byte) error { | ||
secret := newCertOnlySecret("cacert", namespace, "cacert.pem", cert) | ||
_, err := client.CoreV1().Secrets(namespace).Create(secret) | ||
if err != nil { | ||
|
@@ -123,7 +123,7 @@ func writeKeyPairSecret(outputDir, service, namespace string, cert, key []byte) | |
return checkFile(filepath, err) | ||
} | ||
|
||
func writeKeyPairKube(client *kubernetes.Clientset, service, namespace string, cert, key []byte) error { | ||
func writeKeyPairKube(client kubernetes.Interface, service, namespace string, cert, key []byte) error { | ||
secretname := service + "cert" | ||
secret := newTLSSecret(secretname, namespace, key, cert) | ||
_, err := client.CoreV1().Secrets(namespace).Create(secret) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/returns the empty string/returns "projectcontour"