(metaObj metav1.ObjectMeta)
| 76 | ) |
| 77 | |
| 78 | func GetServerlessPlatform(metaObj metav1.ObjectMeta) (platform string, err error) { |
| 79 | metaLabels := metaObj.Labels |
| 80 | metaAnnotations := metaObj.Annotations |
| 81 | |
| 82 | // Setting both DeprecatedServerlessPlatformKey and common.InjectServerless is not allowed |
| 83 | if KeyMatched(metaLabels, DeprecatedServerlessPlatformKey) && enabled(metaLabels, common.InjectServerless) { |
| 84 | err = fmt.Errorf("\"%s\" and \"%s\" is not allowed to set together, remove \"%s\" and retry", DeprecatedServerlessPlatformKey, common.InjectServerless, DeprecatedServerlessPlatformKey) |
| 85 | return |
| 86 | } |
| 87 | |
| 88 | // handle deprecated serverless platform key. |
| 89 | if KeyMatched(metaLabels, DeprecatedServerlessPlatformKey) { |
| 90 | platform = metaLabels[DeprecatedServerlessPlatformKey] |
| 91 | return |
| 92 | } |
| 93 | |
| 94 | // handle deprecated common.InjectFuseSidecar. In this case, |
| 95 | // only two platforms are supported: PlatformDefault and PlatformUnprivileged |
| 96 | if enabled(metaLabels, common.InjectFuseSidecar) { |
| 97 | if enabled(metaLabels, common.InjectUnprivilegedFuseSidecar) { |
| 98 | platform = ServerlessPlatformUnprivileged |
| 99 | } else { |
| 100 | platform = ServerlessPlatformDefault |
| 101 | } |
| 102 | return |
| 103 | } |
| 104 | |
| 105 | if enabled(metaLabels, common.InjectServerless) { |
| 106 | if enabled(metaLabels, common.InjectUnprivilegedFuseSidecar) { |
| 107 | platform = ServerlessPlatformUnprivileged |
| 108 | return |
| 109 | } |
| 110 | |
| 111 | // Setting common.InjectServerless in labels and common.AnnotationServerlessPlatform in annotations |
| 112 | // together to indicate the serverless platform |
| 113 | if KeyMatched(metaAnnotations, common.AnnotationServerlessPlatform) { |
| 114 | platform = metaAnnotations[common.AnnotationServerlessPlatform] |
| 115 | return |
| 116 | } |
| 117 | |
| 118 | platform = ServerlessPlatformDefault |
| 119 | return |
| 120 | } |
| 121 | |
| 122 | // default to an empty platform, meaning no platform is found |
| 123 | return "", fmt.Errorf("no serverless platform can be found from Pod's metadata") |
| 124 | } |
| 125 | |
| 126 | // ServerlessEnabled decides if fuse sidecar should be injected, whether privileged or unprivileged |
| 127 | // We don't have to know which serverless platform it is using here. |
no test coverage detected