1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use super::*;

pub trait ServiceAccountExt: super::ResourceBuilder {
    fn new(name: impl ToString) -> Self;

    fn automount_service_account_token(self, yes: bool) -> Self;

    fn image_pull_secret(self, secret: impl ToString) -> Self;

    fn image_pull_secrets(self, secrets: impl IntoIterator<Item = impl ToString>) -> Self;
}

impl ServiceAccountExt for corev1::ServiceAccount {
    fn new(name: impl ToString) -> Self {
        let metadata = metadata(name);
        Self {
            metadata,
            // automount_service_account_token: todo!(),
            // image_pull_secrets: todo!(),
            // secrets: todo!(),
            ..default()
        }
    }

    fn automount_service_account_token(self, yes: bool) -> Self {
        let automount_service_account_token = Some(yes);
        Self {
            automount_service_account_token,
            ..self
        }
    }

    fn image_pull_secret(self, name: impl ToString) -> Self {
        let name = Some(name.to_string());
        let secret = corev1::LocalObjectReference { name };
        let image_pull_secrets = Some(vec![secret]);
        Self {
            image_pull_secrets,
            ..self
        }
    }

    fn image_pull_secrets(self, secrets: impl IntoIterator<Item = impl ToString>) -> Self {
        let secrets = secrets
            .into_iter()
            .map(|secret| Some(secret.to_string()))
            .map(|name| corev1::LocalObjectReference { name })
            .collect();
        let image_pull_secrets = Some(secrets);
        Self {
            image_pull_secrets,
            ..self
        }
    }
}