Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rajivnathan committed Nov 8, 2023
1 parent 753977c commit 378a4bd
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 13 deletions.
3 changes: 0 additions & 3 deletions cmd/webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ func main() {
spacebindingrequestValidator := &validatingwebhook.SpaceBindingRequestValidator{
Client: cl,
}
// vmMutator := &mutatingwebhook.VMMutator{
// MemberConfig: memberCfg,
// }
mux := http.NewServeMux()

mux.HandleFunc("/mutate-users-pods", mutatingwebhook.HandleMutateUserPods)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ require (
sigs.k8s.io/controller-runtime v0.13.0
)

replace github.com/codeready-toolchain/toolchain-common => github.com/rajivnathan/toolchain-common v0.0.0-20231107215310-b3711428895f
replace github.com/codeready-toolchain/toolchain-common => github.com/rajivnathan/toolchain-common v0.0.0-20231107221232-96f5a5f166db

require (
github.com/gofrs/uuid v4.4.0+incompatible
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,8 @@ github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1
github.com/prometheus/procfs v0.7.3 h1:4jVXhlkAyzOScmCkXBTOLRLTz8EeU+eyjrwB/EPq0VU=
github.com/prometheus/procfs v0.7.3/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rajivnathan/toolchain-common v0.0.0-20231107215310-b3711428895f h1:jsL8SGvoWd4Ysl9p9ts/PLFHM7zdoJOUf67IAKKll98=
github.com/rajivnathan/toolchain-common v0.0.0-20231107215310-b3711428895f/go.mod h1:gyyXkpyEXoJJyHLuHBh/fckZ9XqjeP2AKlKkG/r9wpk=
github.com/rajivnathan/toolchain-common v0.0.0-20231107221232-96f5a5f166db h1:c8gkDkliMGgLYvQScAtu/MWcAXnPieVG5MWQ0T161yk=
github.com/rajivnathan/toolchain-common v0.0.0-20231107221232-96f5a5f166db/go.mod h1:gyyXkpyEXoJJyHLuHBh/fckZ9XqjeP2AKlKkG/r9wpk=
github.com/redhat-cop/operator-utils v1.3.3-0.20220121120056-862ef22b8cdf h1:fsZiv9XuFo8G7IyzFWjG02vqzJG7kSqFvD1Wiq3V/o8=
github.com/redhat-cop/operator-utils v1.3.3-0.20220121120056-862ef22b8cdf/go.mod h1:FfTyeSCu+e2VLgeMh/1RFG8TSkVjKRPEyR6EmDt0RIw=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
Expand Down
4 changes: 2 additions & 2 deletions pkg/webhook/deploy/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func service(namespace string) string {
}

func deployment(namespace, sa string, image string) string {
return fmt.Sprintf(`{"apiVersion":"apps/v1","kind":"Deployment","metadata":{"name":"member-operator-webhook","namespace":"%s","labels":{"app":"member-operator-webhook","toolchain.dev.openshift.com/provider":"codeready-toolchain"}},"spec":{"replicas":1,"selector":{"matchLabels":{"app":"member-operator-webhook"}},"template":{"metadata":{"name":"member-operator-webhook","labels":{"app":"member-operator-webhook"}},"spec":{"serviceAccountName": "%s","containers":[{"name":"mutator","image":"%s","command":["member-operator-webhook"],"imagePullPolicy":"IfNotPresent","resources":{"requests":{"cpu":"75m","memory":"128Mi"}},"volumeMounts":[{"name":"webhook-certs","mountPath":"/etc/webhook/certs","readOnly":true}]}],"volumes":[{"name":"webhook-certs","secret":{"secretName":"webhook-certs"}}]}}}}`, namespace, sa, image)
return fmt.Sprintf(`{"apiVersion":"apps/v1","kind":"Deployment","metadata":{"name":"member-operator-webhook","namespace":"%s","labels":{"app":"member-operator-webhook","toolchain.dev.openshift.com/provider":"codeready-toolchain"}},"spec":{"replicas":1,"selector":{"matchLabels":{"app":"member-operator-webhook"}},"template":{"metadata":{"name":"member-operator-webhook","labels":{"app":"member-operator-webhook"}},"spec":{"serviceAccountName": "%s","containers":[{"name":"mutator","image":"%s","command":["member-operator-webhook"],"imagePullPolicy":"IfNotPresent","env":[{"name":"WATCH_NAMESPACE","valueFrom":{"fieldRef":{"fieldPath":"metadata.namespace"}}}],"resources":{"requests":{"cpu":"75m","memory":"128Mi"}},"volumeMounts":[{"name":"webhook-certs","mountPath":"/etc/webhook/certs","readOnly":true}]}],"volumes":[{"name":"webhook-certs","secret":{"secretName":"webhook-certs"}}]}}}}`, namespace, sa, image)
}

func mutatingWebhookConfig(namespace, caBundle string) string {
Expand All @@ -235,7 +235,7 @@ func serviceAccount(namespace string) string {
}

func clusterRole() string {
return `{"apiVersion": "rbac.authorization.k8s.io/v1","kind": "ClusterRole","metadata": {"creationTimestamp": null,"name": "webhook-role"}, "rules": [{"apiGroups": ["user.openshift.io"],"resources": ["identities","useridentitymappings","users"],"verbs": ["get","list","watch"]},{"apiGroups": ["toolchain.dev.openshift.com"],"resources": ["spacebindingrequests"],"verbs": ["get","list","watch"]},{"apiGroups": ["kubevirt.io"],"resources": ["virtualmachines"],"verbs": ["get","list","watch"]}]}`
return `{"apiVersion": "rbac.authorization.k8s.io/v1","kind": "ClusterRole","metadata": {"creationTimestamp": null,"name": "webhook-role"}, "rules": [{"apiGroups": [""],"resources": ["secrets"],"verbs": ["get","list","watch"]},{"apiGroups": ["user.openshift.io"],"resources": ["identities","useridentitymappings","users"],"verbs": ["get","list","watch"]},{"apiGroups": ["toolchain.dev.openshift.com"],"resources": ["memberoperatorconfigs","spacebindingrequests"],"verbs": ["get","list","watch"]},{"apiGroups": ["kubevirt.io"],"resources": ["virtualmachines"],"verbs": ["get","list","watch"]}]}`
}

func clusterRoleBinding(namespace string) string {
Expand Down
6 changes: 3 additions & 3 deletions pkg/webhook/mutatingwebhook/vm_mutate.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func ensureVolumeConfig(unstructuredRequestObj *unstructured.Unstructured, patch
userData, ok := cloudInitConfig["userData"]
if ok {
// userData is defined, append the ssh key
updatedUserData, err := addSSHKeyToUserData(userData.(string), sshKeys)
updatedUserData, err := addSSHKeysToUserData(userData.(string), sshKeys)
if err != nil {
return patchItems, errors.Wrapf(err, "failed to add ssh key to userData")
}
Expand Down Expand Up @@ -137,8 +137,8 @@ func ensureVolumeConfig(unstructuredRequestObj *unstructured.Unstructured, patch
return patchItems, nil
}

// addSSHKeyToUserData parses the userData YAML and adds the provided ssh key to it or returns an error otherwise
func addSSHKeyToUserData(userDataString string, sshKeys []string) (string, error) {
// addSSHKeysToUserData parses the userData YAML and adds the provided ssh key to it or returns an error otherwise
func addSSHKeysToUserData(userDataString string, sshKeys []string) (string, error) {
userData := map[string]interface{}{}

if err := yaml.Unmarshal([]byte(userDataString), &userData); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/webhook/mutatingwebhook/vm_mutate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func TestAddSSHKeyToUserData(t *testing.T) {

t.Run("no existing keys", func(t *testing.T) {
// when
userDataStr, err := addSSHKeyToUserData(userDataWithoutSSHKey, sshKey)
userDataStr, err := addSSHKeysToUserData(userDataWithoutSSHKey, sshKey)

// then
require.NoError(t, err)
Expand All @@ -304,7 +304,7 @@ func TestAddSSHKeyToUserData(t *testing.T) {

t.Run("pre-existing key", func(t *testing.T) {
// when
userDataStr, err := addSSHKeyToUserData(userDataWithSSHKey, sshKey)
userDataStr, err := addSSHKeysToUserData(userDataWithSSHKey, sshKey)

// then
require.NoError(t, err)
Expand Down

0 comments on commit 378a4bd

Please sign in to comment.