This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 276
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ref(cli): extract policy check-pod helpers into pkg/cli for reuse
Signed-off-by: Sanya Kochhar <[email protected]>
- Loading branch information
1 parent
4dcc321
commit aa36b91
Showing
2 changed files
with
46 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package cli | ||
|
||
import ( | ||
"github.com/servicemeshinterface/smi-sdk-go/pkg/apis/access/v1alpha3" | ||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
const ( | ||
serviceAccountKind = "ServiceAccount" | ||
) | ||
|
||
// DoesTargetRefDstPod checks whether the TrafficTarget spec refers to the destination pod's service account | ||
func DoesTargetRefDstPod(spec v1alpha3.TrafficTargetSpec, dstPod *corev1.Pod) bool { | ||
if spec.Destination.Kind != serviceAccountKind { | ||
return false | ||
} | ||
|
||
// Map traffic targets to the given pods | ||
if spec.Destination.Name == dstPod.Spec.ServiceAccountName && spec.Destination.Namespace == dstPod.Namespace { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
// DoesTargetRefSrcPod checks whether the TrafficTarget spec refers to the source pod's service account | ||
func DoesTargetRefSrcPod(spec v1alpha3.TrafficTargetSpec, srcPod *corev1.Pod) bool { | ||
for _, source := range spec.Sources { | ||
if source.Kind != serviceAccountKind { | ||
continue | ||
} | ||
|
||
if source.Name == srcPod.Spec.ServiceAccountName && source.Namespace == srcPod.Namespace { | ||
return true | ||
} | ||
} | ||
return false | ||
} |