func istioRules()

in appconfigmgrv2/controllers/istio_rules.go [64:93]


func istioRules(cfg Config, t *appconfig.AppEnvConfigTemplateV2) ([]*unstructured.Unstructured, error) {
	list := make([]*unstructured.Unstructured, 0, len(t.Spec.Services))
	gvk := istioRuleGVK()

	for i := range t.Spec.Services {
		var allowedClients types.ListValue
		for _, allowed := range t.Spec.Services[i].AllowedClients {
			allowedClients.Values = append(allowedClients.Values, &types.Value{Kind: &types.Value_StringValue{StringValue: allowed.Name}})
		}

		meta := map[string]interface{}{
			"name":      istioRuleName(t, i),
			"namespace": t.Namespace,
		}
		spec := &v1beta1.Rule{
			Match: fmt.Sprintf(`destination.labels["app"] == "%v"`, t.Spec.Services[i].Name),
			Actions: []*v1beta1.Action{
				{Handler: istioWhitelistHandlerName(t, i), Instances: []string{istioAppLabelInstanceName(t)}},
			},
		}

		unst, err := unstructuredFromProto(gvk, meta, spec)
		if err != nil {
			return nil, fmt.Errorf("unstructured from proto: %v", err)
		}
		list = append(list, unst)
	}

	return list, nil
}