@@ -2,7 +2,9 @@ package utils
2
2
3
3
import (
4
4
"bytes"
5
+ "context"
5
6
"encoding/json"
7
+ "errors"
6
8
"fmt"
7
9
"os"
8
10
"sort"
@@ -14,6 +16,7 @@ import (
14
16
"k8s.io/client-go/kubernetes/scheme"
15
17
"k8s.io/client-go/rest"
16
18
"k8s.io/client-go/tools/remotecommand"
19
+ "sigs.k8s.io/controller-runtime/pkg/client"
17
20
18
21
"github.com/application-stacks/runtime-component-operator/common"
19
22
prometheusv1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
@@ -27,6 +30,7 @@ import (
27
30
"k8s.io/apimachinery/pkg/api/resource"
28
31
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
29
32
"k8s.io/apimachinery/pkg/runtime"
33
+ "k8s.io/apimachinery/pkg/types"
30
34
"k8s.io/apimachinery/pkg/util/intstr"
31
35
servingv1 "knative.dev/serving/pkg/apis/serving/v1"
32
36
)
@@ -126,7 +130,9 @@ func CustomizeRoute(route *routev1.Route, ba common.BaseComponent, key string, c
126
130
route .Spec .TLS .CACertificate = ""
127
131
route .Spec .TLS .Key = ""
128
132
route .Spec .TLS .DestinationCACertificate = ""
129
- route .Spec .TLS .InsecureEdgeTerminationPolicy = ""
133
+ if rt .GetInsecureEdgeTerminationPolicy () != nil {
134
+ route .Spec .TLS .InsecureEdgeTerminationPolicy = * rt .GetInsecureEdgeTerminationPolicy ()
135
+ }
130
136
} else if route .Spec .TLS .Termination == routev1 .TLSTerminationEdge {
131
137
route .Spec .TLS .Certificate = crt
132
138
route .Spec .TLS .CACertificate = ca
@@ -1042,3 +1048,38 @@ func (r *ReconcilerBase) toJSONFromRaw(content *runtime.RawExtension) (map[strin
1042
1048
}
1043
1049
return data , nil
1044
1050
}
1051
+
1052
+ // Looks for a pull secret in the service account retrieved from the component
1053
+ // Returns nil if there is at least one image pull secret, otherwise an error
1054
+ func ServiceAccountPullSecretExists (ba common.BaseComponent , client client.Client ) error {
1055
+ obj := ba .(metav1.Object )
1056
+ ns := obj .GetNamespace ()
1057
+ saName := obj .GetName ()
1058
+ if ba .GetServiceAccountName () != nil && * ba .GetServiceAccountName () != "" {
1059
+ saName = * ba .GetServiceAccountName ()
1060
+ }
1061
+
1062
+ sa := & corev1.ServiceAccount {}
1063
+ getErr := client .Get (context .TODO (), types.NamespacedName {Name : saName , Namespace : ns }, sa )
1064
+ if getErr != nil {
1065
+ return getErr
1066
+ }
1067
+ secrets := sa .ImagePullSecrets
1068
+ found := false
1069
+ if len (secrets ) > 0 {
1070
+ // if this is our service account there will be one image pull secret
1071
+ // For others there could be more. either way, just use the first?
1072
+ sName := secrets [0 ].Name
1073
+ err := client .Get (context .TODO (), types.NamespacedName {Name : sName , Namespace : ns }, & corev1.Secret {})
1074
+ if err != nil {
1075
+ return err
1076
+ }
1077
+ found = true
1078
+
1079
+ }
1080
+ if ! found {
1081
+ saErr := errors .New ("Service account " + saName + " isn't ready" )
1082
+ return saErr
1083
+ }
1084
+ return nil
1085
+ }
0 commit comments