-
Notifications
You must be signed in to change notification settings - Fork 674
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SVR-185 Serverless Image Builder mutating webhook (#244)
* SVR-185 Image Builder Mutating/Validation Webhook Support a mutating and validating webhook for creating Pods. Notable changes: * Supports replacing obscuring URL cr.union.ai with underlying GAR URL * Introduce concept of WebhookType to distinguish Secrets and ImageBuilder * Update existing adminissionregistrationv1.MutatingWebhookConfiguration with a **new additional Webhook** for ImageBuilder. This was necessary because Secrets and ImageBuilder uses different Pod Label Selectors. Removed PodMutator containing a list of mutators. * This introduces somewhat strict requirements that **all serverless flyte* FlytePropeller originated Pods must conform to a specific set of GAR registry paths.
- Loading branch information
Showing
15 changed files
with
1,319 additions
and
299 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,103 @@ | ||
package config | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// Ensure HostnameReplacements resolves to non-nil empty list. | ||
func TestConfig_DefaultImageBuilder(t *testing.T) { | ||
assert.Nil(t, DefaultConfig.ImageBuilderConfig) | ||
} | ||
|
||
func TestConfig_LoadSimpleJSON(t *testing.T) { | ||
expectedJSON := `{ | ||
"metrics-prefix": "test-prefix", | ||
"certDir": "/test/cert/dir", | ||
"localCert": true, | ||
"listenPort": 8080, | ||
"serviceName": "test-service", | ||
"servicePort": 8081, | ||
"secretName": "test-secret", | ||
"secretManagerType": "K8s" | ||
}` | ||
|
||
var config Config | ||
err := json.Unmarshal([]byte(expectedJSON), &config) | ||
assert.Nil(t, err) | ||
|
||
assert.Nil(t, config.ImageBuilderConfig) | ||
} | ||
|
||
func TestConfig_ImageBuilderConfig(t *testing.T) { | ||
|
||
t.Run("With verification enabled", func(t *testing.T) { | ||
expectedJSON := `{ | ||
"metrics-prefix": "test-prefix", | ||
"certDir": "/test/cert/dir", | ||
"localCert": true, | ||
"listenPort": 8080, | ||
"serviceName": "test-service", | ||
"servicePort": 8081, | ||
"secretName": "test-secret", | ||
"secretManagerType": "K8s", | ||
"imageBuilderConfig": { | ||
"hostnameReplacement": { | ||
"existing": "test.existing.hostname", | ||
"replacement": "test.replacement.hostname" | ||
}, | ||
"labelSelector": { | ||
"matchLabels": { | ||
"test-key": "test-value" | ||
} | ||
} | ||
} | ||
}` | ||
|
||
var config Config | ||
err := json.Unmarshal([]byte(expectedJSON), &config) | ||
assert.Nil(t, err) | ||
|
||
assert.Equal(t, "test.existing.hostname", config.ImageBuilderConfig.HostnameReplacement.Existing) | ||
assert.Equal(t, "test.replacement.hostname", config.ImageBuilderConfig.HostnameReplacement.Replacement) | ||
assert.Equal(t, false, config.ImageBuilderConfig.HostnameReplacement.DisableVerification) | ||
assert.Equal(t, "test-value", config.ImageBuilderConfig.LabelSelector.MatchLabels["test-key"]) | ||
}) | ||
|
||
t.Run("With verification disabled", func(t *testing.T) { | ||
expectedJSON := `{ | ||
"metrics-prefix": "test-prefix", | ||
"certDir": "/test/cert/dir", | ||
"localCert": true, | ||
"listenPort": 8080, | ||
"serviceName": "test-service", | ||
"servicePort": 8081, | ||
"secretName": "test-secret", | ||
"secretManagerType": "K8s", | ||
"imageBuilderConfig": { | ||
"hostnameReplacement": { | ||
"existing": "test.existing.hostname", | ||
"replacement": "test.replacement.hostname", | ||
"disableVerification": true | ||
}, | ||
"labelSelector": { | ||
"matchLabels": { | ||
"test-key": "test-value" | ||
} | ||
} | ||
} | ||
}` | ||
|
||
var config Config | ||
err := json.Unmarshal([]byte(expectedJSON), &config) | ||
assert.Nil(t, err) | ||
|
||
assert.Equal(t, "test.existing.hostname", config.ImageBuilderConfig.HostnameReplacement.Existing) | ||
assert.Equal(t, "test.replacement.hostname", config.ImageBuilderConfig.HostnameReplacement.Replacement) | ||
assert.Equal(t, true, config.ImageBuilderConfig.HostnameReplacement.DisableVerification) | ||
assert.Equal(t, "test-value", config.ImageBuilderConfig.LabelSelector.MatchLabels["test-key"]) | ||
}) | ||
|
||
} |
This file contains 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 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,21 @@ | ||
package webhook | ||
|
||
import ( | ||
"net/http" | ||
|
||
"sigs.k8s.io/controller-runtime/pkg/manager" | ||
) | ||
|
||
//go:generate mockery --output=./mocks --case=underscore -name=HTTPHookRegistererIface | ||
|
||
type HTTPHookRegistererIface interface { | ||
Register(path string, hook http.Handler) | ||
} | ||
|
||
type K8sRuntimeHTTPHookRegisterer struct { | ||
mgr manager.Manager | ||
} | ||
|
||
func (k K8sRuntimeHTTPHookRegisterer) Register(path string, hook http.Handler) { | ||
k.mgr.GetWebhookServer().Register(path, hook) | ||
} |
Oops, something went wrong.