diff --git a/apps/console/internal/app/graph/generated/generated.go b/apps/console/internal/app/graph/generated/generated.go index 0abc4321f..f7df0da48 100644 --- a/apps/console/internal/app/graph/generated/generated.go +++ b/apps/console/internal/app/graph/generated/generated.go @@ -937,7 +937,7 @@ type ManagedResourceResolver interface { UpdateTime(ctx context.Context, obj *entities.ManagedResource) (string, error) } type MatchFilterResolver interface { - MatchType(ctx context.Context, obj *repos.MatchFilter) (string, error) + MatchType(ctx context.Context, obj *repos.MatchFilter) (model.GithubComKloudliteAPIPkgReposMatchType, error) } type MetadataResolver interface { Annotations(ctx context.Context, obj *v13.ObjectMeta) (map[string]interface{}, error) @@ -1072,7 +1072,7 @@ type ManagedResourceInResolver interface { Spec(ctx context.Context, obj *entities.ManagedResource, data *model.GithubComKloudliteOperatorApisCrdsV1ManagedResourceSpecIn) error } type MatchFilterInResolver interface { - MatchType(ctx context.Context, obj *repos.MatchFilter, data string) error + MatchType(ctx context.Context, obj *repos.MatchFilter, data model.GithubComKloudliteAPIPkgReposMatchType) error } type MetadataInResolver interface { Annotations(ctx context.Context, obj *v13.ObjectMeta, data map[string]interface{}) error @@ -6054,6 +6054,13 @@ enum Github__com___kloudlite___api___apps___console___internal___entities__PullS params } +enum Github__com___kloudlite___api___pkg___repos__MatchType { + array + exact + not_in_array + regex +} + enum Github__com___kloudlite___api___pkg___types__SyncAction { APPLY DELETE @@ -6460,7 +6467,7 @@ input ManagedResourceKeyValueRefIn { {Name: "../struct-to-graphql/matchfilter.graphqls", Input: `type MatchFilter @shareable { array: [Any!] exact: Any - matchType: String! + matchType: Github__com___kloudlite___api___pkg___repos__MatchType! notInArray: [Any!] regex: String } @@ -6468,7 +6475,7 @@ input ManagedResourceKeyValueRefIn { input MatchFilterIn { array: [Any!] exact: Any - matchType: String! + matchType: Github__com___kloudlite___api___pkg___repos__MatchType! notInArray: [Any!] regex: String } @@ -25331,9 +25338,9 @@ func (ec *executionContext) _MatchFilter_matchType(ctx context.Context, field gr } return graphql.Null } - res := resTmp.(string) + res := resTmp.(model.GithubComKloudliteAPIPkgReposMatchType) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNGithub__com___kloudlite___api___pkg___repos__MatchType2githubᚗcomᚋkloudliteᚋapiᚋappsᚋconsoleᚋinternalᚋappᚋgraphᚋmodelᚐGithubComKloudliteAPIPkgReposMatchType(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_MatchFilter_matchType(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -25343,7 +25350,7 @@ func (ec *executionContext) fieldContext_MatchFilter_matchType(ctx context.Conte IsMethod: true, IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type String does not have child fields") + return nil, errors.New("field of type Github__com___kloudlite___api___pkg___repos__MatchType does not have child fields") }, } return fc, nil @@ -40167,7 +40174,7 @@ func (ec *executionContext) unmarshalInputMatchFilterIn(ctx context.Context, obj var err error ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("matchType")) - data, err := ec.unmarshalNString2string(ctx, v) + data, err := ec.unmarshalNGithub__com___kloudlite___api___pkg___repos__MatchType2githubᚗcomᚋkloudliteᚋapiᚋappsᚋconsoleᚋinternalᚋappᚋgraphᚋmodelᚐGithubComKloudliteAPIPkgReposMatchType(ctx, v) if err != nil { return it, err } @@ -48852,6 +48859,16 @@ func (ec *executionContext) marshalNGithub__com___kloudlite___api___common__Crea return ec._Github__com___kloudlite___api___common__CreatedOrUpdatedBy(ctx, sel, &v) } +func (ec *executionContext) unmarshalNGithub__com___kloudlite___api___pkg___repos__MatchType2githubᚗcomᚋkloudliteᚋapiᚋappsᚋconsoleᚋinternalᚋappᚋgraphᚋmodelᚐGithubComKloudliteAPIPkgReposMatchType(ctx context.Context, v interface{}) (model.GithubComKloudliteAPIPkgReposMatchType, error) { + var res model.GithubComKloudliteAPIPkgReposMatchType + err := res.UnmarshalGQL(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNGithub__com___kloudlite___api___pkg___repos__MatchType2githubᚗcomᚋkloudliteᚋapiᚋappsᚋconsoleᚋinternalᚋappᚋgraphᚋmodelᚐGithubComKloudliteAPIPkgReposMatchType(ctx context.Context, sel ast.SelectionSet, v model.GithubComKloudliteAPIPkgReposMatchType) graphql.Marshaler { + return v +} + func (ec *executionContext) unmarshalNGithub__com___kloudlite___api___pkg___types__SyncAction2githubᚗcomᚋkloudliteᚋapiᚋpkgᚋtypesᚐSyncAction(ctx context.Context, v interface{}) (types.SyncAction, error) { tmp, err := graphql.UnmarshalString(v) res := types.SyncAction(tmp) @@ -50264,7 +50281,7 @@ func (ec *executionContext) marshalNfederation__Scope2ᚕᚕstringᚄ(ctx contex return ret } -func (ec *executionContext) unmarshalOAny2interface(ctx context.Context, v interface{}) (interface{}, error) { +func (ec *executionContext) unmarshalOAny2interface(ctx context.Context, v interface{}) (any, error) { if v == nil { return nil, nil } @@ -50272,7 +50289,7 @@ func (ec *executionContext) unmarshalOAny2interface(ctx context.Context, v inter return res, graphql.ErrorOnPath(ctx, err) } -func (ec *executionContext) marshalOAny2interface(ctx context.Context, sel ast.SelectionSet, v interface{}) graphql.Marshaler { +func (ec *executionContext) marshalOAny2interface(ctx context.Context, sel ast.SelectionSet, v any) graphql.Marshaler { if v == nil { return graphql.Null } diff --git a/apps/console/internal/app/graph/matchfilter.resolvers.go b/apps/console/internal/app/graph/matchfilter.resolvers.go index df256f810..ca7acb50a 100644 --- a/apps/console/internal/app/graph/matchfilter.resolvers.go +++ b/apps/console/internal/app/graph/matchfilter.resolvers.go @@ -9,16 +9,17 @@ import ( "fmt" "github.com/kloudlite/api/apps/console/internal/app/graph/generated" + "github.com/kloudlite/api/apps/console/internal/app/graph/model" "github.com/kloudlite/api/pkg/repos" ) // MatchType is the resolver for the matchType field. -func (r *matchFilterResolver) MatchType(ctx context.Context, obj *repos.MatchFilter) (string, error) { +func (r *matchFilterResolver) MatchType(ctx context.Context, obj *repos.MatchFilter) (model.GithubComKloudliteAPIPkgReposMatchType, error) { panic(fmt.Errorf("not implemented: MatchType - matchType")) } // MatchType is the resolver for the matchType field. -func (r *matchFilterInResolver) MatchType(ctx context.Context, obj *repos.MatchFilter, data string) error { +func (r *matchFilterInResolver) MatchType(ctx context.Context, obj *repos.MatchFilter, data model.GithubComKloudliteAPIPkgReposMatchType) error { panic(fmt.Errorf("not implemented: MatchType - matchType")) } diff --git a/apps/console/internal/app/graph/model/models_gen.go b/apps/console/internal/app/graph/model/models_gen.go index cf85df621..f07b193a6 100644 --- a/apps/console/internal/app/graph/model/models_gen.go +++ b/apps/console/internal/app/graph/model/models_gen.go @@ -840,6 +840,51 @@ func (e GithubComKloudliteAPIAppsConsoleInternalEntitiesPullSecretFormat) Marsha fmt.Fprint(w, strconv.Quote(e.String())) } +type GithubComKloudliteAPIPkgReposMatchType string + +const ( + GithubComKloudliteAPIPkgReposMatchTypeArray GithubComKloudliteAPIPkgReposMatchType = "array" + GithubComKloudliteAPIPkgReposMatchTypeExact GithubComKloudliteAPIPkgReposMatchType = "exact" + GithubComKloudliteAPIPkgReposMatchTypeNotInArray GithubComKloudliteAPIPkgReposMatchType = "not_in_array" + GithubComKloudliteAPIPkgReposMatchTypeRegex GithubComKloudliteAPIPkgReposMatchType = "regex" +) + +var AllGithubComKloudliteAPIPkgReposMatchType = []GithubComKloudliteAPIPkgReposMatchType{ + GithubComKloudliteAPIPkgReposMatchTypeArray, + GithubComKloudliteAPIPkgReposMatchTypeExact, + GithubComKloudliteAPIPkgReposMatchTypeNotInArray, + GithubComKloudliteAPIPkgReposMatchTypeRegex, +} + +func (e GithubComKloudliteAPIPkgReposMatchType) IsValid() bool { + switch e { + case GithubComKloudliteAPIPkgReposMatchTypeArray, GithubComKloudliteAPIPkgReposMatchTypeExact, GithubComKloudliteAPIPkgReposMatchTypeNotInArray, GithubComKloudliteAPIPkgReposMatchTypeRegex: + return true + } + return false +} + +func (e GithubComKloudliteAPIPkgReposMatchType) String() string { + return string(e) +} + +func (e *GithubComKloudliteAPIPkgReposMatchType) UnmarshalGQL(v interface{}) error { + str, ok := v.(string) + if !ok { + return fmt.Errorf("enums must be strings") + } + + *e = GithubComKloudliteAPIPkgReposMatchType(str) + if !e.IsValid() { + return fmt.Errorf("%s is not a valid Github__com___kloudlite___api___pkg___repos__MatchType", str) + } + return nil +} + +func (e GithubComKloudliteAPIPkgReposMatchType) MarshalGQL(w io.Writer) { + fmt.Fprint(w, strconv.Quote(e.String())) +} + type GithubComKloudliteOperatorApisCrdsV1ConfigOrSecret string const ( diff --git a/apps/console/internal/app/graph/struct-to-graphql/common-types.graphqls b/apps/console/internal/app/graph/struct-to-graphql/common-types.graphqls index 0884c61de..72dd19b71 100644 --- a/apps/console/internal/app/graph/struct-to-graphql/common-types.graphqls +++ b/apps/console/internal/app/graph/struct-to-graphql/common-types.graphqls @@ -636,6 +636,13 @@ enum Github__com___kloudlite___api___apps___console___internal___entities__PullS params } +enum Github__com___kloudlite___api___pkg___repos__MatchType { + array + exact + not_in_array + regex +} + enum Github__com___kloudlite___api___pkg___types__SyncAction { APPLY DELETE diff --git a/apps/console/internal/app/graph/struct-to-graphql/matchfilter.graphqls b/apps/console/internal/app/graph/struct-to-graphql/matchfilter.graphqls index c60308168..e1e59fb4d 100644 --- a/apps/console/internal/app/graph/struct-to-graphql/matchfilter.graphqls +++ b/apps/console/internal/app/graph/struct-to-graphql/matchfilter.graphqls @@ -1,7 +1,7 @@ type MatchFilter @shareable { array: [Any!] exact: Any - matchType: String! + matchType: Github__com___kloudlite___api___pkg___repos__MatchType! notInArray: [Any!] regex: String } @@ -9,7 +9,7 @@ type MatchFilter @shareable { input MatchFilterIn { array: [Any!] exact: Any - matchType: String! + matchType: Github__com___kloudlite___api___pkg___repos__MatchType! notInArray: [Any!] regex: String } diff --git a/apps/console/internal/app/process-error-on-apply.go b/apps/console/internal/app/process-error-on-apply.go index cbb574a06..e63c7b9f0 100644 --- a/apps/console/internal/app/process-error-on-apply.go +++ b/apps/console/internal/app/process-error-on-apply.go @@ -11,6 +11,7 @@ import ( "github.com/kloudlite/api/apps/console/internal/domain" "github.com/kloudlite/api/apps/console/internal/entities" + msgOfficeT "github.com/kloudlite/api/apps/message-office/types" fn "github.com/kloudlite/api/pkg/functions" "github.com/kloudlite/api/pkg/logging" "github.com/kloudlite/api/pkg/messaging" @@ -36,8 +37,14 @@ func ProcessErrorOnApply(consumer ErrorOnApplyConsumer, d domain.Domain, logger msgReader := func(msg *msgTypes.ConsumeMsg) error { counter += 1 logger.Debugf("received message [%d]", counter) + + em, err := msgOfficeT.UnmarshalErrMessage(msg.Payload) + if err != nil { + return errors.NewE(err) + } + var errObj t.AgentErrMessage - if err := json.Unmarshal(msg.Payload, &errObj); err != nil { + if err := json.Unmarshal(em.Error, &errObj); err != nil { return errors.NewE(err) } @@ -45,8 +52,8 @@ func ProcessErrorOnApply(consumer ErrorOnApplyConsumer, d domain.Domain, logger mLogger := logger.WithKV( "gvk", obj.GroupVersionKind(), - "accountName", errObj.AccountName, - "clusterName", errObj.ClusterName, + "accountName", em.AccountName, + "clusterName", em.ClusterName, ) mLogger.Infof("received message") @@ -54,7 +61,7 @@ func ProcessErrorOnApply(consumer ErrorOnApplyConsumer, d domain.Domain, logger mLogger.Infof("processed message") }() - dctx := domain.NewConsoleContext(context.TODO(), "sys-user:apply-on-error-worker", errObj.AccountName) + dctx := domain.NewConsoleContext(context.TODO(), "sys-user:apply-on-error-worker", em.AccountName) opts := domain.UpdateAndDeleteOpts{MessageTimestamp: msg.Timestamp} @@ -103,7 +110,7 @@ func ProcessErrorOnApply(consumer ErrorOnApplyConsumer, d domain.Domain, logger } //case projectManagedServiceGVK.String(): // { - // mapping, err := d.GetProjectResourceMapping(dctx, entities.ResourceTypeProjectManagedService, errObj.ClusterName, obj.GetNamespace(), obj.GetName()) + // mapping, err := d.GetProjectResourceMapping(dctx, entities.ResourceTypeProjectManagedService, em.ClusterName, obj.GetNamespace(), obj.GetName()) // if err != nil { // return err // } @@ -125,7 +132,7 @@ func ProcessErrorOnApply(consumer ErrorOnApplyConsumer, d domain.Domain, logger case appsGVK.String(): { - rctx, err := getEnvironmentResourceContext(dctx, entities.ResourceTypeApp, errObj.ClusterName, obj) + rctx, err := getEnvironmentResourceContext(dctx, entities.ResourceTypeApp, em.ClusterName, obj) if err != nil { return errors.NewE(err) } @@ -143,7 +150,7 @@ func ProcessErrorOnApply(consumer ErrorOnApplyConsumer, d domain.Domain, logger } case externalAppsGVK.String(): { - rctx, err := getEnvironmentResourceContext(dctx, entities.ResourceTypeExternalApp, errObj.ClusterName, obj) + rctx, err := getEnvironmentResourceContext(dctx, entities.ResourceTypeExternalApp, em.ClusterName, obj) if err != nil { return errors.NewE(err) } @@ -161,7 +168,7 @@ func ProcessErrorOnApply(consumer ErrorOnApplyConsumer, d domain.Domain, logger } case configGVK.String(): { - rctx, err := getEnvironmentResourceContext(dctx, entities.ResourceTypeConfig, errObj.ClusterName, obj) + rctx, err := getEnvironmentResourceContext(dctx, entities.ResourceTypeConfig, em.ClusterName, obj) if err != nil { return errors.NewE(err) } @@ -178,7 +185,7 @@ func ProcessErrorOnApply(consumer ErrorOnApplyConsumer, d domain.Domain, logger } case secretGVK.String(): { - rctx, err := getEnvironmentResourceContext(dctx, entities.ResourceTypeSecret, errObj.ClusterName, obj) + rctx, err := getEnvironmentResourceContext(dctx, entities.ResourceTypeSecret, em.ClusterName, obj) if err != nil { return errors.NewE(err) } @@ -195,7 +202,7 @@ func ProcessErrorOnApply(consumer ErrorOnApplyConsumer, d domain.Domain, logger } case routerGVK.String(): { - rctx, err := getEnvironmentResourceContext(dctx, entities.ResourceTypeRouter, errObj.ClusterName, obj) + rctx, err := getEnvironmentResourceContext(dctx, entities.ResourceTypeRouter, em.ClusterName, obj) if err != nil { return errors.NewE(err) } @@ -212,7 +219,7 @@ func ProcessErrorOnApply(consumer ErrorOnApplyConsumer, d domain.Domain, logger } case managedResourceGVK.String(): { - rctx, err := getEnvironmentResourceContext(dctx, entities.ResourceTypeManagedResource, errObj.ClusterName, obj) + rctx, err := getEnvironmentResourceContext(dctx, entities.ResourceTypeManagedResource, em.ClusterName, obj) if err != nil { return errors.NewE(err) } diff --git a/apps/console/internal/app/process-resource-updates.go b/apps/console/internal/app/process-resource-updates.go index daca3a2c3..1c2637d02 100644 --- a/apps/console/internal/app/process-resource-updates.go +++ b/apps/console/internal/app/process-resource-updates.go @@ -8,6 +8,7 @@ import ( "github.com/kloudlite/api/apps/console/internal/domain" "github.com/kloudlite/api/apps/console/internal/entities" + msgOfficeT "github.com/kloudlite/api/apps/message-office/types" "github.com/kloudlite/api/pkg/errors" fn "github.com/kloudlite/api/pkg/functions" "github.com/kloudlite/api/pkg/logging" @@ -61,18 +62,24 @@ func ProcessResourceUpdates(consumer ResourceUpdateConsumer, d domain.Domain, lo counter += 1 logger.Debugf("[%d] received message", counter) - var ru types.ResourceUpdate - if err := json.Unmarshal(msg.Payload, &ru); err != nil { - logger.Errorf(err, "parsing into status update") + ru, err := msgOfficeT.UnmarshalResourceUpdate(msg.Payload) + if err != nil { + logger.Errorf(err, "unmarshaling resource update") + return nil + } + + var rwu types.ResourceUpdate + if err := json.Unmarshal(ru.WatcherUpdate, &rwu); err != nil { + logger.Errorf(err, "unmarshaling into resource watcher update") return nil } - if ru.Object == nil { + if rwu.Object == nil { logger.Infof("msg.Object is nil, so could not extract any info from message, ignoring ...") return nil } - obj := unstructured.Unstructured{Object: ru.Object} + obj := unstructured.Unstructured{Object: rwu.Object} mLogger := logger.WithKV( "gvk", obj.GetObjectKind().GroupVersionKind(), @@ -101,7 +108,7 @@ func ProcessResourceUpdates(consumer ResourceUpdateConsumer, d domain.Domain, lo gvkStr := obj.GetObjectKind().GroupVersionKind().String() resStatus, err := func() (types.ResourceStatus, error) { - v, ok := ru.Object[types.ResourceStatusKey] + v, ok := rwu.Object[types.ResourceStatusKey] if !ok { return "", errors.NewE(fmt.Errorf("field %s not found in object", types.ResourceStatusKey)) } @@ -122,12 +129,12 @@ func ProcessResourceUpdates(consumer ResourceUpdateConsumer, d domain.Domain, lo case deviceGVK.String(): { - dev, err := fn.JsonConvert[entities.ConsoleVPNDevice](ru.Object) + dev, err := fn.JsonConvert[entities.ConsoleVPNDevice](rwu.Object) if err != nil { return errors.NewE(err) } - if v, ok := ru.Object[types.KeyVPNDeviceConfig]; ok { + if v, ok := rwu.Object[types.KeyVPNDeviceConfig]; ok { b, err := json.Marshal(v) if err != nil { return errors.NewE(err) @@ -191,7 +198,7 @@ func ProcessResourceUpdates(consumer ResourceUpdateConsumer, d domain.Domain, lo case environmentGVK.String(): { var ws entities.Environment - if err := fn.JsonConversion(ru.Object, &ws); err != nil { + if err := fn.JsonConversion(rwu.Object, &ws); err != nil { return errors.NewE(err) } @@ -203,7 +210,7 @@ func ProcessResourceUpdates(consumer ResourceUpdateConsumer, d domain.Domain, lo case appsGVK.String(): { var app entities.App - if err := fn.JsonConversion(ru.Object, &app); err != nil { + if err := fn.JsonConversion(rwu.Object, &app); err != nil { return errors.NewE(err) } @@ -220,7 +227,7 @@ func ProcessResourceUpdates(consumer ResourceUpdateConsumer, d domain.Domain, lo case externalAppsGVK.String(): { var extApp entities.ExternalApp - if err := fn.JsonConversion(ru.Object, &extApp); err != nil { + if err := fn.JsonConversion(rwu.Object, &extApp); err != nil { return errors.NewE(err) } @@ -237,7 +244,7 @@ func ProcessResourceUpdates(consumer ResourceUpdateConsumer, d domain.Domain, lo case configGVK.String(): { var config entities.Config - if err := fn.JsonConversion(ru.Object, &config); err != nil { + if err := fn.JsonConversion(rwu.Object, &config); err != nil { return errors.NewE(err) } @@ -254,7 +261,7 @@ func ProcessResourceUpdates(consumer ResourceUpdateConsumer, d domain.Domain, lo case secretGVK.String(): { var secret entities.Secret - if err := fn.JsonConversion(ru.Object, &secret); err != nil { + if err := fn.JsonConversion(rwu.Object, &secret); err != nil { return errors.NewE(err) } @@ -283,7 +290,7 @@ func ProcessResourceUpdates(consumer ResourceUpdateConsumer, d domain.Domain, lo case routerGVK.String(): { var router entities.Router - if err := fn.JsonConversion(ru.Object, &router); err != nil { + if err := fn.JsonConversion(rwu.Object, &router); err != nil { return errors.NewE(err) } @@ -300,7 +307,7 @@ func ProcessResourceUpdates(consumer ResourceUpdateConsumer, d domain.Domain, lo case managedResourceGVK.String(): { var mres entities.ManagedResource - if err := fn.JsonConversion(ru.Object, &mres); err != nil { + if err := fn.JsonConversion(rwu.Object, &mres); err != nil { return errors.NewE(err) } @@ -309,7 +316,7 @@ func ProcessResourceUpdates(consumer ResourceUpdateConsumer, d domain.Domain, lo return errors.NewE(err) } - if v, ok := ru.Object[types.KeyManagedResSecret]; ok { + if v, ok := rwu.Object[types.KeyManagedResSecret]; ok { s, err := fn.JsonConvertP[corev1.Secret](v) if err != nil { mLogger.Infof("managed resource, invalid output secret received") diff --git a/apps/container-registry/internal/app/graph/generated/generated.go b/apps/container-registry/internal/app/graph/generated/generated.go index e2bad7cde..100685307 100644 --- a/apps/container-registry/internal/app/graph/generated/generated.go +++ b/apps/container-registry/internal/app/graph/generated/generated.go @@ -557,7 +557,7 @@ type GitlabProjectResolver interface { LastActivityAt(ctx context.Context, obj *entities.GitlabProject) (*string, error) } type MatchFilterResolver interface { - MatchType(ctx context.Context, obj *repos.MatchFilter) (string, error) + MatchType(ctx context.Context, obj *repos.MatchFilter) (model.GithubComKloudliteAPIPkgReposMatchType, error) } type MetadataResolver interface { Annotations(ctx context.Context, obj *v1.ObjectMeta) (map[string]interface{}, error) @@ -610,7 +610,7 @@ type CredentialInResolver interface { Expiration(ctx context.Context, obj *entities.Credential, data *model.GithubComKloudliteAPIAppsContainerRegistryInternalDomainEntitiesExpirationIn) error } type MatchFilterInResolver interface { - MatchType(ctx context.Context, obj *repos.MatchFilter, data string) error + MatchType(ctx context.Context, obj *repos.MatchFilter, data model.GithubComKloudliteAPIPkgReposMatchType) error } type MetadataInResolver interface { Annotations(ctx context.Context, obj *v1.ObjectMeta, data map[string]interface{}) error @@ -3294,6 +3294,13 @@ enum Github__com___kloudlite___api___apps___container____registry___internal___d read_write } +enum Github__com___kloudlite___api___pkg___repos__MatchType { + array + exact + not_in_array + regex +} + enum Github__com___kloudlite___api___pkg___types__SyncAction { APPLY DELETE @@ -3493,7 +3500,7 @@ directive @goField( {Name: "../struct-to-graphql/matchfilter.graphqls", Input: `type MatchFilter @shareable { array: [Any!] exact: Any - matchType: String! + matchType: Github__com___kloudlite___api___pkg___repos__MatchType! notInArray: [Any!] regex: String } @@ -3501,7 +3508,7 @@ directive @goField( input MatchFilterIn { array: [Any!] exact: Any - matchType: String! + matchType: Github__com___kloudlite___api___pkg___repos__MatchType! notInArray: [Any!] regex: String } @@ -14420,9 +14427,9 @@ func (ec *executionContext) _MatchFilter_matchType(ctx context.Context, field gr } return graphql.Null } - res := resTmp.(string) + res := resTmp.(model.GithubComKloudliteAPIPkgReposMatchType) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNGithub__com___kloudlite___api___pkg___repos__MatchType2githubᚗcomᚋkloudliteᚋapiᚋappsᚋcontainerᚑregistryᚋinternalᚋappᚋgraphᚋmodelᚐGithubComKloudliteAPIPkgReposMatchType(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_MatchFilter_matchType(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -14432,7 +14439,7 @@ func (ec *executionContext) fieldContext_MatchFilter_matchType(ctx context.Conte IsMethod: true, IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type String does not have child fields") + return nil, errors.New("field of type Github__com___kloudlite___api___pkg___repos__MatchType does not have child fields") }, } return fc, nil @@ -21030,7 +21037,7 @@ func (ec *executionContext) unmarshalInputMatchFilterIn(ctx context.Context, obj var err error ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("matchType")) - data, err := ec.unmarshalNString2string(ctx, v) + data, err := ec.unmarshalNGithub__com___kloudlite___api___pkg___repos__MatchType2githubᚗcomᚋkloudliteᚋapiᚋappsᚋcontainerᚑregistryᚋinternalᚋappᚋgraphᚋmodelᚐGithubComKloudliteAPIPkgReposMatchType(ctx, v) if err != nil { return it, err } @@ -26225,6 +26232,16 @@ func (ec *executionContext) marshalNGithub__com___kloudlite___api___common__Crea return ec._Github__com___kloudlite___api___common__CreatedOrUpdatedBy(ctx, sel, &v) } +func (ec *executionContext) unmarshalNGithub__com___kloudlite___api___pkg___repos__MatchType2githubᚗcomᚋkloudliteᚋapiᚋappsᚋcontainerᚑregistryᚋinternalᚋappᚋgraphᚋmodelᚐGithubComKloudliteAPIPkgReposMatchType(ctx context.Context, v interface{}) (model.GithubComKloudliteAPIPkgReposMatchType, error) { + var res model.GithubComKloudliteAPIPkgReposMatchType + err := res.UnmarshalGQL(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNGithub__com___kloudlite___api___pkg___repos__MatchType2githubᚗcomᚋkloudliteᚋapiᚋappsᚋcontainerᚑregistryᚋinternalᚋappᚋgraphᚋmodelᚐGithubComKloudliteAPIPkgReposMatchType(ctx context.Context, sel ast.SelectionSet, v model.GithubComKloudliteAPIPkgReposMatchType) graphql.Marshaler { + return v +} + func (ec *executionContext) unmarshalNGithub__com___kloudlite___api___pkg___types__SyncAction2githubᚗcomᚋkloudliteᚋapiᚋappsᚋcontainerᚑregistryᚋinternalᚋappᚋgraphᚋmodelᚐGithubComKloudliteAPIPkgTypesSyncAction(ctx context.Context, v interface{}) (model.GithubComKloudliteAPIPkgTypesSyncAction, error) { var res model.GithubComKloudliteAPIPkgTypesSyncAction err := res.UnmarshalGQL(v) diff --git a/apps/container-registry/internal/app/graph/matchfilter.resolvers.go b/apps/container-registry/internal/app/graph/matchfilter.resolvers.go index 98803eee1..d90b4533b 100644 --- a/apps/container-registry/internal/app/graph/matchfilter.resolvers.go +++ b/apps/container-registry/internal/app/graph/matchfilter.resolvers.go @@ -9,16 +9,17 @@ import ( "fmt" "github.com/kloudlite/api/apps/container-registry/internal/app/graph/generated" + "github.com/kloudlite/api/apps/container-registry/internal/app/graph/model" "github.com/kloudlite/api/pkg/repos" ) // MatchType is the resolver for the matchType field. -func (r *matchFilterResolver) MatchType(ctx context.Context, obj *repos.MatchFilter) (string, error) { +func (r *matchFilterResolver) MatchType(ctx context.Context, obj *repos.MatchFilter) (model.GithubComKloudliteAPIPkgReposMatchType, error) { panic(fmt.Errorf("not implemented: MatchType - matchType")) } // MatchType is the resolver for the matchType field. -func (r *matchFilterInResolver) MatchType(ctx context.Context, obj *repos.MatchFilter, data string) error { +func (r *matchFilterInResolver) MatchType(ctx context.Context, obj *repos.MatchFilter, data model.GithubComKloudliteAPIPkgReposMatchType) error { panic(fmt.Errorf("not implemented: MatchType - matchType")) } diff --git a/apps/container-registry/internal/app/graph/model/models_gen.go b/apps/container-registry/internal/app/graph/model/models_gen.go index e897d4125..24b4a173f 100644 --- a/apps/container-registry/internal/app/graph/model/models_gen.go +++ b/apps/container-registry/internal/app/graph/model/models_gen.go @@ -512,6 +512,51 @@ func (e GithubComKloudliteAPIAppsContainerRegistryInternalDomainEntitiesRepoAcce fmt.Fprint(w, strconv.Quote(e.String())) } +type GithubComKloudliteAPIPkgReposMatchType string + +const ( + GithubComKloudliteAPIPkgReposMatchTypeArray GithubComKloudliteAPIPkgReposMatchType = "array" + GithubComKloudliteAPIPkgReposMatchTypeExact GithubComKloudliteAPIPkgReposMatchType = "exact" + GithubComKloudliteAPIPkgReposMatchTypeNotInArray GithubComKloudliteAPIPkgReposMatchType = "not_in_array" + GithubComKloudliteAPIPkgReposMatchTypeRegex GithubComKloudliteAPIPkgReposMatchType = "regex" +) + +var AllGithubComKloudliteAPIPkgReposMatchType = []GithubComKloudliteAPIPkgReposMatchType{ + GithubComKloudliteAPIPkgReposMatchTypeArray, + GithubComKloudliteAPIPkgReposMatchTypeExact, + GithubComKloudliteAPIPkgReposMatchTypeNotInArray, + GithubComKloudliteAPIPkgReposMatchTypeRegex, +} + +func (e GithubComKloudliteAPIPkgReposMatchType) IsValid() bool { + switch e { + case GithubComKloudliteAPIPkgReposMatchTypeArray, GithubComKloudliteAPIPkgReposMatchTypeExact, GithubComKloudliteAPIPkgReposMatchTypeNotInArray, GithubComKloudliteAPIPkgReposMatchTypeRegex: + return true + } + return false +} + +func (e GithubComKloudliteAPIPkgReposMatchType) String() string { + return string(e) +} + +func (e *GithubComKloudliteAPIPkgReposMatchType) UnmarshalGQL(v interface{}) error { + str, ok := v.(string) + if !ok { + return fmt.Errorf("enums must be strings") + } + + *e = GithubComKloudliteAPIPkgReposMatchType(str) + if !e.IsValid() { + return fmt.Errorf("%s is not a valid Github__com___kloudlite___api___pkg___repos__MatchType", str) + } + return nil +} + +func (e GithubComKloudliteAPIPkgReposMatchType) MarshalGQL(w io.Writer) { + fmt.Fprint(w, strconv.Quote(e.String())) +} + type GithubComKloudliteAPIPkgTypesSyncAction string const ( diff --git a/apps/container-registry/internal/app/graph/struct-to-graphql/common-types.graphqls b/apps/container-registry/internal/app/graph/struct-to-graphql/common-types.graphqls index eb14f4de4..f736d876b 100644 --- a/apps/container-registry/internal/app/graph/struct-to-graphql/common-types.graphqls +++ b/apps/container-registry/internal/app/graph/struct-to-graphql/common-types.graphqls @@ -282,6 +282,13 @@ enum Github__com___kloudlite___api___apps___container____registry___internal___d read_write } +enum Github__com___kloudlite___api___pkg___repos__MatchType { + array + exact + not_in_array + regex +} + enum Github__com___kloudlite___api___pkg___types__SyncAction { APPLY DELETE diff --git a/apps/container-registry/internal/app/graph/struct-to-graphql/matchfilter.graphqls b/apps/container-registry/internal/app/graph/struct-to-graphql/matchfilter.graphqls index c60308168..e1e59fb4d 100644 --- a/apps/container-registry/internal/app/graph/struct-to-graphql/matchfilter.graphqls +++ b/apps/container-registry/internal/app/graph/struct-to-graphql/matchfilter.graphqls @@ -1,7 +1,7 @@ type MatchFilter @shareable { array: [Any!] exact: Any - matchType: String! + matchType: Github__com___kloudlite___api___pkg___repos__MatchType! notInArray: [Any!] regex: String } @@ -9,7 +9,7 @@ type MatchFilter @shareable { input MatchFilterIn { array: [Any!] exact: Any - matchType: String! + matchType: Github__com___kloudlite___api___pkg___repos__MatchType! notInArray: [Any!] regex: String } diff --git a/apps/container-registry/internal/app/process-error-on-apply.go b/apps/container-registry/internal/app/process-error-on-apply.go index d0d2b52cc..36ba29c7e 100644 --- a/apps/container-registry/internal/app/process-error-on-apply.go +++ b/apps/container-registry/internal/app/process-error-on-apply.go @@ -3,8 +3,10 @@ package app import ( "context" "encoding/json" + "github.com/kloudlite/api/apps/container-registry/internal/domain" + msgOfficeT "github.com/kloudlite/api/apps/message-office/types" t "github.com/kloudlite/api/apps/tenant-agent/types" "github.com/kloudlite/api/pkg/errors" "github.com/kloudlite/api/pkg/logging" @@ -20,8 +22,13 @@ func ProcessErrorOnApply(consumer ErrorOnApplyConsumer, logger logging.Logger, d processMsg := func(msg *types.ConsumeMsg) error { counter += 1 + em, err := msgOfficeT.UnmarshalErrMessage(msg.Payload) + if err != nil { + return errors.NewE(err) + } + var errMsg t.AgentErrMessage - if err := json.Unmarshal(msg.Payload, &errMsg); err != nil { + if err := json.Unmarshal(em.Error, &errMsg); err != nil { return errors.NewE(err) } @@ -44,13 +51,13 @@ func ProcessErrorOnApply(consumer ErrorOnApplyConsumer, logger logging.Logger, d UserId: "sys-user:error-on-apply-worker", UserEmail: "", UserName: "", - AccountName: errMsg.AccountName, + AccountName: em.AccountName, } switch obj.GroupVersionKind().String() { case buildRunGVK.String(): { - return d.OnBuildRunApplyErrorMessage(dctx, errMsg.ClusterName, obj.GetName(), errMsg.Error) + return d.OnBuildRunApplyErrorMessage(dctx, em.ClusterName, obj.GetName(), errMsg.Error) } default: { diff --git a/apps/container-registry/internal/app/process-resource-updates.go b/apps/container-registry/internal/app/process-resource-updates.go index eae637ad9..b9a9825be 100644 --- a/apps/container-registry/internal/app/process-resource-updates.go +++ b/apps/container-registry/internal/app/process-resource-updates.go @@ -16,6 +16,7 @@ import ( "github.com/kloudlite/operator/operators/resource-watcher/types" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" + msgOfficeT "github.com/kloudlite/api/apps/message-office/types" "github.com/kloudlite/api/pkg/messaging" msgTypes "github.com/kloudlite/api/pkg/messaging/types" "sigs.k8s.io/controller-runtime/pkg/client" @@ -34,6 +35,12 @@ func processResourceUpdates(consumer ReceiveResourceUpdatesConsumer, d domain.Do readMsg := func(msg *msgTypes.ConsumeMsg) error { logger.Debugf("processing msg timestamp %s", msg.Timestamp.Format(time.RFC3339)) + ru, err := msgOfficeT.UnmarshalResourceUpdate(msg.Payload) + if err != nil { + logger.Errorf(err, "unmarshaling resource update") + return nil + } + var su types.ResourceUpdate if err := json.Unmarshal(msg.Payload, &su); err != nil { logger.Errorf(err, "parsing into status update") @@ -45,7 +52,7 @@ func processResourceUpdates(consumer ReceiveResourceUpdatesConsumer, d domain.Do return nil } - if len(strings.TrimSpace(su.AccountName)) == 0 { + if len(strings.TrimSpace(ru.AccountName)) == 0 { logger.Infof("message does not contain 'accountName', so won't be able to find a resource uniquely, thus ignoring ...") return nil } @@ -53,7 +60,7 @@ func processResourceUpdates(consumer ReceiveResourceUpdatesConsumer, d domain.Do obj := unstructured.Unstructured{Object: su.Object} mLogger := logger.WithKV( "gvk", obj.GetObjectKind().GroupVersionKind(), - "accountName/clusterName", fmt.Sprintf("%s/%s", su.AccountName, su.ClusterName), + "accountName/clusterName", fmt.Sprintf("%s/%s", ru.AccountName, ru.ClusterName), ) resStatus, err := func() (types.ResourceStatus, error) { @@ -79,7 +86,7 @@ func processResourceUpdates(consumer ReceiveResourceUpdatesConsumer, d domain.Do mLogger.Infof("processed message") }() - dctx := domain.RegistryContext{Context: context.TODO(), UserId: "sys-user-process-infra-updates", AccountName: su.AccountName} + dctx := domain.RegistryContext{Context: context.TODO(), UserId: "sys-user-process-infra-updates", AccountName: ru.AccountName} gvkStr := obj.GetObjectKind().GroupVersionKind().String() @@ -91,8 +98,8 @@ func processResourceUpdates(consumer ReceiveResourceUpdatesConsumer, d domain.Do return err } - buildRun.AccountName = su.AccountName - buildRun.ClusterName = su.ClusterName + buildRun.AccountName = ru.AccountName + buildRun.ClusterName = ru.ClusterName if obj.GetDeletionTimestamp() != nil { return d.OnBuildRunDeleteMessage(dctx, buildRun) diff --git a/apps/infra/internal/app/gqlgen.yml b/apps/infra/internal/app/gqlgen.yml index 7216f812b..e6ae20687 100644 --- a/apps/infra/internal/app/gqlgen.yml +++ b/apps/infra/internal/app/gqlgen.yml @@ -145,6 +145,7 @@ models: model: github.com/kloudlite/api/pkg/repos.MatchFilter MatchFilterIn: *match-filter-model + MatchFilterMatchType: model: github.com/kloudlite/api/pkg/repos.MatchType diff --git a/apps/infra/internal/app/graph/generated/generated.go b/apps/infra/internal/app/graph/generated/generated.go index 370c5b0bf..8f327d6ba 100644 --- a/apps/infra/internal/app/graph/generated/generated.go +++ b/apps/infra/internal/app/graph/generated/generated.go @@ -59,6 +59,7 @@ type ResolverRoot interface { GlobalVPN() GlobalVPNResolver GlobalVPNDevice() GlobalVPNDeviceResolver HelmRelease() HelmReleaseResolver + MatchFilter() MatchFilterResolver Metadata() MetadataResolver Mutation() MutationResolver Namespace() NamespaceResolver @@ -75,6 +76,7 @@ type ResolverRoot interface { GlobalVPNDeviceIn() GlobalVPNDeviceInResolver GlobalVPNIn() GlobalVPNInResolver HelmReleaseIn() HelmReleaseInResolver + MatchFilterIn() MatchFilterInResolver MetadataIn() MetadataInResolver NamespaceIn() NamespaceInResolver NodePoolIn() NodePoolInResolver @@ -615,6 +617,7 @@ type ComplexityRoot struct { CreationTime func(childComplexity int) int DisplayName func(childComplexity int) int ID func(childComplexity int) int + KloudliteDevice func(childComplexity int) int LastUpdatedBy func(childComplexity int) int MarkedForDeletion func(childComplexity int) int NumAllocatedClusterCIDRs func(childComplexity int) int @@ -662,6 +665,11 @@ type ComplexityRoot struct { Node func(childComplexity int) int } + GlobalVPNKloudliteDevice struct { + IPAddr func(childComplexity int) int + Name func(childComplexity int) int + } + GlobalVPNPaginatedRecords struct { Edges func(childComplexity int) int PageInfo func(childComplexity int) int @@ -1109,10 +1117,11 @@ type ComplexityRoot struct { } MatchFilter struct { - Array func(childComplexity int) int - Exact func(childComplexity int) int - MatchType func(childComplexity int) int - Regex func(childComplexity int) int + Array func(childComplexity int) int + Exact func(childComplexity int) int + MatchType func(childComplexity int) int + NotInArray func(childComplexity int) int + Regex func(childComplexity int) int } Metadata struct { @@ -1462,6 +1471,7 @@ type GlobalVPNResolver interface { CreationTime(ctx context.Context, obj *entities.GlobalVPN) (string, error) ID(ctx context.Context, obj *entities.GlobalVPN) (repos.ID, error) + KloudliteDevice(ctx context.Context, obj *entities.GlobalVPN) (*model.GlobalVPNKloudliteDevice, error) UpdateTime(ctx context.Context, obj *entities.GlobalVPN) (string, error) } @@ -1483,6 +1493,9 @@ type HelmReleaseResolver interface { UpdateTime(ctx context.Context, obj *entities.HelmRelease) (string, error) } +type MatchFilterResolver interface { + MatchType(ctx context.Context, obj *repos.MatchFilter) (model.GithubComKloudliteAPIPkgReposMatchType, error) +} type MetadataResolver interface { Annotations(ctx context.Context, obj *v1.ObjectMeta) (map[string]interface{}, error) CreationTimestamp(ctx context.Context, obj *v1.ObjectMeta) (string, error) @@ -1574,7 +1587,7 @@ type QueryResolver interface { InfraGetCluster(ctx context.Context, name string) (*entities.Cluster, error) InfraListBYOKClusters(ctx context.Context, search *model.SearchCluster, pagination *repos.CursorPagination) (*model.BYOKClusterPaginatedRecords, error) InfraGetBYOKCluster(ctx context.Context, name string) (*entities.BYOKCluster, error) - InfratGetBYOKClusterSetupInstructions(ctx context.Context, name string) (*string, error) + InfratGetBYOKClusterSetupInstructions(ctx context.Context, name string) ([]string, error) InfraListGlobalVPNs(ctx context.Context, search *model.SearchGlobalVPNs, pagination *repos.CursorPagination) (*model.GlobalVPNPaginatedRecords, error) InfraGetGlobalVpn(ctx context.Context, name string) (*entities.GlobalVPN, error) InfraListGlobalVPNDevices(ctx context.Context, gvpn string, search *model.SearchGlobalVPNDevices, pagination *repos.CursorPagination) (*model.GlobalVPNDevicePaginatedRecords, error) @@ -1634,12 +1647,16 @@ type GlobalVPNDeviceInResolver interface { Metadata(ctx context.Context, obj *entities.GlobalVPNDevice, data *v1.ObjectMeta) error } type GlobalVPNInResolver interface { + KloudliteDevice(ctx context.Context, obj *entities.GlobalVPN, data *model.GlobalVPNKloudliteDeviceIn) error Metadata(ctx context.Context, obj *entities.GlobalVPN, data *v1.ObjectMeta) error } type HelmReleaseInResolver interface { Metadata(ctx context.Context, obj *entities.HelmRelease, data *v1.ObjectMeta) error Spec(ctx context.Context, obj *entities.HelmRelease, data *model.GithubComKloudliteOperatorApisCrdsV1HelmChartSpecIn) error } +type MatchFilterInResolver interface { + MatchType(ctx context.Context, obj *repos.MatchFilter, data model.GithubComKloudliteAPIPkgReposMatchType) error +} type MetadataInResolver interface { Annotations(ctx context.Context, obj *v1.ObjectMeta, data map[string]interface{}) error Labels(ctx context.Context, obj *v1.ObjectMeta, data map[string]interface{}) error @@ -4014,6 +4031,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.GlobalVPN.ID(childComplexity), true + case "GlobalVPN.kloudliteDevice": + if e.complexity.GlobalVPN.KloudliteDevice == nil { + break + } + + return e.complexity.GlobalVPN.KloudliteDevice(childComplexity), true + case "GlobalVPN.lastUpdatedBy": if e.complexity.GlobalVPN.LastUpdatedBy == nil { break @@ -4245,6 +4269,20 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.GlobalVPNEdge.Node(childComplexity), true + case "GlobalVPNKloudliteDevice.ipAddr": + if e.complexity.GlobalVPNKloudliteDevice.IPAddr == nil { + break + } + + return e.complexity.GlobalVPNKloudliteDevice.IPAddr(childComplexity), true + + case "GlobalVPNKloudliteDevice.name": + if e.complexity.GlobalVPNKloudliteDevice.Name == nil { + break + } + + return e.complexity.GlobalVPNKloudliteDevice.Name(childComplexity), true + case "GlobalVPNPaginatedRecords.edges": if e.complexity.GlobalVPNPaginatedRecords.Edges == nil { break @@ -6128,6 +6166,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.MatchFilter.MatchType(childComplexity), true + case "MatchFilter.notInArray": + if e.complexity.MatchFilter.NotInArray == nil { + break + } + + return e.complexity.MatchFilter.NotInArray(childComplexity), true + case "MatchFilter.regex": if e.complexity.MatchFilter.Regex == nil { break @@ -7864,6 +7909,7 @@ func (e *executableSchema) Exec(ctx context.Context) graphql.ResponseHandler { ec.unmarshalInputGithub__com___kloudlite___operator___apis___crds___v1__ServiceTemplateIn, ec.unmarshalInputGlobalVPNDeviceIn, ec.unmarshalInputGlobalVPNIn, + ec.unmarshalInputGlobalVPNKloudliteDeviceIn, ec.unmarshalInputHelmReleaseIn, ec.unmarshalInputK8s__io___api___core___v1__AWSElasticBlockStoreVolumeSourceIn, ec.unmarshalInputK8s__io___api___core___v1__AffinityIn, @@ -8130,7 +8176,7 @@ type Query { # byok infra_listBYOKClusters(search: SearchCluster, pagination: CursorPaginationIn): BYOKClusterPaginatedRecords @isLoggedInAndVerified @hasAccount infra_getBYOKCluster(name: String!): BYOKCluster @isLoggedInAndVerified @hasAccount - infrat_getBYOKClusterSetupInstructions(name: String!): String @isLoggedInAndVerified @hasAccount + infrat_getBYOKClusterSetupInstructions(name: String!): [String!] @isLoggedInAndVerified @hasAccount # global VPN infra_listGlobalVPNs(search: SearchGlobalVPNs, pagination: CursorPaginationIn): GlobalVPNPaginatedRecords @isLoggedInAndVerified @hasAccount @@ -9729,6 +9775,13 @@ input MetadataIn { namespace: String } +enum Github__com___kloudlite___api___pkg___repos__MatchType { + array + exact + not_in_array + regex +} + enum Github__com___kloudlite___api___pkg___types__SyncAction { APPLY DELETE @@ -9927,6 +9980,7 @@ input DomainEntryIn { creationTime: Date! displayName: String! id: ID! + kloudliteDevice: GlobalVPNKloudliteDevice! lastUpdatedBy: Github__com___kloudlite___api___common__CreatedOrUpdatedBy! markedForDeletion: Boolean metadata: Metadata! @goField(name: "objectMeta") @@ -9943,6 +9997,11 @@ type GlobalVPNEdge @shareable { node: GlobalVPN! } +type GlobalVPNKloudliteDevice @shareable { + ipAddr: String! + name: String! +} + type GlobalVPNPaginatedRecords @shareable { edges: [GlobalVPNEdge!]! pageInfo: PageInfo! @@ -9953,6 +10012,7 @@ input GlobalVPNIn { allocatableCIDRSuffix: Int! CIDR: String! displayName: String! + kloudliteDevice: GlobalVPNKloudliteDeviceIn! metadata: MetadataIn! numAllocatedClusterCIDRs: Int! numAllocatedDevices: Int! @@ -9960,6 +10020,11 @@ input GlobalVPNIn { wgInterface: String! } +input GlobalVPNKloudliteDeviceIn { + ipAddr: String! + name: String! +} + `, BuiltIn: false}, {Name: "../struct-to-graphql/globalvpndevice.graphqls", Input: `type GlobalVPNDevice @shareable { accountName: String! @@ -10041,23 +10106,19 @@ input HelmReleaseIn { {Name: "../struct-to-graphql/matchfilter.graphqls", Input: `type MatchFilter @shareable { array: [Any!] exact: Any - matchType: MatchFilterMatchType! + matchType: Github__com___kloudlite___api___pkg___repos__MatchType! + notInArray: [Any!] regex: String } input MatchFilterIn { array: [Any!] exact: Any - matchType: MatchFilterMatchType! + matchType: Github__com___kloudlite___api___pkg___repos__MatchType! + notInArray: [Any!] regex: String } -enum MatchFilterMatchType { - array - exact - regex -} - `, BuiltIn: false}, {Name: "../struct-to-graphql/msvctemplate.graphqls", Input: `type MsvcTemplate @shareable { category: String! @@ -26907,6 +26968,56 @@ func (ec *executionContext) fieldContext_GlobalVPN_id(ctx context.Context, field return fc, nil } +func (ec *executionContext) _GlobalVPN_kloudliteDevice(ctx context.Context, field graphql.CollectedField, obj *entities.GlobalVPN) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_GlobalVPN_kloudliteDevice(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.GlobalVPN().KloudliteDevice(rctx, obj) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.GlobalVPNKloudliteDevice) + fc.Result = res + return ec.marshalNGlobalVPNKloudliteDevice2ᚖgithubᚗcomᚋkloudliteᚋapiᚋappsᚋinfraᚋinternalᚋappᚋgraphᚋmodelᚐGlobalVPNKloudliteDevice(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_GlobalVPN_kloudliteDevice(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "GlobalVPN", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + switch field.Name { + case "ipAddr": + return ec.fieldContext_GlobalVPNKloudliteDevice_ipAddr(ctx, field) + case "name": + return ec.fieldContext_GlobalVPNKloudliteDevice_name(ctx, field) + } + return nil, fmt.Errorf("no field named %q was found under type GlobalVPNKloudliteDevice", field.Name) + }, + } + return fc, nil +} + func (ec *executionContext) _GlobalVPN_lastUpdatedBy(ctx context.Context, field graphql.CollectedField, obj *entities.GlobalVPN) (ret graphql.Marshaler) { fc, err := ec.fieldContext_GlobalVPN_lastUpdatedBy(ctx, field) if err != nil { @@ -28467,6 +28578,8 @@ func (ec *executionContext) fieldContext_GlobalVPNEdge_node(ctx context.Context, return ec.fieldContext_GlobalVPN_displayName(ctx, field) case "id": return ec.fieldContext_GlobalVPN_id(ctx, field) + case "kloudliteDevice": + return ec.fieldContext_GlobalVPN_kloudliteDevice(ctx, field) case "lastUpdatedBy": return ec.fieldContext_GlobalVPN_lastUpdatedBy(ctx, field) case "markedForDeletion": @@ -28492,6 +28605,94 @@ func (ec *executionContext) fieldContext_GlobalVPNEdge_node(ctx context.Context, return fc, nil } +func (ec *executionContext) _GlobalVPNKloudliteDevice_ipAddr(ctx context.Context, field graphql.CollectedField, obj *model.GlobalVPNKloudliteDevice) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_GlobalVPNKloudliteDevice_ipAddr(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IPAddr, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_GlobalVPNKloudliteDevice_ipAddr(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "GlobalVPNKloudliteDevice", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _GlobalVPNKloudliteDevice_name(ctx context.Context, field graphql.CollectedField, obj *model.GlobalVPNKloudliteDevice) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_GlobalVPNKloudliteDevice_name(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Name, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_GlobalVPNKloudliteDevice_name(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "GlobalVPNKloudliteDevice", + Field: field, + IsMethod: false, + IsResolver: false, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type String does not have child fields") + }, + } + return fc, nil +} + func (ec *executionContext) _GlobalVPNPaginatedRecords_edges(ctx context.Context, field graphql.CollectedField, obj *model.GlobalVPNPaginatedRecords) (ret graphql.Marshaler) { fc, err := ec.fieldContext_GlobalVPNPaginatedRecords_edges(ctx, field) if err != nil { @@ -40497,7 +40698,7 @@ func (ec *executionContext) _MatchFilter_matchType(ctx context.Context, field gr }() resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { ctx = rctx // use context from middleware stack in children - return obj.MatchType, nil + return ec.resolvers.MatchFilter().MatchType(rctx, obj) }) if err != nil { ec.Error(ctx, err) @@ -40509,19 +40710,60 @@ func (ec *executionContext) _MatchFilter_matchType(ctx context.Context, field gr } return graphql.Null } - res := resTmp.(repos.MatchType) + res := resTmp.(model.GithubComKloudliteAPIPkgReposMatchType) fc.Result = res - return ec.marshalNMatchFilterMatchType2githubᚗcomᚋkloudliteᚋapiᚋpkgᚋreposᚐMatchType(ctx, field.Selections, res) + return ec.marshalNGithub__com___kloudlite___api___pkg___repos__MatchType2githubᚗcomᚋkloudliteᚋapiᚋappsᚋinfraᚋinternalᚋappᚋgraphᚋmodelᚐGithubComKloudliteAPIPkgReposMatchType(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_MatchFilter_matchType(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { + fc = &graphql.FieldContext{ + Object: "MatchFilter", + Field: field, + IsMethod: true, + IsResolver: true, + Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { + return nil, errors.New("field of type Github__com___kloudlite___api___pkg___repos__MatchType does not have child fields") + }, + } + return fc, nil +} + +func (ec *executionContext) _MatchFilter_notInArray(ctx context.Context, field graphql.CollectedField, obj *repos.MatchFilter) (ret graphql.Marshaler) { + fc, err := ec.fieldContext_MatchFilter_notInArray(ctx, field) + if err != nil { + return graphql.Null + } + ctx = graphql.WithFieldContext(ctx, fc) + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.NotInArray, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + return graphql.Null + } + res := resTmp.([]any) + fc.Result = res + return ec.marshalOAny2ᚕinterfaceᚄ(ctx, field.Selections, res) +} + +func (ec *executionContext) fieldContext_MatchFilter_notInArray(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { fc = &graphql.FieldContext{ Object: "MatchFilter", Field: field, IsMethod: false, IsResolver: false, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type MatchFilterMatchType does not have child fields") + return nil, errors.New("field of type Any does not have child fields") }, } return fc, nil @@ -41407,6 +41649,8 @@ func (ec *executionContext) fieldContext_Mutation_infra_createGlobalVPN(ctx cont return ec.fieldContext_GlobalVPN_displayName(ctx, field) case "id": return ec.fieldContext_GlobalVPN_id(ctx, field) + case "kloudliteDevice": + return ec.fieldContext_GlobalVPN_kloudliteDevice(ctx, field) case "lastUpdatedBy": return ec.fieldContext_GlobalVPN_lastUpdatedBy(ctx, field) case "markedForDeletion": @@ -41519,6 +41763,8 @@ func (ec *executionContext) fieldContext_Mutation_infra_updateGlobalVPN(ctx cont return ec.fieldContext_GlobalVPN_displayName(ctx, field) case "id": return ec.fieldContext_GlobalVPN_id(ctx, field) + case "kloudliteDevice": + return ec.fieldContext_GlobalVPN_kloudliteDevice(ctx, field) case "lastUpdatedBy": return ec.fieldContext_GlobalVPN_lastUpdatedBy(ctx, field) case "markedForDeletion": @@ -49627,10 +49873,10 @@ func (ec *executionContext) _Query_infrat_getBYOKClusterSetupInstructions(ctx co if tmp == nil { return nil, nil } - if data, ok := tmp.(*string); ok { + if data, ok := tmp.([]string); ok { return data, nil } - return nil, fmt.Errorf(`unexpected type %T from directive, should be *string`, tmp) + return nil, fmt.Errorf(`unexpected type %T from directive, should be []string`, tmp) }) if err != nil { ec.Error(ctx, err) @@ -49639,9 +49885,9 @@ func (ec *executionContext) _Query_infrat_getBYOKClusterSetupInstructions(ctx co if resTmp == nil { return graphql.Null } - res := resTmp.(*string) + res := resTmp.([]string) fc.Result = res - return ec.marshalOString2ᚖstring(ctx, field.Selections, res) + return ec.marshalOString2ᚕstringᚄ(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_Query_infrat_getBYOKClusterSetupInstructions(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -49830,6 +50076,8 @@ func (ec *executionContext) fieldContext_Query_infra_getGlobalVPN(ctx context.Co return ec.fieldContext_GlobalVPN_displayName(ctx, field) case "id": return ec.fieldContext_GlobalVPN_id(ctx, field) + case "kloudliteDevice": + return ec.fieldContext_GlobalVPN_kloudliteDevice(ctx, field) case "lastUpdatedBy": return ec.fieldContext_GlobalVPN_lastUpdatedBy(ctx, field) case "markedForDeletion": @@ -56648,7 +56896,7 @@ func (ec *executionContext) unmarshalInputGlobalVPNIn(ctx context.Context, obj i asMap[k] = v } - fieldsInOrder := [...]string{"allocatableCIDRSuffix", "CIDR", "displayName", "metadata", "numAllocatedClusterCIDRs", "numAllocatedDevices", "numReservedIPsForNonClusterUse", "wgInterface"} + fieldsInOrder := [...]string{"allocatableCIDRSuffix", "CIDR", "displayName", "kloudliteDevice", "metadata", "numAllocatedClusterCIDRs", "numAllocatedDevices", "numReservedIPsForNonClusterUse", "wgInterface"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -56682,6 +56930,17 @@ func (ec *executionContext) unmarshalInputGlobalVPNIn(ctx context.Context, obj i return it, err } it.DisplayName = data + case "kloudliteDevice": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("kloudliteDevice")) + data, err := ec.unmarshalNGlobalVPNKloudliteDeviceIn2ᚖgithubᚗcomᚋkloudliteᚋapiᚋappsᚋinfraᚋinternalᚋappᚋgraphᚋmodelᚐGlobalVPNKloudliteDeviceIn(ctx, v) + if err != nil { + return it, err + } + if err = ec.resolvers.GlobalVPNIn().KloudliteDevice(ctx, &it, data); err != nil { + return it, err + } case "metadata": var err error @@ -56735,6 +56994,44 @@ func (ec *executionContext) unmarshalInputGlobalVPNIn(ctx context.Context, obj i return it, nil } +func (ec *executionContext) unmarshalInputGlobalVPNKloudliteDeviceIn(ctx context.Context, obj interface{}) (model.GlobalVPNKloudliteDeviceIn, error) { + var it model.GlobalVPNKloudliteDeviceIn + asMap := map[string]interface{}{} + for k, v := range obj.(map[string]interface{}) { + asMap[k] = v + } + + fieldsInOrder := [...]string{"ipAddr", "name"} + for _, k := range fieldsInOrder { + v, ok := asMap[k] + if !ok { + continue + } + switch k { + case "ipAddr": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("ipAddr")) + data, err := ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + it.IPAddr = data + case "name": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("name")) + data, err := ec.unmarshalNString2string(ctx, v) + if err != nil { + return it, err + } + it.Name = data + } + } + + return it, nil +} + func (ec *executionContext) unmarshalInputHelmReleaseIn(ctx context.Context, obj interface{}) (entities.HelmRelease, error) { var it entities.HelmRelease asMap := map[string]interface{}{} @@ -60109,7 +60406,7 @@ func (ec *executionContext) unmarshalInputMatchFilterIn(ctx context.Context, obj asMap[k] = v } - fieldsInOrder := [...]string{"array", "exact", "matchType", "regex"} + fieldsInOrder := [...]string{"array", "exact", "matchType", "notInArray", "regex"} for _, k := range fieldsInOrder { v, ok := asMap[k] if !ok { @@ -60138,11 +60435,22 @@ func (ec *executionContext) unmarshalInputMatchFilterIn(ctx context.Context, obj var err error ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("matchType")) - data, err := ec.unmarshalNMatchFilterMatchType2githubᚗcomᚋkloudliteᚋapiᚋpkgᚋreposᚐMatchType(ctx, v) + data, err := ec.unmarshalNGithub__com___kloudlite___api___pkg___repos__MatchType2githubᚗcomᚋkloudliteᚋapiᚋappsᚋinfraᚋinternalᚋappᚋgraphᚋmodelᚐGithubComKloudliteAPIPkgReposMatchType(ctx, v) + if err != nil { + return it, err + } + if err = ec.resolvers.MatchFilterIn().MatchType(ctx, &it, data); err != nil { + return it, err + } + case "notInArray": + var err error + + ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("notInArray")) + data, err := ec.unmarshalOAny2ᚕinterfaceᚄ(ctx, v) if err != nil { return it, err } - it.MatchType = data + it.NotInArray = data case "regex": var err error @@ -65631,6 +65939,42 @@ func (ec *executionContext) _GlobalVPN(ctx context.Context, sel ast.SelectionSet continue } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + case "kloudliteDevice": + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._GlobalVPN_kloudliteDevice(ctx, field, obj) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res + } + + if field.Deferrable != nil { + dfs, ok := deferred[field.Deferrable.Label] + di := 0 + if ok { + dfs.AddField(field) + di = len(dfs.Values) - 1 + } else { + dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) + deferred[field.Deferrable.Label] = dfs + } + dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { + return innerFunc(ctx, dfs) + }) + + // don't run the out.Concurrently() call below + out.Values[i] = graphql.Null + continue + } + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) case "lastUpdatedBy": out.Values[i] = ec._GlobalVPN_lastUpdatedBy(ctx, field, obj) @@ -66096,6 +66440,50 @@ func (ec *executionContext) _GlobalVPNEdge(ctx context.Context, sel ast.Selectio return out } +var globalVPNKloudliteDeviceImplementors = []string{"GlobalVPNKloudliteDevice"} + +func (ec *executionContext) _GlobalVPNKloudliteDevice(ctx context.Context, sel ast.SelectionSet, obj *model.GlobalVPNKloudliteDevice) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, globalVPNKloudliteDeviceImplementors) + + out := graphql.NewFieldSet(fields) + deferred := make(map[string]*graphql.FieldSet) + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("GlobalVPNKloudliteDevice") + case "ipAddr": + out.Values[i] = ec._GlobalVPNKloudliteDevice_ipAddr(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + case "name": + out.Values[i] = ec._GlobalVPNKloudliteDevice_name(ctx, field, obj) + if out.Values[i] == graphql.Null { + out.Invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch(ctx) + if out.Invalids > 0 { + return graphql.Null + } + + atomic.AddInt32(&ec.deferred, int32(len(deferred))) + + for label, dfs := range deferred { + ec.processDeferredGroup(graphql.DeferredGroup{ + Label: label, + Path: graphql.GetPath(ctx), + FieldSet: dfs, + Context: ctx, + }) + } + + return out +} + var globalVPNPaginatedRecordsImplementors = []string{"GlobalVPNPaginatedRecords"} func (ec *executionContext) _GlobalVPNPaginatedRecords(ctx context.Context, sel ast.SelectionSet, obj *model.GlobalVPNPaginatedRecords) graphql.Marshaler { @@ -69058,10 +69446,43 @@ func (ec *executionContext) _MatchFilter(ctx context.Context, sel ast.SelectionS case "exact": out.Values[i] = ec._MatchFilter_exact(ctx, field, obj) case "matchType": - out.Values[i] = ec._MatchFilter_matchType(ctx, field, obj) - if out.Values[i] == graphql.Null { - out.Invalids++ + field := field + + innerFunc := func(ctx context.Context, fs *graphql.FieldSet) (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._MatchFilter_matchType(ctx, field, obj) + if res == graphql.Null { + atomic.AddUint32(&fs.Invalids, 1) + } + return res } + + if field.Deferrable != nil { + dfs, ok := deferred[field.Deferrable.Label] + di := 0 + if ok { + dfs.AddField(field) + di = len(dfs.Values) - 1 + } else { + dfs = graphql.NewFieldSet([]graphql.CollectedField{field}) + deferred[field.Deferrable.Label] = dfs + } + dfs.Concurrently(di, func(ctx context.Context) graphql.Marshaler { + return innerFunc(ctx, dfs) + }) + + // don't run the out.Concurrently() call below + out.Values[i] = graphql.Null + continue + } + + out.Concurrently(i, func(ctx context.Context) graphql.Marshaler { return innerFunc(ctx, out) }) + case "notInArray": + out.Values[i] = ec._MatchFilter_notInArray(ctx, field, obj) case "regex": out.Values[i] = ec._MatchFilter_regex(ctx, field, obj) default: @@ -73228,6 +73649,16 @@ func (ec *executionContext) marshalNGithub__com___kloudlite___api___common__Crea return ec._Github__com___kloudlite___api___common__CreatedOrUpdatedBy(ctx, sel, &v) } +func (ec *executionContext) unmarshalNGithub__com___kloudlite___api___pkg___repos__MatchType2githubᚗcomᚋkloudliteᚋapiᚋappsᚋinfraᚋinternalᚋappᚋgraphᚋmodelᚐGithubComKloudliteAPIPkgReposMatchType(ctx context.Context, v interface{}) (model.GithubComKloudliteAPIPkgReposMatchType, error) { + var res model.GithubComKloudliteAPIPkgReposMatchType + err := res.UnmarshalGQL(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNGithub__com___kloudlite___api___pkg___repos__MatchType2githubᚗcomᚋkloudliteᚋapiᚋappsᚋinfraᚋinternalᚋappᚋgraphᚋmodelᚐGithubComKloudliteAPIPkgReposMatchType(ctx context.Context, sel ast.SelectionSet, v model.GithubComKloudliteAPIPkgReposMatchType) graphql.Marshaler { + return v +} + func (ec *executionContext) unmarshalNGithub__com___kloudlite___api___pkg___types__SyncAction2githubᚗcomᚋkloudliteᚋapiᚋpkgᚋtypesᚐSyncAction(ctx context.Context, v interface{}) (types.SyncAction, error) { tmp, err := graphql.UnmarshalString(v) res := types.SyncAction(tmp) @@ -73682,6 +74113,30 @@ func (ec *executionContext) unmarshalNGlobalVPNIn2githubᚗcomᚋkloudliteᚋapi return res, graphql.ErrorOnPath(ctx, err) } +func (ec *executionContext) marshalNGlobalVPNKloudliteDevice2githubᚗcomᚋkloudliteᚋapiᚋappsᚋinfraᚋinternalᚋappᚋgraphᚋmodelᚐGlobalVPNKloudliteDevice(ctx context.Context, sel ast.SelectionSet, v model.GlobalVPNKloudliteDevice) graphql.Marshaler { + return ec._GlobalVPNKloudliteDevice(ctx, sel, &v) +} + +func (ec *executionContext) marshalNGlobalVPNKloudliteDevice2ᚖgithubᚗcomᚋkloudliteᚋapiᚋappsᚋinfraᚋinternalᚋappᚋgraphᚋmodelᚐGlobalVPNKloudliteDevice(ctx context.Context, sel ast.SelectionSet, v *model.GlobalVPNKloudliteDevice) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "the requested element is null which the schema does not allow") + } + return graphql.Null + } + return ec._GlobalVPNKloudliteDevice(ctx, sel, v) +} + +func (ec *executionContext) unmarshalNGlobalVPNKloudliteDeviceIn2githubᚗcomᚋkloudliteᚋapiᚋappsᚋinfraᚋinternalᚋappᚋgraphᚋmodelᚐGlobalVPNKloudliteDeviceIn(ctx context.Context, v interface{}) (model.GlobalVPNKloudliteDeviceIn, error) { + res, err := ec.unmarshalInputGlobalVPNKloudliteDeviceIn(ctx, v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) unmarshalNGlobalVPNKloudliteDeviceIn2ᚖgithubᚗcomᚋkloudliteᚋapiᚋappsᚋinfraᚋinternalᚋappᚋgraphᚋmodelᚐGlobalVPNKloudliteDeviceIn(ctx context.Context, v interface{}) (*model.GlobalVPNKloudliteDeviceIn, error) { + res, err := ec.unmarshalInputGlobalVPNKloudliteDeviceIn(ctx, v) + return &res, graphql.ErrorOnPath(ctx, err) +} + func (ec *executionContext) marshalNHelmRelease2ᚖgithubᚗcomᚋkloudliteᚋapiᚋappsᚋinfraᚋinternalᚋentitiesᚐHelmRelease(ctx context.Context, sel ast.SelectionSet, v *entities.HelmRelease) graphql.Marshaler { if v == nil { if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { @@ -74153,22 +74608,6 @@ func (ec *executionContext) marshalNMap2map(ctx context.Context, sel ast.Selecti return res } -func (ec *executionContext) unmarshalNMatchFilterMatchType2githubᚗcomᚋkloudliteᚋapiᚋpkgᚋreposᚐMatchType(ctx context.Context, v interface{}) (repos.MatchType, error) { - tmp, err := graphql.UnmarshalString(v) - res := repos.MatchType(tmp) - return res, graphql.ErrorOnPath(ctx, err) -} - -func (ec *executionContext) marshalNMatchFilterMatchType2githubᚗcomᚋkloudliteᚋapiᚋpkgᚋreposᚐMatchType(ctx context.Context, sel ast.SelectionSet, v repos.MatchType) graphql.Marshaler { - res := graphql.MarshalString(string(v)) - if res == graphql.Null { - if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { - ec.Errorf(ctx, "the requested element is null which the schema does not allow") - } - } - return res -} - func (ec *executionContext) marshalNMetadata2k8sᚗioᚋapimachineryᚋpkgᚋapisᚋmetaᚋv1ᚐObjectMeta(ctx context.Context, sel ast.SelectionSet, v v1.ObjectMeta) graphql.Marshaler { return ec._Metadata(ctx, sel, &v) } @@ -74991,7 +75430,7 @@ func (ec *executionContext) marshalNfederation__Scope2ᚕᚕstringᚄ(ctx contex return ret } -func (ec *executionContext) unmarshalOAny2interface(ctx context.Context, v interface{}) (any, error) { +func (ec *executionContext) unmarshalOAny2interface(ctx context.Context, v interface{}) (interface{}, error) { if v == nil { return nil, nil } @@ -74999,7 +75438,7 @@ func (ec *executionContext) unmarshalOAny2interface(ctx context.Context, v inter return res, graphql.ErrorOnPath(ctx, err) } -func (ec *executionContext) marshalOAny2interface(ctx context.Context, sel ast.SelectionSet, v any) graphql.Marshaler { +func (ec *executionContext) marshalOAny2interface(ctx context.Context, sel ast.SelectionSet, v interface{}) graphql.Marshaler { if v == nil { return graphql.Null } diff --git a/apps/infra/internal/app/graph/globalvpn.resolvers.go b/apps/infra/internal/app/graph/globalvpn.resolvers.go index 7f9bacbc8..d0ee90235 100644 --- a/apps/infra/internal/app/graph/globalvpn.resolvers.go +++ b/apps/infra/internal/app/graph/globalvpn.resolvers.go @@ -6,10 +6,12 @@ package graph import ( "context" + "fmt" "github.com/kloudlite/api/pkg/errors" "time" "github.com/kloudlite/api/apps/infra/internal/app/graph/generated" + "github.com/kloudlite/api/apps/infra/internal/app/graph/model" "github.com/kloudlite/api/apps/infra/internal/entities" fn "github.com/kloudlite/api/pkg/functions" "github.com/kloudlite/api/pkg/repos" @@ -32,6 +34,11 @@ func (r *globalVPNResolver) ID(ctx context.Context, obj *entities.GlobalVPN) (re return obj.Id, nil } +// KloudliteDevice is the resolver for the kloudliteDevice field. +func (r *globalVPNResolver) KloudliteDevice(ctx context.Context, obj *entities.GlobalVPN) (*model.GlobalVPNKloudliteDevice, error) { + panic(fmt.Errorf("not implemented: KloudliteDevice - kloudliteDevice")) +} + // UpdateTime is the resolver for the updateTime field. func (r *globalVPNResolver) UpdateTime(ctx context.Context, obj *entities.GlobalVPN) (string, error) { if obj == nil { @@ -40,6 +47,11 @@ func (r *globalVPNResolver) UpdateTime(ctx context.Context, obj *entities.Global return obj.UpdateTime.Format(time.RFC3339), nil } +// KloudliteDevice is the resolver for the kloudliteDevice field. +func (r *globalVPNInResolver) KloudliteDevice(ctx context.Context, obj *entities.GlobalVPN, data *model.GlobalVPNKloudliteDeviceIn) error { + panic(fmt.Errorf("not implemented: KloudliteDevice - kloudliteDevice")) +} + // Metadata is the resolver for the metadata field. func (r *globalVPNInResolver) Metadata(ctx context.Context, obj *entities.GlobalVPN, data *v1.ObjectMeta) error { if obj == nil { diff --git a/apps/infra/internal/app/graph/matchfilter.resolvers.go b/apps/infra/internal/app/graph/matchfilter.resolvers.go new file mode 100644 index 000000000..c8e5494a3 --- /dev/null +++ b/apps/infra/internal/app/graph/matchfilter.resolvers.go @@ -0,0 +1,33 @@ +package graph + +// This file will be automatically regenerated based on the schema, any resolver implementations +// will be copied through when generating and any unknown code will be moved to the end. +// Code generated by github.com/99designs/gqlgen version v0.17.39 + +import ( + "context" + "fmt" + + "github.com/kloudlite/api/apps/infra/internal/app/graph/generated" + "github.com/kloudlite/api/apps/infra/internal/app/graph/model" + "github.com/kloudlite/api/pkg/repos" +) + +// MatchType is the resolver for the matchType field. +func (r *matchFilterResolver) MatchType(ctx context.Context, obj *repos.MatchFilter) (model.GithubComKloudliteAPIPkgReposMatchType, error) { + panic(fmt.Errorf("not implemented: MatchType - matchType")) +} + +// MatchType is the resolver for the matchType field. +func (r *matchFilterInResolver) MatchType(ctx context.Context, obj *repos.MatchFilter, data model.GithubComKloudliteAPIPkgReposMatchType) error { + panic(fmt.Errorf("not implemented: MatchType - matchType")) +} + +// MatchFilter returns generated.MatchFilterResolver implementation. +func (r *Resolver) MatchFilter() generated.MatchFilterResolver { return &matchFilterResolver{r} } + +// MatchFilterIn returns generated.MatchFilterInResolver implementation. +func (r *Resolver) MatchFilterIn() generated.MatchFilterInResolver { return &matchFilterInResolver{r} } + +type matchFilterResolver struct{ *Resolver } +type matchFilterInResolver struct{ *Resolver } diff --git a/apps/infra/internal/app/graph/model/models_gen.go b/apps/infra/internal/app/graph/model/models_gen.go index 213db8b89..c60df49a1 100644 --- a/apps/infra/internal/app/graph/model/models_gen.go +++ b/apps/infra/internal/app/graph/model/models_gen.go @@ -532,6 +532,16 @@ type GlobalVPNEdge struct { Node *entities.GlobalVPN `json:"node"` } +type GlobalVPNKloudliteDevice struct { + IPAddr string `json:"ipAddr"` + Name string `json:"name"` +} + +type GlobalVPNKloudliteDeviceIn struct { + IPAddr string `json:"ipAddr"` + Name string `json:"name"` +} + type GlobalVPNPaginatedRecords struct { Edges []*GlobalVPNEdge `json:"edges"` PageInfo *PageInfo `json:"pageInfo"` @@ -1505,6 +1515,51 @@ type VolumeAttachmentPaginatedRecords struct { TotalCount int `json:"totalCount"` } +type GithubComKloudliteAPIPkgReposMatchType string + +const ( + GithubComKloudliteAPIPkgReposMatchTypeArray GithubComKloudliteAPIPkgReposMatchType = "array" + GithubComKloudliteAPIPkgReposMatchTypeExact GithubComKloudliteAPIPkgReposMatchType = "exact" + GithubComKloudliteAPIPkgReposMatchTypeNotInArray GithubComKloudliteAPIPkgReposMatchType = "not_in_array" + GithubComKloudliteAPIPkgReposMatchTypeRegex GithubComKloudliteAPIPkgReposMatchType = "regex" +) + +var AllGithubComKloudliteAPIPkgReposMatchType = []GithubComKloudliteAPIPkgReposMatchType{ + GithubComKloudliteAPIPkgReposMatchTypeArray, + GithubComKloudliteAPIPkgReposMatchTypeExact, + GithubComKloudliteAPIPkgReposMatchTypeNotInArray, + GithubComKloudliteAPIPkgReposMatchTypeRegex, +} + +func (e GithubComKloudliteAPIPkgReposMatchType) IsValid() bool { + switch e { + case GithubComKloudliteAPIPkgReposMatchTypeArray, GithubComKloudliteAPIPkgReposMatchTypeExact, GithubComKloudliteAPIPkgReposMatchTypeNotInArray, GithubComKloudliteAPIPkgReposMatchTypeRegex: + return true + } + return false +} + +func (e GithubComKloudliteAPIPkgReposMatchType) String() string { + return string(e) +} + +func (e *GithubComKloudliteAPIPkgReposMatchType) UnmarshalGQL(v interface{}) error { + str, ok := v.(string) + if !ok { + return fmt.Errorf("enums must be strings") + } + + *e = GithubComKloudliteAPIPkgReposMatchType(str) + if !e.IsValid() { + return fmt.Errorf("%s is not a valid Github__com___kloudlite___api___pkg___repos__MatchType", str) + } + return nil +} + +func (e GithubComKloudliteAPIPkgReposMatchType) MarshalGQL(w io.Writer) { + fmt.Fprint(w, strconv.Quote(e.String())) +} + type GithubComKloudliteOperatorApisClustersV1AWSPoolType string const ( diff --git a/apps/infra/internal/app/graph/schema.graphqls b/apps/infra/internal/app/graph/schema.graphqls index ea2bfe809..99aeb89c1 100644 --- a/apps/infra/internal/app/graph/schema.graphqls +++ b/apps/infra/internal/app/graph/schema.graphqls @@ -91,7 +91,7 @@ type Query { # byok infra_listBYOKClusters(search: SearchCluster, pagination: CursorPaginationIn): BYOKClusterPaginatedRecords @isLoggedInAndVerified @hasAccount infra_getBYOKCluster(name: String!): BYOKCluster @isLoggedInAndVerified @hasAccount - infrat_getBYOKClusterSetupInstructions(name: String!): String @isLoggedInAndVerified @hasAccount + infrat_getBYOKClusterSetupInstructions(name: String!): [String!] @isLoggedInAndVerified @hasAccount # global VPN infra_listGlobalVPNs(search: SearchGlobalVPNs, pagination: CursorPaginationIn): GlobalVPNPaginatedRecords @isLoggedInAndVerified @hasAccount diff --git a/apps/infra/internal/app/graph/schema.resolvers.go b/apps/infra/internal/app/graph/schema.resolvers.go index c628a0fae..1f2931de5 100644 --- a/apps/infra/internal/app/graph/schema.resolvers.go +++ b/apps/infra/internal/app/graph/schema.resolvers.go @@ -8,7 +8,6 @@ import ( "context" "encoding/base64" "fmt" - "github.com/kloudlite/api/pkg/errors" "github.com/kloudlite/api/apps/infra/internal/app/graph/generated" @@ -491,7 +490,7 @@ func (r *queryResolver) InfraGetBYOKCluster(ctx context.Context, name string) (* } // InfratGetBYOKClusterSetupInstructions is the resolver for the infrat_getBYOKClusterSetupInstructions field. -func (r *queryResolver) InfratGetBYOKClusterSetupInstructions(ctx context.Context, name string) (*string, error) { +func (r *queryResolver) InfratGetBYOKClusterSetupInstructions(ctx context.Context, name string) ([]string, error) { ictx, err := toInfraContext(ctx) if err != nil { return nil, errors.NewE(err) @@ -1104,17 +1103,5 @@ func (r *Resolver) Mutation() generated.MutationResolver { return &mutationResol // Query returns generated.QueryResolver implementation. func (r *Resolver) Query() generated.QueryResolver { return &queryResolver{r} } -type ( - mutationResolver struct{ *Resolver } - queryResolver struct{ *Resolver } -) - -// !!! WARNING !!! -// The code below was going to be deleted when updating resolvers. It has been copied here so you have -// one last chance to move it out of harms way if you want. There are two reasons this happens: -// - When renaming or deleting a resolver the old code will be put in here. You can safely delete -// it when you're done. -// - You have helper methods in this file. Move them out to keep these resolver files clean. -func (r *queryResolver) InfratGetBYOKSetupInstructions(ctx context.Context, name string) (*string, error) { - panic(fmt.Errorf("not implemented: InfratGetBYOKSetupInstructions - infrat_getBYOKSetupInstructions")) -} +type mutationResolver struct{ *Resolver } +type queryResolver struct{ *Resolver } diff --git a/apps/infra/internal/app/graph/struct-to-graphql/common-types.graphqls b/apps/infra/internal/app/graph/struct-to-graphql/common-types.graphqls index 19cc5b35d..5a62c8370 100644 --- a/apps/infra/internal/app/graph/struct-to-graphql/common-types.graphqls +++ b/apps/infra/internal/app/graph/struct-to-graphql/common-types.graphqls @@ -1336,6 +1336,13 @@ input MetadataIn { namespace: String } +enum Github__com___kloudlite___api___pkg___repos__MatchType { + array + exact + not_in_array + regex +} + enum Github__com___kloudlite___api___pkg___types__SyncAction { APPLY DELETE diff --git a/apps/infra/internal/app/graph/struct-to-graphql/globalvpn.graphqls b/apps/infra/internal/app/graph/struct-to-graphql/globalvpn.graphqls index 4fadfa558..84150b1bd 100644 --- a/apps/infra/internal/app/graph/struct-to-graphql/globalvpn.graphqls +++ b/apps/infra/internal/app/graph/struct-to-graphql/globalvpn.graphqls @@ -6,6 +6,7 @@ type GlobalVPN @shareable { creationTime: Date! displayName: String! id: ID! + kloudliteDevice: GlobalVPNKloudliteDevice! lastUpdatedBy: Github__com___kloudlite___api___common__CreatedOrUpdatedBy! markedForDeletion: Boolean metadata: Metadata! @goField(name: "objectMeta") @@ -22,6 +23,11 @@ type GlobalVPNEdge @shareable { node: GlobalVPN! } +type GlobalVPNKloudliteDevice @shareable { + ipAddr: String! + name: String! +} + type GlobalVPNPaginatedRecords @shareable { edges: [GlobalVPNEdge!]! pageInfo: PageInfo! @@ -32,6 +38,7 @@ input GlobalVPNIn { allocatableCIDRSuffix: Int! CIDR: String! displayName: String! + kloudliteDevice: GlobalVPNKloudliteDeviceIn! metadata: MetadataIn! numAllocatedClusterCIDRs: Int! numAllocatedDevices: Int! @@ -39,3 +46,8 @@ input GlobalVPNIn { wgInterface: String! } +input GlobalVPNKloudliteDeviceIn { + ipAddr: String! + name: String! +} + diff --git a/apps/infra/internal/app/graph/struct-to-graphql/matchfilter.graphqls b/apps/infra/internal/app/graph/struct-to-graphql/matchfilter.graphqls index ef1a0cb45..e1e59fb4d 100644 --- a/apps/infra/internal/app/graph/struct-to-graphql/matchfilter.graphqls +++ b/apps/infra/internal/app/graph/struct-to-graphql/matchfilter.graphqls @@ -1,20 +1,16 @@ type MatchFilter @shareable { array: [Any!] exact: Any - matchType: MatchFilterMatchType! + matchType: Github__com___kloudlite___api___pkg___repos__MatchType! + notInArray: [Any!] regex: String } input MatchFilterIn { array: [Any!] exact: Any - matchType: MatchFilterMatchType! + matchType: Github__com___kloudlite___api___pkg___repos__MatchType! + notInArray: [Any!] regex: String } -enum MatchFilterMatchType { - array - exact - regex -} - diff --git a/apps/infra/internal/app/process-error-on-apply.go b/apps/infra/internal/app/process-error-on-apply.go index 6a4a6c079..8290d324a 100644 --- a/apps/infra/internal/app/process-error-on-apply.go +++ b/apps/infra/internal/app/process-error-on-apply.go @@ -6,6 +6,7 @@ import ( "github.com/kloudlite/api/apps/infra/internal/domain" "github.com/kloudlite/api/apps/infra/internal/entities" + msgOfficeT "github.com/kloudlite/api/apps/message-office/types" t "github.com/kloudlite/api/apps/tenant-agent/types" "github.com/kloudlite/api/pkg/errors" fn "github.com/kloudlite/api/pkg/functions" @@ -22,8 +23,13 @@ func ProcessErrorOnApply(consumer ErrorOnApplyConsumer, logger logging.Logger, d processMsg := func(msg *types.ConsumeMsg) error { counter += 1 + em, err := msgOfficeT.UnmarshalErrMessage(msg.Payload) + if err != nil { + return errors.NewE(err) + } + var errObj t.AgentErrMessage - if err := json.Unmarshal(msg.Payload, &errObj); err != nil { + if err := json.Unmarshal(em.Error, &errObj); err != nil { return errors.NewE(err) } @@ -31,8 +37,8 @@ func ProcessErrorOnApply(consumer ErrorOnApplyConsumer, logger logging.Logger, d mLogger := logger.WithKV( "gvk", obj.GroupVersionKind(), - "accountName", errObj.AccountName, - "clusterName", errObj.ClusterName, + "accountName", em.AccountName, + "clusterName", em.ClusterName, ) mLogger.Infof("[%d] received message", counter) @@ -45,7 +51,7 @@ func ProcessErrorOnApply(consumer ErrorOnApplyConsumer, logger logging.Logger, d UserId: "sys-user:error-on-apply-worker", UserEmail: "", UserName: "", - AccountName: errObj.AccountName, + AccountName: em.AccountName, } opts := domain.UpdateAndDeleteOpts{MessageTimestamp: msg.Timestamp} @@ -60,9 +66,9 @@ func ProcessErrorOnApply(consumer ErrorOnApplyConsumer, logger logging.Logger, d } if errObj.Action == t.ActionApply { - return d.OnGlobalVPNConnectionApplyError(dctx, errObj.ClusterName, obj.GetName(), errObj.Error, opts) + return d.OnGlobalVPNConnectionApplyError(dctx, em.ClusterName, obj.GetName(), errObj.Error, opts) } - return d.OnGlobalVPNConnectionDeleteMessage(dctx, errObj.ClusterName, cc) + return d.OnGlobalVPNConnectionDeleteMessage(dctx, em.ClusterName, cc) } case nodepoolGVK.String(): { @@ -72,9 +78,9 @@ func ProcessErrorOnApply(consumer ErrorOnApplyConsumer, logger logging.Logger, d } if errObj.Action == t.ActionApply { - return d.OnNodepoolApplyError(dctx, errObj.ClusterName, obj.GetName(), errObj.Error, opts) + return d.OnNodepoolApplyError(dctx, em.ClusterName, obj.GetName(), errObj.Error, opts) } - return d.OnNodePoolDeleteMessage(dctx, errObj.ClusterName, nodepool) + return d.OnNodePoolDeleteMessage(dctx, em.ClusterName, nodepool) } case clusterMsvcGVK.String(): { @@ -84,9 +90,9 @@ func ProcessErrorOnApply(consumer ErrorOnApplyConsumer, logger logging.Logger, d } if errObj.Action == t.ActionApply { - return d.OnClusterManagedServiceApplyError(dctx, errObj.ClusterName, obj.GetName(), errObj.Error, opts) + return d.OnClusterManagedServiceApplyError(dctx, em.ClusterName, obj.GetName(), errObj.Error, opts) } - return d.OnClusterManagedServiceDeleteMessage(dctx, errObj.ClusterName, cmsvc) + return d.OnClusterManagedServiceDeleteMessage(dctx, em.ClusterName, cmsvc) } case helmreleaseGVK.String(): @@ -97,9 +103,9 @@ func ProcessErrorOnApply(consumer ErrorOnApplyConsumer, logger logging.Logger, d } if errObj.Action == t.ActionApply { - return d.OnHelmReleaseApplyError(dctx, errObj.ClusterName, obj.GetName(), errObj.Error, opts) + return d.OnHelmReleaseApplyError(dctx, em.ClusterName, obj.GetName(), errObj.Error, opts) } - return d.OnHelmReleaseDeleteMessage(dctx, errObj.ClusterName, helmRelease) + return d.OnHelmReleaseDeleteMessage(dctx, em.ClusterName, helmRelease) } default: { diff --git a/apps/infra/internal/app/process-resource-updates.go b/apps/infra/internal/app/process-resource-updates.go index 0a4f05308..87e4bc446 100644 --- a/apps/infra/internal/app/process-resource-updates.go +++ b/apps/infra/internal/app/process-resource-updates.go @@ -22,6 +22,7 @@ import ( corev1 "k8s.io/api/core/v1" "sigs.k8s.io/controller-runtime/pkg/client" + msgOfficeT "github.com/kloudlite/api/apps/message-office/types" networkingv1 "k8s.io/api/networking/v1" ) @@ -33,9 +34,7 @@ func gvk(obj client.Object) string { } var ( - clusterGVK = fn.GVK("clusters.kloudlite.io/v1", "Cluster") - // clusterConnGVK = fn.GVK("wireguard.kloudlite.io/v1", "ClusterConnection") - // globalVpnGVK = fn.GVK("wireguard.kloudlite.io/v1", "GlobalVPNConnection") + clusterGVK = fn.GVK("clusters.kloudlite.io/v1", "Cluster") globalVpnGVK = fn.GVK("wireguard.kloudlite.io/v1", "GlobalVPN") nodepoolGVK = fn.GVK("clusters.kloudlite.io/v1", "NodePool") helmreleaseGVK = fn.GVK("crds.kloudlite.io/v1", "HelmChart") @@ -52,8 +51,14 @@ func processResourceUpdates(consumer ReceiveResourceUpdatesConsumer, d domain.Do readMsg := func(msg *msgTypes.ConsumeMsg) error { logger.Debugf("processing msg timestamp %s", msg.Timestamp.Format(time.RFC3339)) + ru, err := msgOfficeT.UnmarshalResourceUpdate(msg.Payload) + if err != nil { + logger.Errorf(err, "unmarshaling resource update") + return nil + } + var su types.ResourceUpdate - if err := json.Unmarshal(msg.Payload, &su); err != nil { + if err := json.Unmarshal(ru.WatcherUpdate, &su); err != nil { logger.Errorf(err, "parsing into status update") return nil } @@ -63,12 +68,12 @@ func processResourceUpdates(consumer ReceiveResourceUpdatesConsumer, d domain.Do return nil } - if len(strings.TrimSpace(su.AccountName)) == 0 { + if len(strings.TrimSpace(ru.AccountName)) == 0 { logger.Infof("message does not contain 'accountName', so won't be able to find a resource uniquely, thus ignoring ...") return nil } - dctx := domain.InfraContext{Context: context.TODO(), UserId: "sys-user-process-infra-updates", AccountName: su.AccountName} + dctx := domain.InfraContext{Context: context.TODO(), UserId: "sys-user-process-infra-updates", AccountName: ru.AccountName} obj := unstructured.Unstructured{Object: su.Object} gvkStr := obj.GetObjectKind().GroupVersionKind().String() @@ -93,7 +98,7 @@ func processResourceUpdates(consumer ReceiveResourceUpdatesConsumer, d domain.Do "gvk", obj.GetObjectKind().GroupVersionKind(), "NN", fmt.Sprintf("%s/%s", obj.GetNamespace(), obj.GetName()), "resource-status", resStatus, - "accountName/clusterName", fmt.Sprintf("%s/%s", su.AccountName, su.ClusterName), + "accountName/clusterName", fmt.Sprintf("%s/%s", ru.AccountName, ru.ClusterName), ) mLogger.Infof("received message") @@ -130,9 +135,9 @@ func processResourceUpdates(consumer ReceiveResourceUpdatesConsumer, d domain.Do } if resStatus == types.ResourceStatusDeleted { - return d.OnGlobalVPNConnectionDeleteMessage(dctx, su.ClusterName, gvpn) + return d.OnGlobalVPNConnectionDeleteMessage(dctx, ru.ClusterName, gvpn) } - return d.OnGlobalVPNConnectionUpdateMessage(dctx, su.ClusterName, gvpn, resStatus, domain.UpdateAndDeleteOpts{MessageTimestamp: msg.Timestamp}) + return d.OnGlobalVPNConnectionUpdateMessage(dctx, ru.ClusterName, gvpn, resStatus, domain.UpdateAndDeleteOpts{MessageTimestamp: msg.Timestamp}) } case nodepoolGVK.String(): { @@ -142,9 +147,9 @@ func processResourceUpdates(consumer ReceiveResourceUpdatesConsumer, d domain.Do } if resStatus == types.ResourceStatusDeleted { - return d.OnNodePoolDeleteMessage(dctx, su.ClusterName, np) + return d.OnNodePoolDeleteMessage(dctx, ru.ClusterName, np) } - return d.OnNodePoolUpdateMessage(dctx, su.ClusterName, np, resStatus, domain.UpdateAndDeleteOpts{MessageTimestamp: msg.Timestamp}) + return d.OnNodePoolUpdateMessage(dctx, ru.ClusterName, np, resStatus, domain.UpdateAndDeleteOpts{MessageTimestamp: msg.Timestamp}) } case pvcGVK.String(): { @@ -154,9 +159,9 @@ func processResourceUpdates(consumer ReceiveResourceUpdatesConsumer, d domain.Do } if resStatus == types.ResourceStatusDeleted { - return d.OnPVCDeleteMessage(dctx, su.ClusterName, pvc) + return d.OnPVCDeleteMessage(dctx, ru.ClusterName, pvc) } - return d.OnPVCUpdateMessage(dctx, su.ClusterName, pvc, resStatus, domain.UpdateAndDeleteOpts{MessageTimestamp: msg.Timestamp}) + return d.OnPVCUpdateMessage(dctx, ru.ClusterName, pvc, resStatus, domain.UpdateAndDeleteOpts{MessageTimestamp: msg.Timestamp}) } case pvGVK.String(): @@ -167,9 +172,9 @@ func processResourceUpdates(consumer ReceiveResourceUpdatesConsumer, d domain.Do } if resStatus == types.ResourceStatusDeleted { - return d.OnPVDeleteMessage(dctx, su.ClusterName, pv) + return d.OnPVDeleteMessage(dctx, ru.ClusterName, pv) } - return d.OnPVUpdateMessage(dctx, su.ClusterName, pv, resStatus, domain.UpdateAndDeleteOpts{MessageTimestamp: msg.Timestamp}) + return d.OnPVUpdateMessage(dctx, ru.ClusterName, pv, resStatus, domain.UpdateAndDeleteOpts{MessageTimestamp: msg.Timestamp}) } case volumeAttachmentGVK.String(): @@ -180,9 +185,9 @@ func processResourceUpdates(consumer ReceiveResourceUpdatesConsumer, d domain.Do } if resStatus == types.ResourceStatusDeleted { - return d.OnVolumeAttachmentDeleteMessage(dctx, su.ClusterName, volatt) + return d.OnVolumeAttachmentDeleteMessage(dctx, ru.ClusterName, volatt) } - return d.OnVolumeAttachmentUpdateMessage(dctx, su.ClusterName, volatt, resStatus, domain.UpdateAndDeleteOpts{MessageTimestamp: msg.Timestamp}) + return d.OnVolumeAttachmentUpdateMessage(dctx, ru.ClusterName, volatt, resStatus, domain.UpdateAndDeleteOpts{MessageTimestamp: msg.Timestamp}) } case helmreleaseGVK.String(): @@ -193,9 +198,9 @@ func processResourceUpdates(consumer ReceiveResourceUpdatesConsumer, d domain.Do } if resStatus == types.ResourceStatusDeleted { - return d.OnHelmReleaseDeleteMessage(dctx, su.ClusterName, hr) + return d.OnHelmReleaseDeleteMessage(dctx, ru.ClusterName, hr) } - return d.OnHelmReleaseUpdateMessage(dctx, su.ClusterName, hr, resStatus, domain.UpdateAndDeleteOpts{MessageTimestamp: msg.Timestamp}) + return d.OnHelmReleaseUpdateMessage(dctx, ru.ClusterName, hr, resStatus, domain.UpdateAndDeleteOpts{MessageTimestamp: msg.Timestamp}) } case namespaceGVK.String(): @@ -207,9 +212,9 @@ func processResourceUpdates(consumer ReceiveResourceUpdatesConsumer, d domain.Do } if resStatus == types.ResourceStatusDeleted { - return d.OnNamespaceDeleteMessage(dctx, su.ClusterName, ns) + return d.OnNamespaceDeleteMessage(dctx, ru.ClusterName, ns) } - return d.OnNamespaceUpdateMessage(dctx, su.ClusterName, ns, resStatus, domain.UpdateAndDeleteOpts{MessageTimestamp: msg.Timestamp}) + return d.OnNamespaceUpdateMessage(dctx, ru.ClusterName, ns, resStatus, domain.UpdateAndDeleteOpts{MessageTimestamp: msg.Timestamp}) } case clusterMsvcGVK.String(): @@ -226,9 +231,9 @@ func processResourceUpdates(consumer ReceiveResourceUpdatesConsumer, d domain.Do } if resStatus == types.ResourceStatusDeleted { - return d.OnClusterManagedServiceDeleteMessage(dctx, su.ClusterName, cmsvc) + return d.OnClusterManagedServiceDeleteMessage(dctx, ru.ClusterName, cmsvc) } - return d.OnClusterManagedServiceUpdateMessage(dctx, su.ClusterName, cmsvc, resStatus, domain.UpdateAndDeleteOpts{MessageTimestamp: msg.Timestamp}) + return d.OnClusterManagedServiceUpdateMessage(dctx, ru.ClusterName, cmsvc, resStatus, domain.UpdateAndDeleteOpts{MessageTimestamp: msg.Timestamp}) } case ingressGVK.String(): @@ -239,9 +244,9 @@ func processResourceUpdates(consumer ReceiveResourceUpdatesConsumer, d domain.Do } if resStatus == types.ResourceStatusDeleted { - return d.OnIngressDeleteMessage(dctx, su.ClusterName, ingress) + return d.OnIngressDeleteMessage(dctx, ru.ClusterName, ingress) } - return d.OnIngressUpdateMessage(dctx, su.ClusterName, ingress, resStatus, domain.UpdateAndDeleteOpts{MessageTimestamp: msg.Timestamp}) + return d.OnIngressUpdateMessage(dctx, ru.ClusterName, ingress, resStatus, domain.UpdateAndDeleteOpts{MessageTimestamp: msg.Timestamp}) } case secretGVK.String(): @@ -259,7 +264,7 @@ func processResourceUpdates(consumer ReceiveResourceUpdatesConsumer, d domain.Do // FIXME: not implemented for now return nil } - return d.UpsertBYOKClusterKubeconfig(dctx, su.ClusterName, secret.Data["kubeconfig"]) + return d.UpsertBYOKClusterKubeconfig(dctx, ru.ClusterName, secret.Data["kubeconfig"]) } default: { diff --git a/apps/infra/internal/domain/api.go b/apps/infra/internal/domain/api.go index 3ceafa2c9..9637e902e 100644 --- a/apps/infra/internal/domain/api.go +++ b/apps/infra/internal/domain/api.go @@ -77,7 +77,7 @@ type Domain interface { UpdateBYOKCluster(ctx InfraContext, clusterName string, displayName string) (*entities.BYOKCluster, error) ListBYOKCluster(ctx InfraContext, search map[string]repos.MatchFilter, pagination repos.CursorPagination) (*repos.PaginatedRecord[*entities.BYOKCluster], error) GetBYOKCluster(ctx InfraContext, name string) (*entities.BYOKCluster, error) - GetBYOKClusterSetupInstructions(ctx InfraContext, name string) (*string, error) + GetBYOKClusterSetupInstructions(ctx InfraContext, name string) ([]string, error) DeleteBYOKCluster(ctx InfraContext, name string) error UpsertBYOKClusterKubeconfig(ctx InfraContext, clusterName string, kubeconfig []byte) error diff --git a/apps/infra/internal/domain/byok-clusters.go b/apps/infra/internal/domain/byok-clusters.go index 5cbf4d74c..02ae6c249 100644 --- a/apps/infra/internal/domain/byok-clusters.go +++ b/apps/infra/internal/domain/byok-clusters.go @@ -171,12 +171,26 @@ func (d *domain) GetBYOKCluster(ctx InfraContext, name string) (*entities.BYOKCl return c, nil } -func (d *domain) GetBYOKClusterSetupInstructions(ctx InfraContext, name string) (*string, error) { +func (d *domain) GetBYOKClusterSetupInstructions(ctx InfraContext, name string) ([]string, error) { cluster, err := d.findBYOKCluster(ctx, name) if err != nil { return nil, err } - return fn.New(fmt.Sprintf(`helm upgrade --install kloudlite --namespace kloudlite --create-namespace kloudlite/kloudlite-agent --set accountName="%s" --set clusterName="%s" --set clusterToken="%s" --set messageOfficeGRPCAddr="%s" --set kloudliteRelease="%s" --set byok.enabled=true --set helmCharts.ingressNginx.enabled=true --set helmCharts.certManager.enabled=true`, ctx.AccountName, name, cluster.ClusterToken, d.env.MessageOfficeExternalGrpcAddr, d.env.KloudliteRelease)), nil + + return []string{ + fmt.Sprintf(`helm repo add kloudlite https://kloudlite.github.io/helm-charts`), + fmt.Sprintf(`helm repo update kloudlite`), + fmt.Sprintf(`helm upgrade --install kloudlite --namespace kloudlite --create-namespace kloudlite/kloudlite-agent --version %s --set accountName="%s" --set clusterName="%s" --set clusterToken="%s" --set messageOfficeGRPCAddr="%s" --set byok.enabled=true --set helmCharts.ingressNginx.enabled=true --set helmCharts.certManager.enabled=true`, d.env.KloudliteRelease, ctx.AccountName, name, cluster.ClusterToken, d.env.MessageOfficeExternalGrpcAddr), + }, nil +} + +func (d *domain) GetBYOKClusterSetupInstructions2(ctx InfraContext, name string) (*string, error) { + cluster, err := d.findBYOKCluster(ctx, name) + if err != nil { + return nil, err + } + + return fn.New(fmt.Sprintf(`helm upgrade --install kloudlite --namespace kloudlite --create-namespace kloudlite/kloudlite-agent --version %s --set accountName="%s" --set clusterName="%s" --set clusterToken="%s" --set messageOfficeGRPCAddr="%s" --set byok.enabled=true --set helmCharts.ingressNginx.enabled=true --set helmCharts.certManager.enabled=true`, d.env.KloudliteRelease, ctx.AccountName, name, cluster.ClusterToken, d.env.MessageOfficeExternalGrpcAddr)), nil } func (d *domain) DeleteBYOKCluster(ctx InfraContext, name string) error { diff --git a/apps/iot-console/internal/app/graph/generated/generated.go b/apps/iot-console/internal/app/graph/generated/generated.go index d758fa403..de252b056 100644 --- a/apps/iot-console/internal/app/graph/generated/generated.go +++ b/apps/iot-console/internal/app/graph/generated/generated.go @@ -573,7 +573,7 @@ type IOTProjectResolver interface { UpdateTime(ctx context.Context, obj *entities.IOTProject) (string, error) } type MatchFilterResolver interface { - MatchType(ctx context.Context, obj *repos.MatchFilter) (string, error) + MatchType(ctx context.Context, obj *repos.MatchFilter) (model.GithubComKloudliteAPIPkgReposMatchType, error) } type MetadataResolver interface { Annotations(ctx context.Context, obj *v1.ObjectMeta) (map[string]interface{}, error) @@ -623,7 +623,7 @@ type IOTDeviceBlueprintInResolver interface { BluePrintType(ctx context.Context, obj *entities.IOTDeviceBlueprint, data model.GithubComKloudliteAPIAppsIotConsoleInternalEntitiesBluePrintType) error } type MatchFilterInResolver interface { - MatchType(ctx context.Context, obj *repos.MatchFilter, data string) error + MatchType(ctx context.Context, obj *repos.MatchFilter, data model.GithubComKloudliteAPIPkgReposMatchType) error } type MetadataInResolver interface { Annotations(ctx context.Context, obj *v1.ObjectMeta, data map[string]interface{}) error @@ -3538,6 +3538,13 @@ enum Github__com___kloudlite___api___apps___iot____console___internal___entities singleton_blueprint } +enum Github__com___kloudlite___api___pkg___repos__MatchType { + array + exact + not_in_array + regex +} + enum Github__com___kloudlite___operator___apis___crds___v1__ConfigOrSecret { config pvc @@ -3823,7 +3830,7 @@ input IOTProjectIn { {Name: "../struct-to-graphql/matchfilter.graphqls", Input: `type MatchFilter @shareable { array: [Any!] exact: Any - matchType: String! + matchType: Github__com___kloudlite___api___pkg___repos__MatchType! notInArray: [Any!] regex: String } @@ -3831,7 +3838,7 @@ input IOTProjectIn { input MatchFilterIn { array: [Any!] exact: Any - matchType: String! + matchType: Github__com___kloudlite___api___pkg___repos__MatchType! notInArray: [Any!] regex: String } @@ -16401,9 +16408,9 @@ func (ec *executionContext) _MatchFilter_matchType(ctx context.Context, field gr } return graphql.Null } - res := resTmp.(string) + res := resTmp.(model.GithubComKloudliteAPIPkgReposMatchType) fc.Result = res - return ec.marshalNString2string(ctx, field.Selections, res) + return ec.marshalNGithub__com___kloudlite___api___pkg___repos__MatchType2githubᚗcomᚋkloudliteᚋapiᚋappsᚋiotᚑconsoleᚋinternalᚋappᚋgraphᚋmodelᚐGithubComKloudliteAPIPkgReposMatchType(ctx, field.Selections, res) } func (ec *executionContext) fieldContext_MatchFilter_matchType(ctx context.Context, field graphql.CollectedField) (fc *graphql.FieldContext, err error) { @@ -16413,7 +16420,7 @@ func (ec *executionContext) fieldContext_MatchFilter_matchType(ctx context.Conte IsMethod: true, IsResolver: true, Child: func(ctx context.Context, field graphql.CollectedField) (*graphql.FieldContext, error) { - return nil, errors.New("field of type String does not have child fields") + return nil, errors.New("field of type Github__com___kloudlite___api___pkg___repos__MatchType does not have child fields") }, } return fc, nil @@ -23396,7 +23403,7 @@ func (ec *executionContext) unmarshalInputMatchFilterIn(ctx context.Context, obj var err error ctx := graphql.WithPathContext(ctx, graphql.NewPathWithField("matchType")) - data, err := ec.unmarshalNString2string(ctx, v) + data, err := ec.unmarshalNGithub__com___kloudlite___api___pkg___repos__MatchType2githubᚗcomᚋkloudliteᚋapiᚋappsᚋiotᚑconsoleᚋinternalᚋappᚋgraphᚋmodelᚐGithubComKloudliteAPIPkgReposMatchType(ctx, v) if err != nil { return it, err } @@ -28081,6 +28088,16 @@ func (ec *executionContext) marshalNGithub__com___kloudlite___api___common__Crea return ec._Github__com___kloudlite___api___common__CreatedOrUpdatedBy(ctx, sel, v) } +func (ec *executionContext) unmarshalNGithub__com___kloudlite___api___pkg___repos__MatchType2githubᚗcomᚋkloudliteᚋapiᚋappsᚋiotᚑconsoleᚋinternalᚋappᚋgraphᚋmodelᚐGithubComKloudliteAPIPkgReposMatchType(ctx context.Context, v interface{}) (model.GithubComKloudliteAPIPkgReposMatchType, error) { + var res model.GithubComKloudliteAPIPkgReposMatchType + err := res.UnmarshalGQL(v) + return res, graphql.ErrorOnPath(ctx, err) +} + +func (ec *executionContext) marshalNGithub__com___kloudlite___api___pkg___repos__MatchType2githubᚗcomᚋkloudliteᚋapiᚋappsᚋiotᚑconsoleᚋinternalᚋappᚋgraphᚋmodelᚐGithubComKloudliteAPIPkgReposMatchType(ctx context.Context, sel ast.SelectionSet, v model.GithubComKloudliteAPIPkgReposMatchType) graphql.Marshaler { + return v +} + func (ec *executionContext) marshalNGithub__com___kloudlite___operator___apis___crds___v1__AppContainer2ᚕᚖgithubᚗcomᚋkloudliteᚋapiᚋappsᚋiotᚑconsoleᚋinternalᚋappᚋgraphᚋmodelᚐGithubComKloudliteOperatorApisCrdsV1AppContainerᚄ(ctx context.Context, sel ast.SelectionSet, v []*model.GithubComKloudliteOperatorApisCrdsV1AppContainer) graphql.Marshaler { ret := make(graphql.Array, len(v)) var wg sync.WaitGroup @@ -29229,7 +29246,7 @@ func (ec *executionContext) marshalNfederation__Scope2ᚕᚕstringᚄ(ctx contex return ret } -func (ec *executionContext) unmarshalOAny2interface(ctx context.Context, v interface{}) (interface{}, error) { +func (ec *executionContext) unmarshalOAny2interface(ctx context.Context, v interface{}) (any, error) { if v == nil { return nil, nil } @@ -29237,7 +29254,7 @@ func (ec *executionContext) unmarshalOAny2interface(ctx context.Context, v inter return res, graphql.ErrorOnPath(ctx, err) } -func (ec *executionContext) marshalOAny2interface(ctx context.Context, sel ast.SelectionSet, v interface{}) graphql.Marshaler { +func (ec *executionContext) marshalOAny2interface(ctx context.Context, sel ast.SelectionSet, v any) graphql.Marshaler { if v == nil { return graphql.Null } diff --git a/apps/iot-console/internal/app/graph/matchfilter.resolvers.go b/apps/iot-console/internal/app/graph/matchfilter.resolvers.go index 321e7b2fc..8b4fea54a 100644 --- a/apps/iot-console/internal/app/graph/matchfilter.resolvers.go +++ b/apps/iot-console/internal/app/graph/matchfilter.resolvers.go @@ -9,16 +9,17 @@ import ( "fmt" "github.com/kloudlite/api/apps/iot-console/internal/app/graph/generated" + "github.com/kloudlite/api/apps/iot-console/internal/app/graph/model" "github.com/kloudlite/api/pkg/repos" ) // MatchType is the resolver for the matchType field. -func (r *matchFilterResolver) MatchType(ctx context.Context, obj *repos.MatchFilter) (string, error) { +func (r *matchFilterResolver) MatchType(ctx context.Context, obj *repos.MatchFilter) (model.GithubComKloudliteAPIPkgReposMatchType, error) { panic(fmt.Errorf("not implemented: MatchType - matchType")) } // MatchType is the resolver for the matchType field. -func (r *matchFilterInResolver) MatchType(ctx context.Context, obj *repos.MatchFilter, data string) error { +func (r *matchFilterInResolver) MatchType(ctx context.Context, obj *repos.MatchFilter, data model.GithubComKloudliteAPIPkgReposMatchType) error { panic(fmt.Errorf("not implemented: MatchType - matchType")) } diff --git a/apps/iot-console/internal/app/graph/model/models_gen.go b/apps/iot-console/internal/app/graph/model/models_gen.go index 401b1b4da..8ec823638 100644 --- a/apps/iot-console/internal/app/graph/model/models_gen.go +++ b/apps/iot-console/internal/app/graph/model/models_gen.go @@ -593,6 +593,51 @@ func (e GithubComKloudliteAPIAppsIotConsoleInternalEntitiesBluePrintType) Marsha fmt.Fprint(w, strconv.Quote(e.String())) } +type GithubComKloudliteAPIPkgReposMatchType string + +const ( + GithubComKloudliteAPIPkgReposMatchTypeArray GithubComKloudliteAPIPkgReposMatchType = "array" + GithubComKloudliteAPIPkgReposMatchTypeExact GithubComKloudliteAPIPkgReposMatchType = "exact" + GithubComKloudliteAPIPkgReposMatchTypeNotInArray GithubComKloudliteAPIPkgReposMatchType = "not_in_array" + GithubComKloudliteAPIPkgReposMatchTypeRegex GithubComKloudliteAPIPkgReposMatchType = "regex" +) + +var AllGithubComKloudliteAPIPkgReposMatchType = []GithubComKloudliteAPIPkgReposMatchType{ + GithubComKloudliteAPIPkgReposMatchTypeArray, + GithubComKloudliteAPIPkgReposMatchTypeExact, + GithubComKloudliteAPIPkgReposMatchTypeNotInArray, + GithubComKloudliteAPIPkgReposMatchTypeRegex, +} + +func (e GithubComKloudliteAPIPkgReposMatchType) IsValid() bool { + switch e { + case GithubComKloudliteAPIPkgReposMatchTypeArray, GithubComKloudliteAPIPkgReposMatchTypeExact, GithubComKloudliteAPIPkgReposMatchTypeNotInArray, GithubComKloudliteAPIPkgReposMatchTypeRegex: + return true + } + return false +} + +func (e GithubComKloudliteAPIPkgReposMatchType) String() string { + return string(e) +} + +func (e *GithubComKloudliteAPIPkgReposMatchType) UnmarshalGQL(v interface{}) error { + str, ok := v.(string) + if !ok { + return fmt.Errorf("enums must be strings") + } + + *e = GithubComKloudliteAPIPkgReposMatchType(str) + if !e.IsValid() { + return fmt.Errorf("%s is not a valid Github__com___kloudlite___api___pkg___repos__MatchType", str) + } + return nil +} + +func (e GithubComKloudliteAPIPkgReposMatchType) MarshalGQL(w io.Writer) { + fmt.Fprint(w, strconv.Quote(e.String())) +} + type GithubComKloudliteOperatorApisCrdsV1ConfigOrSecret string const ( diff --git a/apps/iot-console/internal/app/graph/struct-to-graphql/common-types.graphqls b/apps/iot-console/internal/app/graph/struct-to-graphql/common-types.graphqls index 02a61da08..35466e3b6 100644 --- a/apps/iot-console/internal/app/graph/struct-to-graphql/common-types.graphqls +++ b/apps/iot-console/internal/app/graph/struct-to-graphql/common-types.graphqls @@ -451,6 +451,13 @@ enum Github__com___kloudlite___api___apps___iot____console___internal___entities singleton_blueprint } +enum Github__com___kloudlite___api___pkg___repos__MatchType { + array + exact + not_in_array + regex +} + enum Github__com___kloudlite___operator___apis___crds___v1__ConfigOrSecret { config pvc diff --git a/apps/iot-console/internal/app/graph/struct-to-graphql/matchfilter.graphqls b/apps/iot-console/internal/app/graph/struct-to-graphql/matchfilter.graphqls index c60308168..e1e59fb4d 100644 --- a/apps/iot-console/internal/app/graph/struct-to-graphql/matchfilter.graphqls +++ b/apps/iot-console/internal/app/graph/struct-to-graphql/matchfilter.graphqls @@ -1,7 +1,7 @@ type MatchFilter @shareable { array: [Any!] exact: Any - matchType: String! + matchType: Github__com___kloudlite___api___pkg___repos__MatchType! notInArray: [Any!] regex: String } @@ -9,7 +9,7 @@ type MatchFilter @shareable { input MatchFilterIn { array: [Any!] exact: Any - matchType: String! + matchType: Github__com___kloudlite___api___pkg___repos__MatchType! notInArray: [Any!] regex: String } diff --git a/apps/message-office/internal/app/grpc-server.go b/apps/message-office/internal/app/grpc-server.go index daa9b1bf5..a54423575 100644 --- a/apps/message-office/internal/app/grpc-server.go +++ b/apps/message-office/internal/app/grpc-server.go @@ -14,6 +14,7 @@ import ( "github.com/pkg/errors" "google.golang.org/grpc/metadata" + msgOfficeT "github.com/kloudlite/api/apps/message-office/types" "github.com/kloudlite/api/pkg/messaging" msg_nats "github.com/kloudlite/api/pkg/messaging/nats" "github.com/kloudlite/api/pkg/messaging/types" @@ -49,17 +50,17 @@ type ( // ReceiveConsoleResourceUpdate implements messages.MessageDispatchServiceServer. func (g *grpcServer) ReceiveConsoleResourceUpdate(ctx context.Context, msg *messages.ResourceUpdate) (*messages.Empty, error) { - logger := g.logger.WithKV("accountName", msg.AccountName).WithKV("cluster", msg.ClusterName) + accountName, clusterName, err := validateAndDecodeFromGrpcContext(ctx, g.ev.TokenHashingSecret) + if err != nil { + return nil, err + } + logger := g.logger.WithKV("accountName", accountName).WithKV("cluster", clusterName) logger.Debugf("console resource update request received") defer func() { logger.Debugf("console resource update request processed") }() - if _, _, err := validateAndDecodeAccessToken(msg.AccessToken, g.ev.TokenHashingSecret); err != nil { - return nil, err - } - - if err := g.processConsoleResourceUpdate(ctx, msg); err != nil { + if err := g.processConsoleResourceUpdate(ctx, accountName, clusterName, msg); err != nil { return nil, err } @@ -68,17 +69,18 @@ func (g *grpcServer) ReceiveConsoleResourceUpdate(ctx context.Context, msg *mess // ReceiveContainerRegistryUpdate implements messages.MessageDispatchServiceServer. func (g *grpcServer) ReceiveContainerRegistryUpdate(ctx context.Context, msg *messages.ResourceUpdate) (*messages.Empty, error) { - logger := g.logger.WithKV("accountName", msg.AccountName).WithKV("cluster", msg.ClusterName) + accountName, clusterName, err := validateAndDecodeFromGrpcContext(ctx, g.ev.TokenHashingSecret) + if err != nil { + return nil, err + } + + logger := g.logger.WithKV("accountName", accountName).WithKV("cluster", clusterName) logger.Debugf("container registry resource update request received") defer func() { logger.Debugf("container registry resource update request processed") }() - if _, _, err := validateAndDecodeAccessToken(msg.AccessToken, g.ev.TokenHashingSecret); err != nil { - return nil, err - } - - if err := g.processContainerRegistryResourceUpdate(ctx, msg); err != nil { + if err := g.processContainerRegistryResourceUpdate(ctx, accountName, clusterName, msg); err != nil { return nil, err } @@ -87,7 +89,12 @@ func (g *grpcServer) ReceiveContainerRegistryUpdate(ctx context.Context, msg *me // ReceiveError implements messages.MessageDispatchServiceServer. func (g *grpcServer) ReceiveError(ctx context.Context, msg *messages.ErrorData) (*messages.Empty, error) { - logger := g.logger.WithKV("accountName", msg.AccountName).WithKV("cluster", msg.ClusterName) + accountName, clusterName, err := validateAndDecodeFromGrpcContext(ctx, g.ev.TokenHashingSecret) + if err != nil { + return nil, err + } + + logger := g.logger.WithKV("accountName", accountName).WithKV("cluster", clusterName) logger.Debugf("request received for access token validation") isValid := true @@ -95,11 +102,7 @@ func (g *grpcServer) ReceiveError(ctx context.Context, msg *messages.ErrorData) logger.Debugf("is access token valid? (%v)", isValid) }() - if _, _, err := validateAndDecodeAccessToken(msg.AccessToken, g.ev.TokenHashingSecret); err != nil { - return nil, err - } - - if err := g.processError(ctx, msg.AccountName, msg.ClusterName, msg.Message); err != nil { + if err := g.processError(ctx, accountName, clusterName, msg.Message); err != nil { return nil, err } @@ -108,17 +111,18 @@ func (g *grpcServer) ReceiveError(ctx context.Context, msg *messages.ErrorData) // ReceiveInfraResourceUpdate implements messages.MessageDispatchServiceServer. func (g *grpcServer) ReceiveInfraResourceUpdate(ctx context.Context, msg *messages.ResourceUpdate) (*messages.Empty, error) { - logger := g.logger.WithKV("accountName", msg.AccountName).WithKV("cluster", msg.ClusterName) + accountName, clusterName, err := validateAndDecodeFromGrpcContext(ctx, g.ev.TokenHashingSecret) + if err != nil { + return nil, err + } + + logger := g.logger.WithKV("accountName", accountName).WithKV("cluster", clusterName) logger.Debugf("infra resource update request received") defer func() { logger.Debugf("infra resource update request processed") }() - if _, _, err := validateAndDecodeAccessToken(msg.AccessToken, g.ev.TokenHashingSecret); err != nil { - return nil, err - } - - if err := g.processInfraResourceUpdate(ctx, msg); err != nil { + if err := g.processInfraResourceUpdate(ctx, accountName, clusterName, msg); err != nil { return nil, err } @@ -229,21 +233,18 @@ func (g *grpcServer) validateAndDecodeFromGrpcContext(grpcServerCtx context.Cont } func (g *grpcServer) ValidateAccessToken(ctx context.Context, msg *messages.ValidateAccessTokenIn) (*messages.ValidateAccessTokenOut, error) { - logger := g.logger.WithKV("accountName", msg.AccountName).WithKV("cluster", msg.ClusterName) - logger.Debugf("request received for access token validation") - isValid := true + g.logger.Debugf("request received for access token validation") + accountName, clusterName, err := validateAndDecodeFromGrpcContext(ctx, g.ev.TokenHashingSecret) + if err != nil { + return nil, err + } + + logger := g.logger.WithKV("accountName", accountName).WithKV("cluster", clusterName) defer func() { - logger.Debugf("is access token valid? (%v)", isValid) + logger.Debugf("is access token valid? (%v)", true) }() - if msg.AccessToken == g.ev.PlatformAccessToken { - return &messages.ValidateAccessTokenOut{Valid: true}, nil - } - - if _, _, err := validateAndDecodeAccessToken(msg.AccessToken, g.ev.TokenHashingSecret); err != nil { - isValid = false - } - return &messages.ValidateAccessTokenOut{Valid: isValid}, nil + return &messages.ValidateAccessTokenOut{Valid: true}, nil } func (g *grpcServer) processError(ctx context.Context, accountName string, clusterName string, msg []byte) (err error) { @@ -260,21 +261,30 @@ func (g *grpcServer) processError(ctx context.Context, accountName string, clust logger.Infof("[%v] processed error-on-apply message", g.infraUpdatesCounter) }() + b, err := msgOfficeT.MarshalErrMessage(msgOfficeT.ErrMessage{ + AccountName: accountName, + ClusterName: clusterName, + Error: msg, + }) + if err != nil { + return errors.Wrap(err, "while marshaling resource update") + } + msgTopic := common.GetPlatformClusterMessagingTopic(accountName, clusterName, common.InfraReceiver, common.EventErrorOnApply) - if err := g.updatesProducer.Produce(ctx, types.ProduceMsg{Subject: msgTopic, Payload: msg}); err != nil { + if err := g.updatesProducer.Produce(ctx, types.ProduceMsg{Subject: msgTopic, Payload: b}); err != nil { return errors.Wrap(err, fmt.Sprintf("while producing to topic (%s)", msgTopic)) } logger.Infof("[%v] dispatched error-on-apply message to %s receiver", g.errorMessagesCounter, common.InfraReceiver) msgTopic = common.GetPlatformClusterMessagingTopic(accountName, clusterName, common.ConsoleReceiver, common.EventErrorOnApply) - if err := g.updatesProducer.Produce(ctx, types.ProduceMsg{Subject: msgTopic, Payload: msg}); err != nil { + if err := g.updatesProducer.Produce(ctx, types.ProduceMsg{Subject: msgTopic, Payload: b}); err != nil { return errors.Wrap(err, fmt.Sprintf("while producing to topic (%s)", msgTopic)) } logger.Infof("[%v] dispatched error-on-apply message to %s receiver", g.errorMessagesCounter, common.ConsoleReceiver) msgTopic = common.GetPlatformClusterMessagingTopic(accountName, clusterName, common.ContainerRegistryReceiver, common.EventErrorOnApply) - if err := g.updatesProducer.Produce(ctx, types.ProduceMsg{Subject: msgTopic, Payload: msg}); err != nil { + if err := g.updatesProducer.Produce(ctx, types.ProduceMsg{Subject: msgTopic, Payload: b}); err != nil { return errors.Wrap(err, fmt.Sprintf("while producing to topic (%s)", msgTopic)) } logger.Infof("[%v] dispatched error-on-apply message to %s receiver", g.errorMessagesCounter, common.ContainerRegistryReceiver) @@ -286,19 +296,22 @@ func (g *grpcServer) processError(ctx context.Context, accountName string, clust func (g *grpcServer) GetAccessToken(ctx context.Context, msg *messages.GetAccessTokenIn) (*messages.GetAccessTokenOut, error) { g.logger.Infof("request received for cluster-token (%q) exchange", msg.ClusterToken) - ct, err := g.domain.GetClusterToken(ctx, msg.AccountName, msg.ClusterName) + ct, err := g.domain.FindClusterToken(ctx, msg.ClusterToken) if err != nil { return nil, klErrors.NewE(err) } - if ct != msg.ClusterToken { - return nil, errors.New("invalid cluster-token,account-name,cluster-name triplet") + if ct == nil { + return nil, errors.New("invalid cluster token") } - s := encodeAccessToken(msg.AccountName, msg.ClusterName, msg.ClusterToken, g.ev.TokenHashingSecret) - g.logger.Infof("SUCCESSFUL cluster-token exchange for account=%q, cluster=%q", msg.ClusterToken, msg.AccountName, msg.ClusterName) + s := encodeAccessToken(ct.AccountName, ct.ClusterName, msg.ClusterToken, g.ev.TokenHashingSecret) + g.logger.Infof("SUCCESSFUL cluster-token exchange for account=%q, cluster=%q", ct.AccountName, ct.ClusterName) return &messages.GetAccessTokenOut{ - AccessToken: s, + ProtocolVersion: g.ev.GrpcMessageProtocolVersion, + AccountName: ct.AccountName, + ClusterName: ct.ClusterName, + AccessToken: s, }, nil } @@ -351,10 +364,10 @@ func (g *grpcServer) SendActions(request *messages.Empty, server messages.Messag return nil } -func (g *grpcServer) processConsoleResourceUpdate(ctx context.Context, msg *messages.ResourceUpdate) (err error) { +func (g *grpcServer) processConsoleResourceUpdate(ctx context.Context, accountName string, clusterName string, msg *messages.ResourceUpdate) (err error) { g.resourceUpdatesCounter++ - logger := g.logger.WithKV("accountName", msg.AccountName).WithKV("clusterName", msg.ClusterName).WithKV("component", "console-resource-update") + logger := g.logger.WithKV("accountName", accountName).WithKV("clusterName", clusterName).WithKV("component", "console-resource-update") logger.Infof("[%v] received resource status update", g.resourceUpdatesCounter) defer func() { if err != nil { @@ -365,10 +378,19 @@ func (g *grpcServer) processConsoleResourceUpdate(ctx context.Context, msg *mess logger.Infof("[%v] processed resource status update", g.resourceUpdatesCounter) }() - msgTopic := common.GetPlatformClusterMessagingTopic(msg.AccountName, msg.ClusterName, common.ConsoleReceiver, common.EventResourceUpdate) + b, err := msgOfficeT.MarshalResourceUpdate(msgOfficeT.ResourceUpdate{ + AccountName: accountName, + ClusterName: clusterName, + WatcherUpdate: msg.Message, + }) + if err != nil { + return errors.Wrap(err, "marshalling resource update") + } + + msgTopic := common.GetPlatformClusterMessagingTopic(accountName, clusterName, common.ConsoleReceiver, common.EventResourceUpdate) if err := g.updatesProducer.Produce(ctx, types.ProduceMsg{ Subject: msgTopic, - Payload: msg.Message, + Payload: b, }); err != nil { return errors.Wrap(err, fmt.Sprintf("while producing resource update to topic %q", msgTopic)) } @@ -377,9 +399,9 @@ func (g *grpcServer) processConsoleResourceUpdate(ctx context.Context, msg *mess return nil } -func (g *grpcServer) processInfraResourceUpdate(ctx context.Context, msg *messages.ResourceUpdate) (err error) { +func (g *grpcServer) processInfraResourceUpdate(ctx context.Context, accountName string, clusterName string, msg *messages.ResourceUpdate) (err error) { g.infraUpdatesCounter++ - logger := g.logger.WithKV("accountName", msg.AccountName).WithKV("clusterName", msg.ClusterName).WithKV("component", "infra-resource-update") + logger := g.logger.WithKV("accountName", accountName).WithKV("clusterName", clusterName).WithKV("component", "infra-resource-update") logger.Infof("[%v] received infra update", g.infraUpdatesCounter) defer func() { @@ -391,10 +413,19 @@ func (g *grpcServer) processInfraResourceUpdate(ctx context.Context, msg *messag logger.Infof("[%v] processed infra update", g.infraUpdatesCounter) }() - msgTopic := common.GetPlatformClusterMessagingTopic(msg.AccountName, msg.ClusterName, common.InfraReceiver, common.EventResourceUpdate) + b, err := msgOfficeT.MarshalResourceUpdate(msgOfficeT.ResourceUpdate{ + AccountName: accountName, + ClusterName: clusterName, + WatcherUpdate: msg.Message, + }) + if err != nil { + return errors.Wrap(err, "while marshaling resource update") + } + + msgTopic := common.GetPlatformClusterMessagingTopic(accountName, clusterName, common.InfraReceiver, common.EventResourceUpdate) if err := g.updatesProducer.Produce(ctx, types.ProduceMsg{ Subject: msgTopic, - Payload: msg.Message, + Payload: b, }); err != nil { return errors.Wrap(err, fmt.Sprintf("while producing resource update to topic %q", msgTopic)) } @@ -403,9 +434,9 @@ func (g *grpcServer) processInfraResourceUpdate(ctx context.Context, msg *messag return nil } -func (g *grpcServer) processContainerRegistryResourceUpdate(ctx context.Context, msg *messages.ResourceUpdate) (err error) { +func (g *grpcServer) processContainerRegistryResourceUpdate(ctx context.Context, accountName string, clusterName string, msg *messages.ResourceUpdate) (err error) { g.crUpdatesCounter++ - logger := g.logger.WithKV("accountName", msg.AccountName).WithKV("clusterName", msg.ClusterName).WithKV("component", "container-registry-update") + logger := g.logger.WithKV("accountName", accountName).WithKV("clusterName", clusterName).WithKV("component", "container-registry-update") logger.Infof("[%v] received cr update", g.crUpdatesCounter) defer func() { @@ -417,10 +448,19 @@ func (g *grpcServer) processContainerRegistryResourceUpdate(ctx context.Context, logger.Infof("[%v] processed cr update", g.crUpdatesCounter) }() - msgTopic := common.GetPlatformClusterMessagingTopic(msg.AccountName, msg.ClusterName, common.ContainerRegistryReceiver, common.EventResourceUpdate) + b, err := msgOfficeT.MarshalResourceUpdate(msgOfficeT.ResourceUpdate{ + AccountName: accountName, + ClusterName: clusterName, + WatcherUpdate: msg.Message, + }) + if err != nil { + return errors.Wrap(err, "while marshaling resource update") + } + + msgTopic := common.GetPlatformClusterMessagingTopic(accountName, clusterName, common.ContainerRegistryReceiver, common.EventResourceUpdate) if err := g.updatesProducer.Produce(ctx, types.ProduceMsg{ Subject: msgTopic, - Payload: msg.Message, + Payload: b, }); err != nil { return errors.Wrap(err, fmt.Sprintf("while producing resource update to topic %q", msgTopic)) } diff --git a/apps/message-office/internal/app/vector-proxy-server.go b/apps/message-office/internal/app/vector-proxy-server.go index 254f4667f..1551781aa 100644 --- a/apps/message-office/internal/app/vector-proxy-server.go +++ b/apps/message-office/internal/app/vector-proxy-server.go @@ -2,6 +2,7 @@ package app import ( "context" + "github.com/kloudlite/api/pkg/errors" proto_rpc "github.com/kloudlite/api/apps/message-office/internal/app/proto-rpc" @@ -27,8 +28,8 @@ func (v *vectorProxyServer) PushEvents(ctx context.Context, msg *proto_rpc.PushE logger := v.logger.WithKV("accountName", accountName, "clusterName", clusterName) v.pushEventsCounter++ - logger.Infof("[%v] received push-events message", v.pushEventsCounter) - defer logger.Infof("[%v] dispatched push-events message to vector aggregator", v.pushEventsCounter) + logger.Debugf("[%v] received push-events message", v.pushEventsCounter) + defer logger.Debugf("[%v] dispatched push-events message to vector aggregator", v.pushEventsCounter) per, err := v.realVectorClient.PushEvents(ctx, msg) if err != nil { @@ -46,8 +47,8 @@ func (v *vectorProxyServer) HealthCheck(ctx context.Context, msg *proto_rpc.Heal logger := v.logger.WithKV("accountName", accountName, "clusterName", clusterName) v.healthCheckCounter++ - logger.Infof("[%v] received health-check message", v.healthCheckCounter) - defer logger.Infof("[%v] dispatched health-check message to vector aggregator", v.healthCheckCounter) + logger.Debugf("[%v] received health-check message", v.healthCheckCounter) + defer logger.Debugf("[%v] dispatched health-check message to vector aggregator", v.healthCheckCounter) hcr, err := v.realVectorClient.HealthCheck(ctx, msg) if err != nil { diff --git a/apps/message-office/internal/domain/api.go b/apps/message-office/internal/domain/api.go index be16adaff..493f90cb5 100644 --- a/apps/message-office/internal/domain/api.go +++ b/apps/message-office/internal/domain/api.go @@ -4,6 +4,7 @@ import "context" type Domain interface { GenClusterToken(ctx context.Context, accountName string, clusterName string) (string, error) + FindClusterToken(ctx context.Context, clusterToken string) (*MessageOfficeToken, error) GetClusterToken(ctx context.Context, accountName string, clusterName string) (string, error) GenAccessToken(ctx context.Context, clusterToken string) (*AccessToken, error) ValidateAccessToken(ctx context.Context, accessToken, accountName, clusterName string) error diff --git a/apps/message-office/internal/domain/domain.go b/apps/message-office/internal/domain/domain.go index b79865e89..83a4e0421 100644 --- a/apps/message-office/internal/domain/domain.go +++ b/apps/message-office/internal/domain/domain.go @@ -2,6 +2,7 @@ package domain import ( "context" + "github.com/kloudlite/api/pkg/errors" "go.uber.org/fx" @@ -49,6 +50,17 @@ func (d *domain) getClusterToken(ctx context.Context, accountName string, cluste return mot.Token, nil } +func (d *domain) FindClusterToken(ctx context.Context, clusterToken string) (*MessageOfficeToken, error) { + if clusterToken == "" { + return nil, errors.Newf("clusterToken cannot be empty") + } + mot, err := d.moRepo.FindOne(ctx, repos.Filter{"token": clusterToken}) + if err != nil { + return nil, errors.NewE(err) + } + return mot, nil +} + func (d *domain) GetClusterToken(ctx context.Context, accountName string, clusterName string) (string, error) { return d.getClusterToken(ctx, accountName, clusterName) } diff --git a/apps/message-office/internal/env/env.go b/apps/message-office/internal/env/env.go index 4d5c2e090..e7b37a51a 100644 --- a/apps/message-office/internal/env/env.go +++ b/apps/message-office/internal/env/env.go @@ -15,7 +15,10 @@ type Env struct { ExternalGrpcPort uint16 `env:"EXTERNAL_GRPC_PORT" required:"true"` InternalGrpcPort uint16 `env:"INTERNAL_GRPC_PORT" required:"true"` - HttpPort uint16 `env:"HTTP_PORT" required:"true"` + + GrpcMessageProtocolVersion string `env:"GRPC_MESSAGE_PROTOCOL_VERSION" default:"1"` + + HttpPort uint16 `env:"HTTP_PORT" required:"true"` VectorGrpcAddr string `env:"VECTOR_GRPC_ADDR" required:"true"` diff --git a/apps/message-office/main.go b/apps/message-office/main.go index f100dac17..5726f824b 100644 --- a/apps/message-office/main.go +++ b/apps/message-office/main.go @@ -21,7 +21,7 @@ func main() { flag.BoolVar(&isDev, "dev", false, "--dev") flag.Parse() - logger, err := logging.New(&logging.Options{Name: "message-office", Dev: true}) + logger, err := logging.New(&logging.Options{Name: "message-office", ShowDebugLog: isDev, ShowTime: true, HideCallerTrace: true}) if err != nil { panic(err) } diff --git a/apps/message-office/types/types.go b/apps/message-office/types/types.go new file mode 100644 index 000000000..68f68f519 --- /dev/null +++ b/apps/message-office/types/types.go @@ -0,0 +1,45 @@ +package types + +import ( + "github.com/shamaton/msgpack/v2" +) + +type ErrMessage struct { + AccountName string + ClusterName string + + // this must be unmarshalled into github.com/kloudlite/api/apps/tenant-agent/types.AgentErrMessage + Error []byte +} + +func MarshalErrMessage(ru ErrMessage) ([]byte, error) { + return msgpack.Marshal(ru) +} + +func UnmarshalErrMessage(b []byte) (ErrMessage, error) { + var errM ErrMessage + if err := msgpack.Unmarshal(b, &errM); err != nil { + return ErrMessage{}, err + } + return errM, nil +} + +type ResourceUpdate struct { + AccountName string + ClusterName string + + // this should be json unmarshalled into github.com/kloudlite/operator/operators/resource-watcher/types.ResourceUpdate + WatcherUpdate []byte +} + +func MarshalResourceUpdate(ru ResourceUpdate) ([]byte, error) { + return msgpack.Marshal(ru) +} + +func UnmarshalResourceUpdate(b []byte) (ResourceUpdate, error) { + var ru ResourceUpdate + if err := msgpack.Unmarshal(b, &ru); err != nil { + return ResourceUpdate{}, err + } + return ru, nil +} diff --git a/apps/tenant-agent/internal/env/env.go b/apps/tenant-agent/internal/env/env.go index 96ffae7ab..3209be49e 100644 --- a/apps/tenant-agent/internal/env/env.go +++ b/apps/tenant-agent/internal/env/env.go @@ -12,8 +12,7 @@ type Env struct { AccessTokenSecretName string `env:"ACCESS_TOKEN_SECRET_NAME" required:"true"` AccessTokenSecretNamespace string `env:"ACCESS_TOKEN_SECRET_NAMESPACE" required:"true"` - ClusterName string `env:"CLUSTER_NAME" required:"true"` - AccountName string `env:"ACCOUNT_NAME" required:"true"` + GrpcMessageProtocolVersion string `env:"GRPC_MESSAGE_PROTOCOL_VERSION" default:"1"` VectorProxyGrpcServerAddr string `env:"VECTOR_PROXY_GRPC_SERVER_ADDR" required:"true"` ResourceWatcherName string `env:"RESOURCE_WATCHER_NAME" required:"true"` diff --git a/apps/tenant-agent/main.go b/apps/tenant-agent/main.go index 6ea4882f8..6fc290b5a 100644 --- a/apps/tenant-agent/main.go +++ b/apps/tenant-agent/main.go @@ -10,12 +10,13 @@ import ( "time" "github.com/kloudlite/api/common" - "github.com/kloudlite/api/constants" "github.com/kloudlite/api/pkg/errors" "google.golang.org/grpc" + "google.golang.org/grpc/codes" "google.golang.org/grpc/connectivity" "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/client-go/rest" @@ -56,26 +57,28 @@ func (g *grpcHandler) handleErrorOnApply(ctx context.Context, err error, msg t.A } _, err = g.msgDispatchCli.ReceiveError(ctx, &messages.ErrorData{ - AccountName: msg.AccountName, - ClusterName: msg.ClusterName, - AccessToken: g.ev.AccessToken, - Message: b, + ProtocolVersion: g.ev.GrpcMessageProtocolVersion, + Message: b, }) return err } -func (g *grpcHandler) handleMessage(msg t.AgentMessage) error { +func NewAuthorizedGrpcContext(ctx context.Context, accessToken string) context.Context { + return metadata.NewOutgoingContext(ctx, metadata.Pairs("authorization", accessToken)) +} + +func (g *grpcHandler) handleMessage(gctx context.Context, msg t.AgentMessage) error { g.inMemCounter++ ctx, cf := func() (context.Context, context.CancelFunc) { if g.isDev { - return context.WithCancel(context.TODO()) + return context.WithCancel(gctx) } - return context.WithTimeout(context.TODO(), 3*time.Second) + return context.WithTimeout(gctx, 3*time.Second) }() defer cf() if msg.Object == nil { - g.logger.Infof("msg.Object is nil, could not process anything out of this kafka message, ignoring ...") + g.logger.Infof("msg.Object is nil, could not process anything out of this message, ignoring ...") return nil } @@ -96,8 +99,6 @@ func (g *grpcHandler) handleMessage(msg t.AgentMessage) error { ann = make(map[string]string, 2) } - ann[constants.ObservabilityAccountNameKey] = g.ev.AccountName - ann[constants.ObservabilityClusterNameKey] = g.ev.ClusterName obj.SetAnnotations(ann) b, err := yaml.Marshal(msg.Object) @@ -106,7 +107,6 @@ func (g *grpcHandler) handleMessage(msg t.AgentMessage) error { } if _, err := g.yamlClient.ApplyYAML(ctx, b); err != nil { - // mLogger.Infof("[%d] [error-on-apply]: %s", g.inMemCounter, err.Error()) mLogger.Errorf(err, "[%d] [error-on-apply]: yaml: \n%s\n", g.inMemCounter, b) mLogger.Infof("[%d] failed to process message", g.inMemCounter) return g.handleErrorOnApply(ctx, err, msg) @@ -152,20 +152,18 @@ func (g *grpcHandler) handleMessage(msg t.AgentMessage) error { } func (g *grpcHandler) ensureAccessToken() error { - ctx, cf := context.WithTimeout(context.TODO(), 50*time.Second) - defer cf() if g.ev.AccessToken == "" { g.logger.Infof("waiting on clusterToken exchange for accessToken") } + ctx := NewAuthorizedGrpcContext(context.TODO(), g.ev.AccessToken) + validationOut, err := g.msgDispatchCli.ValidateAccessToken(ctx, &messages.ValidateAccessTokenIn{ - AccountName: g.ev.AccountName, - ClusterName: g.ev.ClusterName, - AccessToken: g.ev.AccessToken, + ProtocolVersion: g.ev.GrpcMessageProtocolVersion, }) - - if err != nil || validationOut == nil || !validationOut.Valid { - g.logger.Infof("accessToken is invalid, requesting new accessToken ...") + if err != nil { + g.logger.Errorf(err, "validating access token") + validationOut = nil } if validationOut != nil && validationOut.Valid { @@ -173,10 +171,11 @@ func (g *grpcHandler) ensureAccessToken() error { return nil } + g.logger.Infof("accessToken is invalid, requesting new accessToken ...") + out, err := g.msgDispatchCli.GetAccessToken(ctx, &messages.GetAccessTokenIn{ - AccountName: g.ev.AccountName, - ClusterName: g.ev.ClusterName, - ClusterToken: g.ev.ClusterToken, + ProtocolVersion: g.ev.GrpcMessageProtocolVersion, + ClusterToken: g.ev.ClusterToken, }) if err != nil { return errors.NewE(err) @@ -193,6 +192,8 @@ func (g *grpcHandler) ensureAccessToken() error { s.Data = make(map[string][]byte, 1) } s.Data["ACCESS_TOKEN"] = []byte(out.AccessToken) + s.Data["ACCOUNT_NAME"] = []byte(out.AccountName) + s.Data["CLUSTER_NAME"] = []byte(out.ClusterName) _, err = g.yamlClient.Client().CoreV1().Secrets(g.ev.AccessTokenSecretNamespace).Update(context.TODO(), s, metav1.UpdateOptions{}) if err != nil { return errors.NewE(err) @@ -221,13 +222,10 @@ func (g *grpcHandler) ensureAccessToken() error { } func (g *grpcHandler) run() error { - ctx, cf := context.WithCancel(context.TODO()) - defer cf() - - outgoingCtx := metadata.NewOutgoingContext(ctx, metadata.Pairs("authorization", g.ev.AccessToken)) + ctx := NewAuthorizedGrpcContext(context.TODO(), g.ev.AccessToken) g.logger.Infof("asking message office to start sending actions") - msgActionsCli, err := g.msgDispatchCli.SendActions(outgoingCtx, &messages.Empty{}) + msgActionsCli, err := g.msgDispatchCli.SendActions(ctx, &messages.Empty{}) if err != nil { return errors.NewE(err) } @@ -241,6 +239,10 @@ func (g *grpcHandler) run() error { var msg t.AgentMessage a, err := msgActionsCli.Recv() if err != nil { + if status.Code(err) == codes.Unavailable { + g.logger.Infof("server unavailable, (may be, Gateway Timed Out 504), reconnecting ...") + return nil + } g.logger.Errorf(err, "[ERROR] while receiving message") return errors.NewE(err) } @@ -250,7 +252,7 @@ func (g *grpcHandler) run() error { return errors.NewE(err) } - if err := g.handleMessage(msg); err != nil { + if err := g.handleMessage(ctx, msg); err != nil { g.logger.Errorf(err, "[ERROR] while handling message") return errors.NewE(err) } @@ -292,8 +294,6 @@ func main() { realVectorClient: nil, logger: logger, accessToken: ev.AccessToken, - accountName: ev.AccountName, - clusterName: ev.ClusterName, } gs := libGrpc.NewGrpcServer(libGrpc.GrpcServerOpts{Logger: logger}) diff --git a/go.mod b/go.mod index f1b851662..3435525e9 100644 --- a/go.mod +++ b/go.mod @@ -42,11 +42,12 @@ require ( require ( github.com/kloudlite/container-registry-authorizer v0.0.0-20231021122509-161dc30fde55 - github.com/kloudlite/operator v1.0.4-0.20240520060449-53a58ea322db + github.com/kloudlite/operator v1.0.4-0.20240524130112-c32c133c28cc github.com/nats-io/nats.go v1.31.0 github.com/onsi/ginkgo/v2 v2.12.0 github.com/onsi/gomega v1.27.10 github.com/seancfoley/ipaddress-go v1.5.4 + github.com/shamaton/msgpack/v2 v2.2.0 github.com/stretchr/testify v1.9.0 github.com/ztrue/tracerr v0.4.0 golang.org/x/exp v0.0.0-20230905200255-921286631fa9 diff --git a/go.sum b/go.sum index a7625bf1b..acfd5b569 100644 --- a/go.sum +++ b/go.sum @@ -163,6 +163,8 @@ github.com/kloudlite/container-registry-authorizer v0.0.0-20231021122509-161dc30 github.com/kloudlite/container-registry-authorizer v0.0.0-20231021122509-161dc30fde55/go.mod h1:GZj3wZmIw/qCciclRhgQTgmGiqe8wxoVzMXQjbOfnbc= github.com/kloudlite/operator v1.0.4-0.20240520060449-53a58ea322db h1:uJlT4QTPZ5QxL61GebHUwu9HDjjcJb5+Xy57cg9yoso= github.com/kloudlite/operator v1.0.4-0.20240520060449-53a58ea322db/go.mod h1:CxZ24OQx30my/xzxOnjQLmUCcEvVhzAuYtGblRhXnhg= +github.com/kloudlite/operator v1.0.4-0.20240524130112-c32c133c28cc h1:/A6XGjylgXUyCPq0Yl7PlxOT62YOK46Lu7PHiRUwMqc= +github.com/kloudlite/operator v1.0.4-0.20240524130112-c32c133c28cc/go.mod h1:sz3ByFoE3ngJC+ai+BZLP5GAfoeLmgkyBLMEcWv7WcI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= @@ -256,6 +258,8 @@ github.com/sendgrid/sendgrid-go v3.11.1+incompatible h1:ai0+woZ3r/+tKLQExznak5Xe github.com/sendgrid/sendgrid-go v3.11.1+incompatible/go.mod h1:QRQt+LX/NmgVEvmdRw0VT/QgUn499+iza2FnDca9fg8= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= +github.com/shamaton/msgpack/v2 v2.2.0 h1:IP1m01pHwCrMa6ZccP9B3bqxEMKMSmMVAVKk54g3L/Y= +github.com/shamaton/msgpack/v2 v2.2.0/go.mod h1:6khjYnkx73f7VQU7wjcFS9DFjs+59naVWJv1TB7qdOI= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= diff --git a/pkg/logging/logger.go b/pkg/logging/logger.go index 52902be6e..67cc95681 100644 --- a/pkg/logging/logger.go +++ b/pkg/logging/logger.go @@ -49,9 +49,13 @@ func (c *logger) WithName(name string) Logger { } type Options struct { - Name string - Dev bool - CallerTrace bool + Name string + + Dev bool // deprecated + + ShowDebugLog bool + ShowTime bool + HideCallerTrace bool } var EmptyLogger *logger @@ -63,17 +67,19 @@ func New(options *Options) (Logger, error) { } cfg := func() zapcore.EncoderConfig { - if opts.Dev { - cfg := zap.NewDevelopmentEncoderConfig() - cfg.EncodeLevel = zapcore.CapitalColorLevelEncoder - cfg.LineEnding = "\n" - cfg.TimeKey = "" - - return cfg - } + // if opts.Dev { + // cfg := zap.NewDevelopmentEncoderConfig() + // cfg.EncodeLevel = zapcore.CapitalColorLevelEncoder + // cfg.LineEnding = "\n" + // cfg.TimeKey = "" + // + // return cfg + // } pcfg := zap.NewProductionEncoderConfig() pcfg.EncodeLevel = zapcore.CapitalColorLevelEncoder - pcfg.TimeKey = "" + if !opts.ShowTime { + pcfg.TimeKey = "" + } pcfg.LineEnding = "\n" return pcfg }() @@ -85,18 +91,14 @@ func New(options *Options) (Logger, error) { // } loglevel := zapcore.InfoLevel - if opts.Dev { + if opts.ShowDebugLog { loglevel = zapcore.DebugLevel } zapOpts := make([]zap.Option, 0, 3) zapOpts = append(zapOpts, zap.AddStacktrace(zap.DPanicLevel)) - if !opts.Dev { - opts.CallerTrace = true - } - - if opts.CallerTrace { + if !opts.HideCallerTrace { zapOpts = append(zapOpts, zap.AddCaller(), zap.AddCallerSkip(1)) } diff --git a/pkg/repos/db-repo-mongo.go b/pkg/repos/db-repo-mongo.go index 372df73d5..ef2a0b0fc 100644 --- a/pkg/repos/db-repo-mongo.go +++ b/pkg/repos/db-repo-mongo.go @@ -653,7 +653,7 @@ func (repo *dbRepo[T]) MergeMatchFilters(filter Filter, matchFilters ...map[stri filter[k] = bson.M{"$regex": primitive.Regex{Pattern: *v.Regex, Options: "i"}} default: { - fmt.Printf("[WARN, repo, mongo]: unknown match type: %q, supported ones: %+v\n", v.MatchType, []string{MatchTypeExact, MatchTypeArray, MatchTypeNotInArray, MatchTypeRegex}) + fmt.Printf("[WARN, repo, mongo]: unknown match type: %q, supported ones: %+v\n", v.MatchType, []MatchType{MatchTypeExact, MatchTypeArray, MatchTypeNotInArray, MatchTypeRegex}) } } } diff --git a/pkg/repos/db-repo.go b/pkg/repos/db-repo.go index 1b238cad6..2a45911ee 100644 --- a/pkg/repos/db-repo.go +++ b/pkg/repos/db-repo.go @@ -45,14 +45,13 @@ type Query struct { type MatchType string const ( - MatchTypeExact = "exact" - MatchTypeArray = "array" - MatchTypeNotInArray = "not-in-array" - MatchTypeRegex = "regex" + MatchTypeExact MatchType = "exact" + MatchTypeArray MatchType = "array" + MatchTypeNotInArray MatchType = "not_in_array" + MatchTypeRegex MatchType = "regex" ) type MatchFilter struct { - // MatchType MatchType `json:"matchType" graphql:"enum=exact;array;regex;"` MatchType MatchType `json:"matchType"` Exact any `json:"exact,omitempty"` Array []any `json:"array,omitempty"`