Skip to content

Commit 7bf7e40

Browse files
committed
Merge branch 'issue-660' into dev
2 parents d9b140c + fd82309 commit 7bf7e40

File tree

1 file changed

+51
-0
lines changed
  • cmd/aws-application-networking-k8s

1 file changed

+51
-0
lines changed

cmd/aws-application-networking-k8s/main.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package main
1919
import (
2020
"context"
2121
"flag"
22+
"fmt"
2223
"os"
2324
"strings"
2425

@@ -28,6 +29,7 @@ import (
2829
"github.com/go-logr/zapr"
2930
"go.uber.org/zap/zapcore"
3031
k8swebhook "sigs.k8s.io/controller-runtime/pkg/webhook"
32+
gwv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2"
3133

3234
"github.com/aws/aws-application-networking-k8s/pkg/aws"
3335
"github.com/aws/aws-application-networking-k8s/pkg/utils/gwlog"
@@ -95,6 +97,51 @@ func addOptionalCRDs(scheme *runtime.Scheme) {
9597
metav1.AddToGroupVersion(scheme, groupVersion)
9698
}
9799

100+
func checkRequiredCRDs(mgr ctrl.Manager) error {
101+
// Add or update the required CRDs when new CRDs are added to the project
102+
requiredCRDs := []schema.GroupVersionKind{
103+
{
104+
Group: gwv1.GroupVersion.Group,
105+
Version: gwv1.GroupVersion.Version,
106+
Kind: "Gateway",
107+
},
108+
{
109+
Group: gwv1.GroupVersion.Group,
110+
Version: gwv1.GroupVersion.Version,
111+
Kind: "GatewayClass",
112+
},
113+
{
114+
Group: gwv1.GroupVersion.Group,
115+
Version: gwv1.GroupVersion.Version,
116+
Kind: "HTTPRoute",
117+
},
118+
{
119+
Group: gwv1.GroupVersion.Group,
120+
Version: gwv1.GroupVersion.Version,
121+
Kind: "GRPCRoute",
122+
},
123+
{
124+
Group: gwv1alpha2.GroupVersion.Group,
125+
Version: gwv1alpha2.GroupVersion.Version,
126+
Kind: "TLSRoute",
127+
},
128+
}
129+
missingCRDs := make([]string, 0, len(requiredCRDs))
130+
for _, crd := range requiredCRDs {
131+
ok, err := k8s.IsGVKSupported(mgr, crd.GroupVersion().String(), crd.Kind)
132+
if err != nil {
133+
return fmt.Errorf("error checking required CRD %s: %w", crd, err)
134+
}
135+
if !ok {
136+
missingCRDs = append(missingCRDs, crd.String())
137+
}
138+
}
139+
if len(missingCRDs) > 0 {
140+
return fmt.Errorf("missing required CRDs: %s", strings.Join(missingCRDs, ", "))
141+
}
142+
return nil
143+
}
144+
98145
func main() {
99146
var metricsAddr string
100147
var enableLeaderElection bool
@@ -170,6 +217,10 @@ func main() {
170217
setupLog.Fatal("manager setup failed:", err)
171218
}
172219

220+
if err := checkRequiredCRDs(mgr); err != nil {
221+
setupLog.Fatal("required CRDs check failed:", err)
222+
}
223+
173224
if enableWebhook {
174225
logger := log.Named("pod-readiness-gate-injector")
175226
readinessGateInjector := webhook.NewPodReadinessGateInjector(

0 commit comments

Comments
 (0)