-
Notifications
You must be signed in to change notification settings - Fork 0
Adding CoreDNS rewrite #39
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -13,13 +13,11 @@ | |||||
| private readonly IDockerEngine _docker; | ||||||
| private readonly Func<string, IKubernetesClient> _client; | ||||||
| private readonly IConsole _console; | ||||||
|
|
||||||
|
|
||||||
|
|
||||||
| private static readonly string NginxConf = Path.Combine("vega.conf"); | ||||||
|
|
||||||
| private readonly IKindClient _kind; | ||||||
|
|
||||||
|
|
||||||
| // ReverseProxyHostPort is 443 by default, unless REVERSE_PROXY_HOST_PORT is set as an env var | ||||||
| private int ReverseProxyHostPort = GetEnvironmentVariableAsInt("REVERSE_PROXY_HOST_PORT", 443); | ||||||
|
|
||||||
|
|
@@ -62,7 +60,7 @@ | |||||
| if (tuple is { isVdk: true, master: not null } && tuple.master.HttpsHostPort.HasValue) | ||||||
| { | ||||||
| _console.WriteLine($" - Adding cluster {tuple.name} to reverse proxy configuration"); | ||||||
| UpsertCluster(tuple.name, tuple.master.HttpsHostPort.Value, tuple.master.HttpHostPort.Value, false); | ||||||
| } | ||||||
| }); | ||||||
| } | ||||||
|
|
@@ -105,7 +103,7 @@ | |||||
| return true; | ||||||
| } | ||||||
|
|
||||||
| return false; | ||||||
| } | ||||||
|
|
||||||
| private void InitConfFile(FileInfo conf) | ||||||
|
|
@@ -147,6 +145,15 @@ | |||||
| } | ||||||
|
|
||||||
| public void UpsertCluster(string clusterName, int targetPortHttps, int targetPortHttp, bool reload = true) | ||||||
| { | ||||||
| PatchNginxConfig(clusterName, targetPortHttps); | ||||||
| if (CreateTlsSecret(clusterName)) return; | ||||||
| PatchCoreDns(clusterName); | ||||||
| if (reload) | ||||||
| ReloadConfigs(); | ||||||
| } | ||||||
|
|
||||||
| private void PatchNginxConfig(string clusterName, int targetPortHttps) | ||||||
| { | ||||||
| // create a new server block in the nginx conf pointing to the target port listening on the https://clusterName.dev-k8s.cloud domain | ||||||
| // reload the nginx configuration | ||||||
|
|
@@ -179,7 +186,112 @@ | |||||
| _console.WriteWarning($"Error clearing cluster configuration ({NginxConf}): {e.Message}"); | ||||||
| _console.WriteWarning("Please check the configuration and try again."); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| private bool PatchCoreDns(string clusterName) | ||||||
| { | ||||||
| // let's wait for and find the ingress controller service. | ||||||
| V1Service? ingressService = null; | ||||||
| var attempts = 0; | ||||||
| do | ||||||
| { | ||||||
| // check up to 10 times , waiting 5 seconds each time | ||||||
| ingressService = _client(clusterName).Get<V1Service>("ingress-nginx-controller", "ingress-nginx"); | ||||||
| if (ingressService == null) | ||||||
| { | ||||||
| _console.WriteLine("Waiting for ingress-nginx-controller service to be available..."); | ||||||
| Thread.Sleep(5000); | ||||||
|
||||||
| Thread.Sleep(5000); | |
| await Task.Delay(5000); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The parameter 'targetPortHttp' is not used within UpsertCluster. Consider removing it or adding logic to use it for HTTP traffic.