MCPcopy Create free account
hub / github.com/devfile/devworkspace-operator / CreateWebhookSA

Function CreateWebhookSA

pkg/webhook/service_account.go:30–62  ·  view source on GitHub ↗
(client crclient.Client,
	ctx context.Context,
	namespace string)

Source from the content-addressed store, hash-verified

28)
29
30func CreateWebhookSA(client crclient.Client,
31 ctx context.Context,
32 namespace string) error {
33
34 serviceAccount, err := getSpecServiceAccount(namespace)
35 if err != nil {
36 return err
37 }
38
39 if err := client.Create(ctx, serviceAccount); err != nil {
40 if !apierrors.IsAlreadyExists(err) {
41 return err
42 }
43 existingCfg, err := getClusterServiceAccount(client, ctx, namespace)
44 if err != nil {
45 return err
46 }
47 if needsUpdate(serviceAccount, existingCfg) {
48 serviceAccount.ResourceVersion = existingCfg.ResourceVersion
49 err = client.Update(ctx, serviceAccount)
50 if err != nil {
51 return err
52 }
53 log.Info("Updated webhook server service account")
54 } else {
55 log.Info("Webhook server service account up to date")
56 }
57 } else {
58 log.Info("Created webhook server service account")
59 }
60
61 return nil
62}
63
64func getSpecServiceAccount(namespace string) (*corev1.ServiceAccount, error) {
65 serviceAccount := &corev1.ServiceAccount{

Callers 1

setUpWebhookServerRBACFunction · 0.85

Calls 3

getSpecServiceAccountFunction · 0.85
getClusterServiceAccountFunction · 0.85
needsUpdateFunction · 0.85

Tested by

no test coverage detected