-
Notifications
You must be signed in to change notification settings - Fork 228
USHIFT-6902 USHIFT-6903: Custom DNS configuration #6592
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
Open
pacevedom
wants to merge
10
commits into
openshift:main
Choose a base branch
from
pacevedom:USHIFT-6902
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
374bb27
USHIFT-6902: Add dns.configFile config field and validation
pacevedom 77239f6
USHIFT-6902: Use custom Corefile in DNS controller rendering
pacevedom 8357514
USHIFT-6902: Add DNS configuration watcher for runtime reload
pacevedom 9e0a8d3
USHIFT-6902: Add unit tests for dns.configFile validation
pacevedom 390a845
USHIFT-6903: Add e2e tests for custom DNS configuration
pacevedom 1bb1468
USHIFT-6902: Address review feedback for custom DNS configuration
pacevedom 4575627
USHIFT-6902: Extract shared DNS test keywords into dns.resource
pacevedom b23bf72
USHIFT-6902: Verify ConfigMap update before DNS resolution in reload …
pacevedom 0157a1c
USHIFT-6902: Fix nits from review feedback
pacevedom 48e380b
USHIFT-6902: Consolidate DNS and hosts file watchers into shared abst…
pacevedom 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
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
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
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
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
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
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
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 |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| package config | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestDNS_ValidateConfigFile_MutualExclusivity(t *testing.T) { | ||
| tmpFile := createTempCorefile(t, ".:5353 { whoami }") | ||
|
|
||
| dns := DNS{ | ||
| ConfigFile: tmpFile, | ||
| Hosts: HostsConfig{ | ||
| Status: HostsStatusEnabled, | ||
| File: "/etc/hosts", | ||
| }, | ||
| } | ||
| err := dns.validate() | ||
| assert.ErrorContains(t, err, "dns.configFile and dns.hosts are mutually exclusive") | ||
| } | ||
|
|
||
| func TestDNS_ValidateConfigFile_WithHostsDisabled(t *testing.T) { | ||
| tmpFile := createTempCorefile(t, ".:5353 { whoami }") | ||
|
|
||
| dns := DNS{ | ||
| ConfigFile: tmpFile, | ||
| Hosts: HostsConfig{ | ||
| Status: HostsStatusDisabled, | ||
| }, | ||
| } | ||
| assert.NoError(t, dns.validate()) | ||
| } | ||
|
|
||
| func TestDNS_ValidateConfigFile_EmptyConfigFilePreservesDefault(t *testing.T) { | ||
| dns := DNS{ | ||
| ConfigFile: "", | ||
| Hosts: HostsConfig{ | ||
| Status: HostsStatusDisabled, | ||
| }, | ||
| } | ||
| assert.NoError(t, dns.validate()) | ||
| } | ||
|
|
||
| func TestDNS_ValidateConfigFile_NonAbsolutePath(t *testing.T) { | ||
| dns := DNS{ | ||
| ConfigFile: "relative/path/Corefile", | ||
| Hosts: HostsConfig{ | ||
| Status: HostsStatusDisabled, | ||
| }, | ||
| } | ||
| err := dns.validate() | ||
| assert.ErrorContains(t, err, "dns config file path must be absolute") | ||
| } | ||
|
|
||
| func TestDNS_ValidateConfigFile_NonExistentFile(t *testing.T) { | ||
| dns := DNS{ | ||
| ConfigFile: "/tmp/nonexistent-corefile-test-12345", | ||
| Hosts: HostsConfig{ | ||
| Status: HostsStatusDisabled, | ||
| }, | ||
| } | ||
| err := dns.validate() | ||
| assert.ErrorContains(t, err, "does not exist") | ||
| } | ||
|
|
||
| func TestDNS_ValidateConfigFile_Directory(t *testing.T) { | ||
| tmpDir := t.TempDir() | ||
|
|
||
| dns := DNS{ | ||
| ConfigFile: tmpDir, | ||
| Hosts: HostsConfig{ | ||
| Status: HostsStatusDisabled, | ||
| }, | ||
| } | ||
| err := dns.validate() | ||
| assert.ErrorContains(t, err, "must be a regular file") | ||
| } | ||
|
|
||
| func TestDNS_ValidateConfigFile_EmptyFile(t *testing.T) { | ||
| tmpFile := createTempCorefile(t, "") | ||
|
|
||
| dns := DNS{ | ||
| ConfigFile: tmpFile, | ||
| Hosts: HostsConfig{ | ||
| Status: HostsStatusDisabled, | ||
| }, | ||
| } | ||
| err := dns.validate() | ||
| assert.ErrorContains(t, err, "is empty") | ||
| } | ||
|
|
||
| func TestDNS_ValidateConfigFile_ExceedsSizeLimit(t *testing.T) { | ||
| tmpDir := t.TempDir() | ||
| tmpFile := filepath.Join(tmpDir, "Corefile") | ||
| // 1 MiB + 1 byte | ||
| data := make([]byte, 1048576+1) | ||
| require.NoError(t, os.WriteFile(tmpFile, data, 0644)) | ||
|
|
||
| dns := DNS{ | ||
| ConfigFile: tmpFile, | ||
| Hosts: HostsConfig{ | ||
| Status: HostsStatusDisabled, | ||
| }, | ||
| } | ||
| err := dns.validate() | ||
| assert.ErrorContains(t, err, "exceeds 1MiB size limit") | ||
| } | ||
|
|
||
| func TestDNS_ValidateConfigFile_ValidFile(t *testing.T) { | ||
| tmpFile := createTempCorefile(t, ".:5353 {\n whoami\n reload\n}\n") | ||
|
|
||
| dns := DNS{ | ||
| ConfigFile: tmpFile, | ||
| Hosts: HostsConfig{ | ||
| Status: HostsStatusDisabled, | ||
| }, | ||
| } | ||
| assert.NoError(t, dns.validate()) | ||
| } | ||
|
|
||
| func TestDNS_ConfigFile_IncorporatedFromDropIn(t *testing.T) { | ||
| tmpFile := createTempCorefile(t, ".:5353 {\n whoami\n reload\n}\n") | ||
|
|
||
| yamlConfig := fmt.Sprintf("dns:\n configFile: %s\n", tmpFile) | ||
| config, err := getActiveConfigFromYAMLDropins([][]byte{[]byte(yamlConfig)}) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, tmpFile, config.DNS.ConfigFile) | ||
| } | ||
|
|
||
| func createTempCorefile(t *testing.T, content string) string { | ||
| t.Helper() | ||
| tmpDir := t.TempDir() | ||
| tmpFile := filepath.Join(tmpDir, "Corefile") | ||
| require.NoError(t, os.WriteFile(tmpFile, []byte(content), 0644)) | ||
| return tmpFile | ||
| } |
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 |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package controllers | ||
|
Member
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 file is very very similar to |
||
|
|
||
| import ( | ||
| "github.com/fsnotify/fsnotify" | ||
| "github.com/openshift/microshift/pkg/config" | ||
| ) | ||
|
|
||
| type DNSConfigurationWatcherManager struct { | ||
| fileWatcher | ||
| } | ||
|
|
||
| func NewDNSConfigurationWatcherManager(cfg *config.Config) *DNSConfigurationWatcherManager { | ||
| return &DNSConfigurationWatcherManager{fileWatcher{cfg: fileWatcherConfig{ | ||
| serviceName: "dns-configuration-watcher-manager", | ||
| dependencies: []string{"infrastructure-services-manager"}, | ||
| file: cfg.DNS.ConfigFile, | ||
| kubeconfig: cfg.KubeConfigPath(config.KubeAdmin), | ||
| enabled: cfg.DNS.ConfigFile != "", | ||
| configMapNamespace: "openshift-dns", | ||
| configMapName: "dns-default", | ||
| configMapDataKey: "Corefile", | ||
| labels: map[string]string{ | ||
| "dns.operator.openshift.io/owning-dns": "default", | ||
| }, | ||
| annotations: map[string]string{ | ||
| "microshift.io/dns-config-file": cfg.DNS.ConfigFile, | ||
| }, | ||
| eventMask: fsnotify.Write | fsnotify.Create | fsnotify.Rename | fsnotify.Remove, | ||
| reAddOnCreate: true, | ||
| mergeAnnotations: true, | ||
| deleteOnDisable: false, | ||
| }}} | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.