@@ -12,12 +12,23 @@ import (
1212 "sigs.k8s.io/controller-runtime/pkg/client"
1313
1414 "github.com/alecthomas/kong"
15+ apps "github.com/ninech/apis/apps/v1alpha1"
16+ infrastructure "github.com/ninech/apis/infrastructure/v1alpha1"
1517 meta "github.com/ninech/apis/meta/v1alpha1"
1618 networking "github.com/ninech/apis/networking/v1alpha1"
19+ storage "github.com/ninech/apis/storage/v1alpha1"
1720 "github.com/ninech/nctl/api"
1821 "github.com/ninech/nctl/internal/cli"
1922)
2023
24+ // These might be replaced to fetch compatible resources from the schema.
25+ var (
26+ // allowedSources are the allowed source kinds for a service connection.
27+ allowedSources = []string {infrastructure .KubernetesClusterKind , apps .ApplicationKind }
28+ // allowedDestinations are the allowed destination kinds for a service connection.
29+ allowedDestinations = []string {storage .KeyValueStoreKind , storage .MySQLKind , storage .PostgresKind , storage .MySQLDatabaseKind }
30+ )
31+
2132type serviceConnectionCmd struct {
2233 resourceCmd
2334 Source TypedReference `placeholder:"kind/name" help:"Source of the connection in the form kind/name. Allowed source kinds are: ${allowed_sources}." required:""`
@@ -200,32 +211,26 @@ func groupVersionKindFromKind(kind string) (schema.GroupVersionKind, error) {
200211 return schema.GroupVersionKind {}, fmt .Errorf ("error creating scheme: %w" , err )
201212 }
202213
203- var availableKinds []string
204214 for gvk := range scheme .AllKnownTypes () {
205215 if strings .EqualFold (kind , gvk .Kind ) {
206216 return gvk , nil
207217 }
208- // Collect non-list kinds for error message
209- if ! strings .HasSuffix (gvk .Kind , "List" ) && gvk .Kind != "" {
210- availableKinds = append (availableKinds , strings .ToLower (gvk .Kind ))
211- }
212218 }
213219
214220 return schema.GroupVersionKind {}, cli .ErrorWithContext (fmt .Errorf ("kind %q is invalid" , kind )).
215221 WithExitCode (cli .ExitUsageError ).
216- WithAvailable (availableKinds ... ).
217222 WithSuggestions (
218- "Valid source kinds: kubernetescluster, application" ,
219- "Valid destination kinds: keyvaluestore, mysql, postgres, mysqldatabase, postgresdatabase" ,
223+ "Valid source kinds: " + strings . Join ( allowedSources , ", " ) ,
224+ "Valid destination kinds: " + strings . Join ( allowedDestinations , ", " ) ,
220225 )
221226}
222227
223228// ServiceConnectionKongVars returns all variables which are used in the ServiceConnection
224229// create command
225230func ServiceConnectionKongVars () kong.Vars {
226231 result := make (kong.Vars )
227- result ["allowed_sources" ] = "kubernetescluster, application"
228- result ["allowed_destinations" ] = "keyvaluestore, mysql, postgres, mysqldatabase, postgresdatabase"
232+ result ["allowed_sources" ] = strings . Join ( allowedSources , ", " )
233+ result ["allowed_destinations" ] = strings . Join ( allowedDestinations , ", " )
229234 result ["label_selector_placeholder" ] = "'key1=value1,key2=value2,key3 in (value3)'"
230235 result ["label_selector_usage" ] = "Selector (label query) to filter on, supports '=', '==', '!=', 'in', 'notin'. Matching objects must satisfy all of the specified label constraints."
231236 result ["label_selector_requirements" ] = "Can only be set when the source is a KubernetesCluster."
0 commit comments