7
7
8
8
trustyaiopendatahubiov1alpha1 "github.com/trustyai-explainability/trustyai-service-operator/api/v1alpha1"
9
9
templateParser "github.com/trustyai-explainability/trustyai-service-operator/controllers/templates"
10
+ apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
10
11
"k8s.io/apimachinery/pkg/api/errors"
11
12
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
12
13
"k8s.io/apimachinery/pkg/types"
@@ -16,6 +17,7 @@ import (
16
17
17
18
const (
18
19
destinationRuleTemplatePath = "service/destination-rule.tmpl.yaml"
20
+ destinationRuleCDRName = "destinationrules.networking.istio.io"
19
21
)
20
22
21
23
// DestinationRuleConfig has the variables for the DestinationRule template
@@ -25,7 +27,25 @@ type DestinationRuleConfig struct {
25
27
DestinationRuleName string
26
28
}
27
29
30
+ // isDestinationRuleCRDPresent returns true if the DestinationRule CRD is present, false otherwise
31
+ func (r * TrustyAIServiceReconciler ) isDestinationRuleCRDPresent (ctx context.Context ) (bool , error ) {
32
+ crd := & apiextensionsv1.CustomResourceDefinition {}
33
+
34
+ err := r .Get (ctx , types.NamespacedName {Name : destinationRuleCDRName }, crd )
35
+ if err != nil {
36
+ if ! errors .IsNotFound (err ) {
37
+ return false , fmt .Errorf ("error getting " + destinationRuleCDRName + " CRD: %v" , err )
38
+ }
39
+ // Not found
40
+ return false , nil
41
+ }
42
+
43
+ // Found
44
+ return true , nil
45
+ }
46
+
28
47
func (r * TrustyAIServiceReconciler ) ensureDestinationRule (ctx context.Context , instance * trustyaiopendatahubiov1alpha1.TrustyAIService ) error {
48
+
29
49
destinationRuleName := instance .Name + "-internal"
30
50
31
51
existingDestinationRule := & unstructured.Unstructured {}
0 commit comments