forked from argoproj/argo-cd
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
87 additions
and
0 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,79 @@ | ||
package reporter | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
appv1 "github.com/argoproj/argo-cd/v2/pkg/apis/application/v1alpha1" | ||
appsv1 "k8s.io/api/apps/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
) | ||
|
||
type ResourceTypeKey struct { | ||
Group string | ||
Kind string | ||
} | ||
|
||
var allowedResourceTypes = map[ResourceTypeKey]bool{ | ||
// Kubernetes core resources | ||
{Group: appsv1.GroupName, Kind: "ReplicaSet"}: true, | ||
{Group: appsv1.GroupName, Kind: "Deployment"}: true, | ||
{Group: appsv1.GroupName, Kind: "StatefulSet"}: true, | ||
{Group: corev1.GroupName, Kind: "Service"}: true, | ||
{Group: corev1.GroupName, Kind: "ConfigMap"}: true, | ||
|
||
// Argo CD resources | ||
{Group: "argoproj.io", Kind: "Application"}: true, | ||
{Group: "argoproj.io", Kind: "ApplicationSet"}: true, | ||
|
||
// Argo Rollouts resources | ||
{Group: "argoproj.io", Kind: "Rollout"}: true, | ||
{Group: "argoproj.io", Kind: "AnalysisRun"}: true, | ||
|
||
// Argo Workflows resources | ||
{Group: "argoproj.io", Kind: "Workflow"}: true, | ||
{Group: "argoproj.io", Kind: "WorkflowTemplate"}: true, | ||
{Group: "argoproj.io", Kind: "ClusterWorkflowTemplate"}: true, | ||
|
||
// Argo Events resources | ||
{Group: "argoproj.io", Kind: "Sensor"}: true, | ||
|
||
// Codefresh resources | ||
{Group: "codefresh.io", Kind: "Product"}: true, | ||
{Group: "codefresh.io", Kind: "PromotionFlow"}: true, | ||
{Group: "codefresh.io", Kind: "PromotionPolicy"}: true, | ||
{Group: "codefresh.io", Kind: "PromotionTemplate"}: true, | ||
{Group: "codefresh.io", Kind: "RestrictedGitSource"}: true, | ||
} | ||
|
||
const ( | ||
CODEFRESH_IO_ENTITY = "codefresh_io_entity" | ||
GIT_PAT_OBTAINER_NAME = "git-pat-obtainer-name" | ||
CODEFRESH_CM_NAME = "codefresh-cm" | ||
) | ||
|
||
func isAllowedResource(rs appv1.ResourceStatus) bool { | ||
gvk := rs.GroupVersionKind() | ||
resourceKey := ResourceTypeKey{ | ||
Group: gvk.Group, | ||
Kind: gvk.Kind, | ||
} | ||
|
||
return allowedResourceTypes[resourceKey] | ||
} | ||
|
||
func isAllowedConfigMap(manifest string) bool { | ||
var u unstructured.Unstructured | ||
if err := json.Unmarshal([]byte(manifest), &u); err != nil { | ||
return false | ||
} | ||
|
||
// Check if it's the codefresh-cm | ||
if u.GetName() == CODEFRESH_CM_NAME { | ||
return true | ||
} | ||
|
||
// Check for the git-pat-obtainer label | ||
labels := u.GetLabels() | ||
return labels != nil && labels[CODEFRESH_IO_ENTITY] == GIT_PAT_OBTAINER_NAME | ||
} |