diff --git a/Gopkg.toml b/Gopkg.toml index a39a28a3d..3262f0759 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -17,6 +17,10 @@ required = ["k8s.io/code-generator/cmd/client-gen"] name = "k8s.io/gengo" unused-packages = false +[[override]] + name = "gopkg.in/fsnotify.v1" + source = "https://github.com/fsnotify/fsnotify.git" + [[constraint]] version = "1.1.1" name = "github.com/gogo/protobuf" diff --git a/api/external/kubernetes/solo-kit.json b/api/external/kubernetes/solo-kit.json index 91719e43f..3126bd5f8 100644 --- a/api/external/kubernetes/solo-kit.json +++ b/api/external/kubernetes/solo-kit.json @@ -1,44 +1,51 @@ { "title": "solo-kit", - "name": "kubernetes.solo.io", - "version": "kubernetes", - "go_package": "github.com/solo-io/solo-kit/pkg/api/v1/resources/common/kubernetes", - "custom_resources": [ - { - "package": "github.com/solo-io/solo-kit/api/external/kubernetes/pod", - "type": "Pod", - "plural_name": "pods", - "short_name": "p" - }, - { - "package": "github.com/solo-io/solo-kit/api/external/kubernetes/namespace", - "type": "KubeNamespace", - "plural_name": "kubenamespaces", - "short_name": "kn" - }, - { - "package": "github.com/solo-io/solo-kit/api/external/kubernetes/configmap", - "type": "ConfigMap", - "plural_name": "configmaps", - "short_name": "cm" - }, - { - "package": "github.com/solo-io/solo-kit/api/external/kubernetes/service", - "type": "Service", - "plural_name": "services", - "short_name": "svc" - }, - { - "package": "github.com/solo-io/solo-kit/api/external/kubernetes/deployment", - "type": "Deployment", - "plural_name": "deployments", - "short_name": "dp " - }, - { - "package": "github.com/solo-io/solo-kit/api/external/kubernetes/customresourcedefinition", - "type": "CustomResourceDefinition", - "plural_name": "customresourcedefinition", - "short_name": "crd " - } - ] + "api_group": { + "name": "kubernetes.solo.io", + "resource_group_go_package": "github.com/solo-io/solo-kit/api/external/kubernetes/group", + "version_configs": [ + { + "version": "kubernetes", + "go_package": "github.com/solo-io/solo-kit/pkg/api/v1/resources/common/kubernetes", + "custom_resources": [ + { + "package": "github.com/solo-io/solo-kit/api/external/kubernetes/pod", + "type": "Pod", + "plural_name": "pods", + "short_name": "p" + }, + { + "package": "github.com/solo-io/solo-kit/api/external/kubernetes/namespace", + "type": "KubeNamespace", + "plural_name": "kubenamespaces", + "short_name": "kn" + }, + { + "package": "github.com/solo-io/solo-kit/api/external/kubernetes/configmap", + "type": "ConfigMap", + "plural_name": "configmaps", + "short_name": "cm" + }, + { + "package": "github.com/solo-io/solo-kit/api/external/kubernetes/service", + "type": "Service", + "plural_name": "services", + "short_name": "svc" + }, + { + "package": "github.com/solo-io/solo-kit/api/external/kubernetes/deployment", + "type": "Deployment", + "plural_name": "deployments", + "short_name": "dp " + }, + { + "package": "github.com/solo-io/solo-kit/api/external/kubernetes/customresourcedefinition", + "type": "CustomResourceDefinition", + "plural_name": "customresourcedefinition", + "short_name": "crd " + } + ] + } + ] + } } \ No newline at end of file diff --git a/api/multicluster/v1/solo-kit.json b/api/multicluster/v1/solo-kit.json index 949f25074..e1be679f4 100644 --- a/api/multicluster/v1/solo-kit.json +++ b/api/multicluster/v1/solo-kit.json @@ -1,21 +1,28 @@ { "title": "Solo-Kit Multicluster Manager", - "name": "multicluster.solo.io", - "version": "v1", - "go_package": "github.com/solo-io/solo-kit/pkg/multicluster/v1", - "custom_resources": [ - { - "package": "github.com/solo-io/solo-kit/api/multicluster/v1", - "type": "KubeConfig", - "plural_name": "kubeconfigs", - "short_name": "kc" - } - ], - "resource_groups": { - "kubeconfigs.multicluster.solo.io": [ + "api_group": { + "name": "multicluster.solo.io", + "resource_group_go_package": "github.com/solo-io/solo-kit/pkg/multicluster/group", + "resource_groups": { + "kubeconfigs.multicluster.solo.io": [ + { + "name": "KubeConfig", + "package": "github.com/solo-io/solo-kit/api/multicluster/v1" + } + ] + }, + "version_configs": [ { - "name": "KubeConfig", - "package": "github.com/solo-io/solo-kit/api/multicluster/v1" + "version": "v1", + "go_package": "github.com/solo-io/solo-kit/pkg/multicluster/v1", + "custom_resources": [ + { + "package": "github.com/solo-io/solo-kit/api/multicluster/v1", + "type": "KubeConfig", + "plural_name": "kubeconfigs", + "short_name": "kc" + } + ] } ] } diff --git a/changelog/v0.12.0/conversions.yaml b/changelog/v0.12.0/conversions.yaml new file mode 100644 index 000000000..4e9788768 --- /dev/null +++ b/changelog/v0.12.0/conversions.yaml @@ -0,0 +1,7 @@ +changelog: + - type: NEW_FEATURE + description: Generate converters for multi-version resources. + issueLink: https://github.com/solo-io/solo-kit/issues/215 + - type: BREAKING_CHANGE + description: Redefine solo-kit project concept to better support multi-version resources. + issueLink: https://github.com/solo-io/solo-kit/issues/215 \ No newline at end of file diff --git a/pkg/api/v1/clients/kube/crd/crd.go b/pkg/api/v1/clients/kube/crd/crd.go index 83911a5c3..d113758a1 100644 --- a/pkg/api/v1/clients/kube/crd/crd.go +++ b/pkg/api/v1/clients/kube/crd/crd.go @@ -1,14 +1,13 @@ package crd import ( - "fmt" "log" "sync" + "github.com/solo-io/go-utils/errors" "github.com/solo-io/solo-kit/pkg/api/v1/clients/kube/crd/client/clientset/versioned/scheme" v1 "github.com/solo-io/solo-kit/pkg/api/v1/clients/kube/crd/solo.io/v1" "github.com/solo-io/solo-kit/pkg/api/v1/resources" - "github.com/solo-io/solo-kit/pkg/utils/protoutils" apiexts "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" @@ -16,7 +15,22 @@ import ( ) // TODO(ilackarms): evaluate this fix for concurrent map access in k8s.io/apimachinery/pkg/runtime.SchemaBuider -var registerLock sync.Mutex +var ( + registerLock sync.Mutex + + VersionNotFoundError = func(version string) error { + return errors.Errorf("could not find version %v", version) + } +) + +type Converter interface { + Convert(src SoloKitCrd, dst SoloKitCrd) error +} + +type SoloKitCrd interface { + runtime.Object + resources.Resource +} type CrdMeta struct { Plural string @@ -28,7 +42,7 @@ type CrdMeta struct { type Version struct { Version string - Type runtime.Object + Type SoloKitCrd } type Crd struct { @@ -41,6 +55,15 @@ type MultiVersionCrd struct { Versions []Version } +func (m *MultiVersionCrd) GetVersion(requested string) (*Version, error) { + for _, version := range m.Versions { + if version.Version == requested { + return &version, nil + } + } + return nil, VersionNotFoundError(requested) +} + func NewCrd( plural string, group string, @@ -48,7 +71,7 @@ func NewCrd( kindName string, shortName string, clusterScoped bool, - objType runtime.Object) Crd { + objType SoloKitCrd) Crd { c := Crd{ CrdMeta: CrdMeta{ Plural: plural, @@ -73,25 +96,9 @@ func (d Crd) Register(apiexts apiexts.Interface) error { } func (d Crd) KubeResource(resource resources.InputResource) *v1.Resource { - data, err := protoutils.MarshalMap(resource) - if err != nil { - panic(fmt.Sprintf("internal error: failed to marshal resource to map: %v", err)) - } - delete(data, "metadata") - delete(data, "status") - spec := v1.Spec(data) - return &v1.Resource{ - TypeMeta: d.TypeMeta(), - ObjectMeta: metav1.ObjectMeta{ - Namespace: resource.GetMetadata().Namespace, - Name: resource.GetMetadata().Name, - ResourceVersion: resource.GetMetadata().ResourceVersion, - Labels: resource.GetMetadata().Labels, - Annotations: resource.GetMetadata().Annotations, - }, - Status: resource.GetStatus(), - Spec: &spec, - } + res := KubeResource(resource) + res.TypeMeta = d.TypeMeta() + return res } func (d CrdMeta) FullName() string { diff --git a/pkg/api/v1/clients/kube/crd/registry.go b/pkg/api/v1/clients/kube/crd/registry.go index abacbe8f5..bfdb6d5fc 100644 --- a/pkg/api/v1/clients/kube/crd/registry.go +++ b/pkg/api/v1/clients/kube/crd/registry.go @@ -8,6 +8,9 @@ import ( "github.com/solo-io/go-utils/errors" "github.com/solo-io/go-utils/kubeutils" "github.com/solo-io/go-utils/versionutils/kubeapi" + v1 "github.com/solo-io/solo-kit/pkg/api/v1/clients/kube/crd/solo.io/v1" + "github.com/solo-io/solo-kit/pkg/api/v1/resources" + "github.com/solo-io/solo-kit/pkg/utils/protoutils" "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1" apiexts "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset" apierrors "k8s.io/apimachinery/pkg/api/errors" @@ -48,6 +51,10 @@ func AddCrd(resource Crd) error { return getRegistry().addCrd(resource) } +func GetMultiVersionCrd(gk schema.GroupKind) (MultiVersionCrd, error) { + return getRegistry().getMultiVersionCrd(gk) +} + func (r *crdRegistry) addCrd(resource Crd) error { r.mu.Lock() defer r.mu.Unlock() @@ -167,3 +174,29 @@ func (r crdRegistry) getKubeCrd(crd MultiVersionCrd, gvk schema.GroupVersionKind }, }, nil } + +func KubeResource(resource resources.Resource) *v1.Resource { + data, err := protoutils.MarshalMap(resource) + if err != nil { + panic(fmt.Sprintf("internal error: failed to marshal resource to map: %v", err)) + } + delete(data, "metadata") + delete(data, "status") + spec := v1.Spec(data) + res := &v1.Resource{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: resource.GetMetadata().Namespace, + Name: resource.GetMetadata().Name, + ResourceVersion: resource.GetMetadata().ResourceVersion, + Labels: resource.GetMetadata().Labels, + Annotations: resource.GetMetadata().Annotations, + }, + Spec: &spec, + } + + if withStatus, ok := resource.(resources.InputResource); ok { + res.Status = withStatus.GetStatus() + } + + return res +} diff --git a/pkg/api/v1/clients/kube/crd/util.go b/pkg/api/v1/clients/kube/crd/util.go new file mode 100644 index 000000000..b4f2b8580 --- /dev/null +++ b/pkg/api/v1/clients/kube/crd/util.go @@ -0,0 +1,17 @@ +package crd + +import ( + "github.com/solo-io/solo-kit/pkg/utils/protoutils" +) + +func Copy(src, dst SoloKitCrd) error { + srcBytes, err := protoutils.MarshalBytes(src) + if err != nil { + return err + } + err = protoutils.UnmarshalBytes(srcBytes, dst) + if err != nil { + return err + } + return nil +} diff --git a/pkg/api/v1/resources/common/kubernetes/kubernetes.solo.io_suite_test.go b/pkg/api/v1/resources/common/kubernetes/kubernetes.solo.io_suite_test.go index 034e96974..3cc5d16d6 100644 --- a/pkg/api/v1/resources/common/kubernetes/kubernetes.solo.io_suite_test.go +++ b/pkg/api/v1/resources/common/kubernetes/kubernetes.solo.io_suite_test.go @@ -36,13 +36,13 @@ var ( Expect(err).NotTo(HaveOccurred()) clientset, err := apiexts.NewForConfig(cfg) Expect(err).NotTo(HaveOccurred()) - err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("anothermockresources.testing.solo.io", &metav1.DeleteOptions{}) - testutils.ErrorNotOccuredOrNotFound(err) - err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("clusterresources.testing.solo.io", &metav1.DeleteOptions{}) + err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("mocks.testing.solo.io", &metav1.DeleteOptions{}) testutils.ErrorNotOccuredOrNotFound(err) err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("fakes.testing.solo.io", &metav1.DeleteOptions{}) testutils.ErrorNotOccuredOrNotFound(err) - err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("mocks.testing.solo.io", &metav1.DeleteOptions{}) + err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("anothermockresources.testing.solo.io", &metav1.DeleteOptions{}) + testutils.ErrorNotOccuredOrNotFound(err) + err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("clusterresources.testing.solo.io", &metav1.DeleteOptions{}) testutils.ErrorNotOccuredOrNotFound(err) Expect(lock.ReleaseLock()).NotTo(HaveOccurred()) }) diff --git a/pkg/code-generator/cmd/main.go b/pkg/code-generator/cmd/main.go index 3ef86c8a7..3065bd777 100644 --- a/pkg/code-generator/cmd/main.go +++ b/pkg/code-generator/cmd/main.go @@ -1,7 +1,6 @@ package cmd import ( - "encoding/json" "fmt" "io/ioutil" "os" @@ -76,17 +75,17 @@ func Generate(opts GenerateOptions) error { return err } - // Creates a ProjectConfig from each of the 'solo-kit.json' files + // Creates a SoloKitProject from each of the 'solo-kit.json' files // found in the directory tree rooted at 'absoluteRoot'. - projectConfigs, err := collectProjectsFromRoot(absoluteRoot, skipDirs) + soloKitProjects, err := collectProjectsFromRoot(absoluteRoot, skipDirs) if err != nil { return err } log.Printf("collected projects: %v", func() []string { var names []string - for _, project := range projectConfigs { - names = append(names, project.Name) + for _, skp := range soloKitProjects { + names = append(names, skp.Title) } sort.Strings(names) return names @@ -97,9 +96,11 @@ func Generate(opts GenerateOptions) error { if !compileProtos { return false } - for _, proj := range projectConfigs { - if strings.HasPrefix(protoFile, filepath.Dir(proj.ProjectFile)) { - return true + for _, skp := range soloKitProjects { + for _, vc := range skp.ApiGroup.VersionConfigs { + if strings.HasPrefix(protoFile, filepath.Dir(skp.ProjectFile)+"/"+vc.Version) { + return true + } } } return false @@ -122,79 +123,124 @@ func Generate(opts GenerateOptions) error { }()) var protoDescriptors []*descriptor.FileDescriptorProto - for _, projectConfig := range projectConfigs { - importedResources, err := importCustomResources(projectConfig.Imports) + for _, skp := range soloKitProjects { + importedResources, err := importCustomResources(skp.ApiGroup.Imports) if err != nil { return err } - - projectConfig.CustomResources = append(projectConfig.CustomResources, importedResources...) - - for _, desc := range descriptors { - if filepath.Dir(desc.ProtoFilePath) == filepath.Dir(projectConfig.ProjectFile) { - projectConfig.ProjectProtos = append(projectConfig.ProjectProtos, desc.GetName()) + for _, vc := range skp.ApiGroup.VersionConfigs { + vc.CustomResources = append(vc.CustomResources, importedResources...) + for _, desc := range descriptors { + if filepath.Dir(desc.ProtoFilePath) == filepath.Dir(skp.ProjectFile)+"/"+vc.Version { + vc.VersionProtos = append(vc.VersionProtos, desc.GetName()) + } + protoDescriptors = append(protoDescriptors, desc.FileDescriptorProto) } - protoDescriptors = append(protoDescriptors, desc.FileDescriptorProto) } } - for _, projectConfig := range projectConfigs { + // Accumulate all resources in order to handle cross-project dependencies + var allResources []*model.Resource + for _, skp := range soloKitProjects { + skp.ApiGroup.SoloKitProject = skp + for _, vc := range skp.ApiGroup.VersionConfigs { + vc.ApiGroup = skp.ApiGroup + version, err := parser.ProcessDescriptors(vc, skp.ApiGroup, protoDescriptors) + if err != nil { + return err + } + allResources = append(allResources, version.Resources...) + } + } - // Build a 'Project' object that contains a resource for each message that: - // - is contained in the FileDescriptor and - // - is a solo kit resource (i.e. it has a field named 'metadata') + for _, skp := range soloKitProjects { + // Store all versions on each api group for conversion generation. + var apiGroupVersions []*model.Version + for _, vc := range skp.ApiGroup.VersionConfigs { + vc.ApiGroup = skp.ApiGroup - project, err := parser.ProcessDescriptors(projectConfig, projectConfigs, protoDescriptors) - if err != nil { - return err - } + // Build a 'Version' object that contains a resource for each message that: + // - is contained in the FileDescriptor and + // - is a solo kit resource (i.e. it has a field named 'metadata') - code, err := codegen.GenerateFiles(project, true, opts.SkipGeneratedTests) - if err != nil { - return err - } + version, err := parser.ProcessDescriptors(vc, skp.ApiGroup, protoDescriptors) + if err != nil { + return err + } + apiGroupVersions = append(apiGroupVersions, version) - if project.ProjectConfig.DocsDir != "" && (genDocs != nil) { - docs, err := docgen.GenerateFiles(project, genDocs) + code, err := codegen.GenerateProjectFiles(version, true, opts.SkipGeneratedTests) if err != nil { return err } - for _, file := range docs { - path := filepath.Join(absoluteRoot, project.ProjectConfig.DocsDir, file.Filename) - if err := os.MkdirAll(filepath.Dir(path), 0777); err != nil { + outDir := filepath.Join(gopathSrc(), version.VersionConfig.GoPackage) + if err := writeCodeFiles(code, outDir); err != nil { + return err + } + + if skp.ApiGroup.DocsDir != "" && (genDocs != nil) { + docs, err := docgen.GenerateFiles(version, genDocs) + if err != nil { return err } - if err := ioutil.WriteFile(path, []byte(file.Content), 0644); err != nil { + + for _, file := range docs { + path := filepath.Join(absoluteRoot, skp.ApiGroup.DocsDir, file.Filename) + if err := os.MkdirAll(filepath.Dir(path), 0777); err != nil { + return err + } + if err := ioutil.WriteFile(path, []byte(file.Content), 0644); err != nil { + return err + } + } + } + + // Generate mocks + // need to run after to make sure all resources have already been written + // Set this env var during tests so that mocks are not generated + if !opts.SkipGenMocks { + if err := genMocks(code, outDir, absoluteRoot); err != nil { return err } } } - outDir := filepath.Join(gopathSrc(), project.ProjectConfig.GoPackage) - - for _, file := range code { - path := filepath.Join(outDir, file.Filename) - if err := os.MkdirAll(filepath.Dir(path), 0777); err != nil { + if skp.ApiGroup.ResourceGroupGoPackage != "" { + skp.ApiGroup.ResourceGroupsFoo, err = parser.GetResourceGroups(skp.ApiGroup, allResources) + if err != nil { return err } - if err := ioutil.WriteFile(path, []byte(file.Content), 0644); err != nil { + + code, err := codegen.GenerateResourceGroupFiles(skp.ApiGroup, false, opts.SkipGeneratedTests) + if err != nil { return err } - if out, err := exec.Command("gofmt", "-w", path).CombinedOutput(); err != nil { - return errors.Wrapf(err, "gofmt failed: %s", out) + + outDir := filepath.Join(gopathSrc(), skp.ApiGroup.ResourceGroupGoPackage) + if err := writeCodeFiles(code, outDir); err != nil { + return err } - if out, err := exec.Command("goimports", "-w", path).CombinedOutput(); err != nil { - return errors.Wrapf(err, "goimports failed: %s", out) + // Generate mocks + // need to run after to make sure all resources have already been written + // Set this env var during tests so that mocks are not generated + if !opts.SkipGenMocks { + if err := genMocks(code, outDir, absoluteRoot); err != nil { + return err + } } } - // Generate mocks - // need to run after to make sure all resources have already been written - // Set this env var during tests so that mocks are not generated - if !opts.SkipGenMocks { - if err := genMocks(code, outDir, absoluteRoot); err != nil { + if skp.ApiGroup.ConversionGoPackage != "" { + skp.ApiGroup.ConversionGoPackageShort = filepath.Base(skp.ApiGroup.ConversionGoPackage) + code, err := codegen.GenerateConversionFiles(skp.ApiGroup, apiGroupVersions) + if err != nil { + return err + } + + outDir := filepath.Join(gopathSrc(), skp.ApiGroup.ConversionGoPackage) + if err := writeCodeFiles(code, outDir); err != nil { return err } } @@ -254,8 +300,8 @@ func gopathSrc() string { return filepath.Join(os.Getenv("GOPATH"), "src") } -func collectProjectsFromRoot(root string, skipDirs []string) ([]*model.ProjectConfig, error) { - var projects []*model.ProjectConfig +func collectProjectsFromRoot(root string, skipDirs []string) ([]*model.SoloKitProject, error) { + var soloKitProjects []*model.SoloKitProject if err := filepath.Walk(root, func(projectFile string, info os.FileInfo, err error) error { if err != nil { @@ -279,12 +325,13 @@ func collectProjectsFromRoot(root string, skipDirs []string) ([]*model.ProjectCo if err != nil { return err } - projects = append(projects, &project) + + soloKitProjects = append(soloKitProjects, &project) return nil }); err != nil { return nil, err } - return projects, nil + return soloKitProjects, nil } func addDescriptorsForFile(addDescriptor func(f DescriptorWithPath), root, protoFile string, customImports, customGogoArgs []string, wantCompile func(string) bool) error { @@ -535,23 +582,40 @@ func importCustomResources(imports []string) ([]model.CustomResourceConfig, erro if !strings.HasSuffix(imp, model.ProjectConfigFilename) { imp = filepath.Join(imp, model.ProjectConfigFilename) } - byt, err := ioutil.ReadFile(imp) - if err != nil { - return nil, err - } - var projectConfig model.ProjectConfig - err = json.Unmarshal(byt, &projectConfig) + soloKitProject, err := model.LoadProjectConfig(imp) if err != nil { return nil, err } - var customResources []model.CustomResourceConfig - for _, v := range projectConfig.CustomResources { - v.Package = projectConfig.GoPackage - v.Imported = true - customResources = append(customResources, v) + for _, vc := range soloKitProject.ApiGroup.VersionConfigs { + var customResources []model.CustomResourceConfig + for _, cr := range vc.CustomResources { + cr.Package = vc.GoPackage + cr.Imported = true + customResources = append(customResources, cr) + } + results = append(results, customResources...) } - results = append(results, customResources...) } return results, nil } + +func writeCodeFiles(code code_generator.Files, outDir string) error { + for _, file := range code { + path := filepath.Join(outDir, file.Filename) + if err := os.MkdirAll(filepath.Dir(path), 0777); err != nil { + return err + } + if err := ioutil.WriteFile(path, []byte(file.Content), 0644); err != nil { + return err + } + if out, err := exec.Command("gofmt", "-w", path).CombinedOutput(); err != nil { + return errors.Wrapf(err, "gofmt failed: %s", out) + } + + if out, err := exec.Command("goimports", "-w", path).CombinedOutput(); err != nil { + return errors.Wrapf(err, "goimports failed: %s", out) + } + } + return nil +} diff --git a/pkg/code-generator/codegen/conversion.go b/pkg/code-generator/codegen/conversion.go new file mode 100644 index 000000000..218cc8ede --- /dev/null +++ b/pkg/code-generator/codegen/conversion.go @@ -0,0 +1,165 @@ +package codegen + +import ( + "bytes" + "sort" + "text/template" + + "github.com/solo-io/go-utils/versionutils/kubeapi" + "github.com/solo-io/solo-kit/pkg/errors" + + "github.com/solo-io/go-utils/log" + code_generator "github.com/solo-io/solo-kit/pkg/code-generator" + "github.com/solo-io/solo-kit/pkg/code-generator/codegen/templates" + "github.com/solo-io/solo-kit/pkg/code-generator/model" +) + +func GenerateConversionFiles(soloKitProject *model.ApiGroup, versions []*model.Version) (code_generator.Files, error) { + var files code_generator.Files + + sort.SliceStable(versions, func(i, j int) bool { + vi, err := kubeapi.ParseVersion(versions[i].VersionConfig.Version) + if err != nil { + return false + } + vj, err := kubeapi.ParseVersion(versions[j].VersionConfig.Version) + if err != nil { + return false + } + return vi.LessThan(vj) + }) + + resourceNameToVersions := make(map[string][]*model.Version) + + for i, v := range versions { + for _, res := range v.Resources { + // only generate files for the resources in our group, otherwise we import + if !v.VersionConfig.IsOurProto(res.Filename) && !res.IsCustom { + log.Printf("not generating solo-kit "+ + "converters for resource %v.%v, "+ + "resource proto package must match v proto package %v", res.ProtoPackage, res.Name, v.ProtoPackage) + continue + } else if res.IsCustom && res.CustomResource.Imported { + log.Printf("not generating solo-kit "+ + "converters for resource %v.%v, "+ + "custom resources from a different v are not generated", res.GoPackage, res.Name, v.VersionConfig.GoPackage) + continue + } + + if _, found := resourceNameToVersions[res.Name]; !found { + resourceNameToVersions[res.Name] = make([]*model.Version, 0, len(versions)-i) + } + resourceNameToVersions[res.Name] = append(resourceNameToVersions[res.Name], v) + } + } + + soloKitProject.Conversions = getConversionsFromResourceProjects(resourceNameToVersions) + + fs, err := generateFilesForConversionConfig(soloKitProject) + if err != nil { + return nil, err + } + files = append(files, fs...) + + for i := range files { + files[i].Content = fileHeader + files[i].Content + } + + return files, nil +} + +func getConversionsFromResourceProjects(resNameToProjects map[string][]*model.Version) []*model.Conversion { + conversions := make([]*model.Conversion, 0, len(resNameToProjects)) + for resName, projects := range resNameToProjects { + if len(projects) < 2 { + continue + } + conversion := &model.Conversion{ + Name: resName, + Projects: getConversionProjects(projects), + } + conversions = append(conversions, conversion) + } + + // Sort conversions by name so reordering diffs aren't introduced to the conversion files + sort.SliceStable(conversions, func(i, j int) bool { return conversions[i].Name < conversions[j].Name }) + + return conversions +} + +func generateFilesForConversionConfig(soloKitProject *model.ApiGroup) (code_generator.Files, error) { + var v code_generator.Files + for name, tmpl := range map[string]*template.Template{ + "resource_converter.sk.go": templates.ConverterTemplate, + "resource_converter_test.go": templates.ConverterTestTemplate, + } { + content, err := generateConversionFile(soloKitProject, tmpl) + if err != nil { + return nil, errors.Wrapf(err, "internal error: processing template '%v' for resource list %v failed", tmpl.ParseName, name) + } + v = append(v, code_generator.File{ + Filename: name, + Content: content, + }) + } + + testSuite := &model.TestSuite{ + PackageName: soloKitProject.ConversionGoPackageShort, + } + for suffix, tmpl := range map[string]*template.Template{ + "_suite_test.go": templates.SimpleTestSuiteTemplate, + } { + name := testSuite.PackageName + suffix + content, err := generateTestSuiteFile(testSuite, tmpl) + if err != nil { + return nil, errors.Wrapf(err, "internal error: processing template '%v' for resource list %v failed", tmpl.ParseName, name) + } + v = append(v, code_generator.File{ + Filename: name, + Content: content, + }) + } + + return v, nil +} + +func generateConversionFile(soloKitProject *model.ApiGroup, tmpl *template.Template) (string, error) { + buf := &bytes.Buffer{} + if err := tmpl.Execute(buf, soloKitProject); err != nil { + return "", err + } + return buf.String(), nil +} + +func generateTestSuiteFile(suite *model.TestSuite, tmpl *template.Template) (string, error) { + buf := &bytes.Buffer{} + if err := tmpl.Execute(buf, suite); err != nil { + return "", err + } + return buf.String(), nil +} + +func getConversionProjects(projects []*model.Version) []*model.ConversionProject { + conversionProjects := make([]*model.ConversionProject, 0, len(projects)) + for index := range projects { + conversionProjects = append(conversionProjects, getConversionProject(index, projects)) + } + return conversionProjects +} + +func getConversionProject(index int, projects []*model.Version) *model.ConversionProject { + var nextVersion, previousVersion string + if index < len(projects)-1 { + nextVersion = projects[index+1].VersionConfig.Version + } + if index > 0 { + previousVersion = projects[index-1].VersionConfig.Version + } + + return &model.ConversionProject{ + Version: projects[index].VersionConfig.Version, + GoPackage: projects[index].VersionConfig.GoPackage, + NextVersion: nextVersion, + PreviousVersion: previousVersion, + } +} diff --git a/pkg/code-generator/codegen/generator.go b/pkg/code-generator/codegen/project.go similarity index 57% rename from pkg/code-generator/codegen/generator.go rename to pkg/code-generator/codegen/project.go index 01b572aba..a05fe9154 100644 --- a/pkg/code-generator/codegen/generator.go +++ b/pkg/code-generator/codegen/project.go @@ -18,22 +18,23 @@ const fileHeader = `// Code generated by solo-kit. DO NOT EDIT. ` -func GenerateFiles(project *model.Project, skipOutOfPackageFiles, skipGeneratedTests bool) (code_generator.Files, error) { - files, err := generateFilesForProject(project) +func GenerateProjectFiles(version *model.Version, skipOutOfPackageFiles, skipGeneratedTests bool) (code_generator.Files, error) { + files, err := generateFilesForVersion(version) if err != nil { return nil, err } - for _, res := range project.Resources { + + for _, res := range version.Resources { // only generate files for the resources in our group, otherwise we import - if !project.ProjectConfig.IsOurProto(res.Filename) && !res.IsCustom { + if !version.VersionConfig.IsOurProto(res.Filename) && !res.IsCustom { log.Printf("not generating solo-kit "+ "clients for resource %v.%v, "+ - "resource proto package must match project proto package %v", res.ProtoPackage, res.Name, project.ProtoPackage) + "resource proto package must match version proto package %v", res.ProtoPackage, res.Name, version.ProtoPackage) continue } else if res.IsCustom && res.CustomResource.Imported { log.Printf("not generating solo-kit "+ "clients for resource %v.%v, "+ - "custom resources from a different project are not generated", res.GoPackage, res.Name, project.ProjectConfig.GoPackage) + "custom resources from a different version are not generated", res.GoPackage, res.Name, version.VersionConfig.GoPackage) continue } @@ -43,19 +44,9 @@ func GenerateFiles(project *model.Project, skipOutOfPackageFiles, skipGeneratedT } files = append(files, fs...) } - for _, grp := range project.ResourceGroups { - if skipOutOfPackageFiles && !(strings.HasSuffix(grp.Name, "."+project.ProtoPackage) || grp.Name == project.ProtoPackage) { - continue - } - fs, err := generateFilesForResourceGroup(grp) - if err != nil { - return nil, err - } - files = append(files, fs...) - } - for _, res := range project.XDSResources { - if skipOutOfPackageFiles && !project.ProjectConfig.IsOurProto(res.Filename) { + for _, res := range version.XDSResources { + if skipOutOfPackageFiles && !version.VersionConfig.IsOurProto(res.Filename) { continue } fs, err := generateFilesForXdsResource(res) @@ -64,6 +55,7 @@ func GenerateFiles(project *model.Project, skipOutOfPackageFiles, skipGeneratedT } files = append(files, fs...) } + for i := range files { files[i].Content = fileHeader + files[i].Content } @@ -117,40 +109,17 @@ func generateFilesForResource(resource *model.Resource) (code_generator.Files, e return v, nil } -func generateFilesForResourceGroup(rg *model.ResourceGroup) (code_generator.Files, error) { - var v code_generator.Files - for suffix, tmpl := range map[string]*template.Template{ - "_snapshot.sk.go": templates.ResourceGroupSnapshotTemplate, - "_snapshot_simple_emitter.sk.go": templates.SimpleEmitterTemplate, - "_snapshot_emitter.sk.go": templates.ResourceGroupEmitterTemplate, - "_snapshot_emitter_test.go": templates.ResourceGroupEmitterTestTemplate, - "_event_loop.sk.go": templates.ResourceGroupEventLoopTemplate, - "_simple_event_loop.sk.go": templates.SimpleEventLoopTemplate, - "_event_loop_test.go": templates.ResourceGroupEventLoopTestTemplate, - } { - content, err := generateResourceGroupFile(rg, tmpl) - if err != nil { - return nil, errors.Wrapf(err, "internal error: processing %template '%v' for resource group %v failed", tmpl.ParseName, rg.Name) - } - v = append(v, code_generator.File{ - Filename: strcase.ToSnake(rg.GoName) + suffix, - Content: content, - }) - } - return v, nil -} - -func generateFilesForProject(project *model.Project) (code_generator.Files, error) { +func generateFilesForVersion(version *model.Version) (code_generator.Files, error) { var v code_generator.Files for suffix, tmpl := range map[string]*template.Template{ "_suite_test.go": templates.ProjectTestSuiteTemplate, } { - content, err := generateProjectFile(project, tmpl) + content, err := generateVersionFile(version, tmpl) if err != nil { - return nil, errors.Wrapf(err, "internal error: processing template '%v' for project %v failed", tmpl.ParseName, project.ProjectConfig.Name) + return nil, errors.Wrapf(err, "internal error: processing template '%v' for apigroup %v failed", tmpl.ParseName, version.VersionConfig.ApiGroup.Name) } v = append(v, code_generator.File{ - Filename: strcase.ToSnake(project.ProjectConfig.Name) + suffix, + Filename: strcase.ToSnake(version.VersionConfig.ApiGroup.Name) + suffix, Content: content, }) } @@ -173,17 +142,9 @@ func generateResourceFile(resource *model.Resource, tmpl *template.Template) (st return buf.String(), nil } -func generateResourceGroupFile(rg *model.ResourceGroup, tmpl *template.Template) (string, error) { - buf := &bytes.Buffer{} - if err := tmpl.Execute(buf, rg); err != nil { - return "", err - } - return buf.String(), nil -} - -func generateProjectFile(project *model.Project, tmpl *template.Template) (string, error) { +func generateVersionFile(version *model.Version, tmpl *template.Template) (string, error) { buf := &bytes.Buffer{} - if err := tmpl.Execute(buf, project); err != nil { + if err := tmpl.Execute(buf, version); err != nil { return "", err } return buf.String(), nil diff --git a/pkg/code-generator/codegen/resource_group.go b/pkg/code-generator/codegen/resource_group.go new file mode 100644 index 000000000..11ef0ca5c --- /dev/null +++ b/pkg/code-generator/codegen/resource_group.go @@ -0,0 +1,93 @@ +package codegen + +import ( + "bytes" + "strings" + "text/template" + + "github.com/solo-io/solo-kit/pkg/errors" + + "github.com/iancoleman/strcase" + code_generator "github.com/solo-io/solo-kit/pkg/code-generator" + "github.com/solo-io/solo-kit/pkg/code-generator/codegen/templates" + "github.com/solo-io/solo-kit/pkg/code-generator/model" +) + +func GenerateResourceGroupFiles(apiGroup *model.ApiGroup, skipOutOfPackageFiles, skipGeneratedTests bool) (code_generator.Files, error) { + var files code_generator.Files + + for _, grp := range apiGroup.ResourceGroupsFoo { + if skipOutOfPackageFiles && !(strings.HasSuffix(grp.Name, "."+apiGroup.Name) || grp.Name == apiGroup.Name) { + continue + } + fs, err := generateFilesForResourceGroup(grp) + if err != nil { + return nil, err + } + files = append(files, fs...) + } + + for i := range files { + files[i].Content = fileHeader + files[i].Content + } + if skipGeneratedTests { + var filesWithoutTests code_generator.Files + for _, file := range files { + if strings.HasSuffix(file.Filename, "_test.go") { + continue + } + filesWithoutTests = append(filesWithoutTests, file) + } + files = filesWithoutTests + } + return files, nil +} + +func generateFilesForResourceGroup(rg *model.ResourceGroup) (code_generator.Files, error) { + var v code_generator.Files + for suffix, tmpl := range map[string]*template.Template{ + "_snapshot.sk.go": templates.ResourceGroupSnapshotTemplate, + "_snapshot_simple_emitter.sk.go": templates.SimpleEmitterTemplate, + "_snapshot_emitter.sk.go": templates.ResourceGroupEmitterTemplate, + "_snapshot_emitter_test.go": templates.ResourceGroupEmitterTestTemplate, + "_event_loop.sk.go": templates.ResourceGroupEventLoopTemplate, + "_simple_event_loop.sk.go": templates.SimpleEventLoopTemplate, + "_event_loop_test.go": templates.ResourceGroupEventLoopTestTemplate, + } { + content, err := generateResourceGroupFile(rg, tmpl) + if err != nil { + return nil, errors.Wrapf(err, "internal error: processing %template '%v' for resource group %v failed", tmpl.ParseName, rg.Name) + } + v = append(v, code_generator.File{ + Filename: strcase.ToSnake(rg.GoName) + suffix, + Content: content, + }) + } + + testSuite := &model.TestSuite{ + PackageName: rg.ApiGroup.ResourceGroupGoPackageShort, + } + for suffix, tmpl := range map[string]*template.Template{ + "_suite_test.go": templates.SimpleTestSuiteTemplate, + } { + name := testSuite.PackageName + suffix + content, err := generateTestSuiteFile(testSuite, tmpl) + if err != nil { + return nil, errors.Wrapf(err, "internal error: processing template '%v' for resource group %v failed", tmpl.ParseName, name) + } + v = append(v, code_generator.File{ + Filename: name, + Content: content, + }) + } + + return v, nil +} + +func generateResourceGroupFile(rg *model.ResourceGroup, tmpl *template.Template) (string, error) { + buf := &bytes.Buffer{} + if err := tmpl.Execute(buf, rg); err != nil { + return "", err + } + return buf.String(), nil +} diff --git a/pkg/code-generator/codegen/templates/converter_template.go b/pkg/code-generator/codegen/templates/converter_template.go new file mode 100644 index 000000000..546e26587 --- /dev/null +++ b/pkg/code-generator/codegen/templates/converter_template.go @@ -0,0 +1,103 @@ +package templates + +import ( + "text/template" +) + +var ConverterTemplate = template.Must(template.New("converter").Funcs(Funcs).Parse(`package {{ .ConversionGoPackageShort }} + +import ( + "github.com/solo-io/go-utils/versionutils/kubeapi" + "github.com/solo-io/solo-kit/pkg/api/v1/clients/kube/crd" + "github.com/solo-io/solo-kit/pkg/code-generator/codegen/templates/errors" + + {{- range .Conversions }} + {{- range .Projects }} + {{ .Version }} "{{ .GoPackage }}" + {{- end }} + {{- end }} +) + +{{- range .Conversions }} +{{ $resourceName := .Name }} + +type {{ upper_camel $resourceName }}UpConverter interface { + {{- range .Projects }} + {{- if .NextVersion }} + From{{ upper_camel .Version }}To{{ upper_camel .NextVersion }}(src *{{ .Version }}.{{ upper_camel $resourceName }}) *{{ .NextVersion }}.{{ upper_camel $resourceName }} + {{- end }} + {{- end }} +} + +type {{ upper_camel $resourceName }}DownConverter interface { + {{- range .Projects }} + {{- if .PreviousVersion }} + From{{ upper_camel .Version }}To{{ upper_camel .PreviousVersion }}(src *{{ .Version }}.{{ upper_camel $resourceName }}) *{{ .PreviousVersion }}.{{ upper_camel $resourceName }} + {{- end }} + {{- end }} +} + +type {{ lower_camel $resourceName }}Converter struct { + upConverter {{ upper_camel $resourceName }}UpConverter + downConverter {{ upper_camel $resourceName }}DownConverter +} + +func New{{ upper_camel $resourceName }}Converter(u {{ upper_camel $resourceName }}UpConverter, d {{ upper_camel $resourceName }}DownConverter) crd.Converter { + return &{{ lower_camel $resourceName }}Converter{ + upConverter: u, + downConverter: d, + } +} + +func (c *{{ lower_camel $resourceName }}Converter) Convert(src, dst crd.SoloKitCrd) error { + srcVersion, err := kubeapi.ParseVersion(src.GetObjectKind().GroupVersionKind().Version) + if err != nil { + return err + } + dstVersion, err := kubeapi.ParseVersion(dst.GetObjectKind().GroupVersionKind().Version) + if err != nil { + return err + } + + if srcVersion.GreaterThan(dstVersion) { + return c.convertDown(src, dst) + } else if srcVersion.LessThan(dstVersion) { + return c.convertUp(src, dst) + } + return crd.Copy(src, dst) +} + +func (c *{{ lower_camel $resourceName }}Converter) convertUp(src, dst crd.SoloKitCrd) error { + if src.GetObjectKind().GroupVersionKind().Version == dst.GetObjectKind().GroupVersionKind().Version { + return crd.Copy(src, dst) + } + + switch t := src.(type) { + {{- range .Projects }} + {{- if .NextVersion }} + case *{{ .Version }}.{{ upper_camel $resourceName }}: + return c.convertUp(c.upConverter.From{{ upper_camel .Version }}To{{ upper_camel .NextVersion }}(t), dst) + {{- end }} + {{- end }} + } + return errors.UnrecognizedSourceType +} + +func (c *{{ lower_camel $resourceName }}Converter) convertDown(src, dst crd.SoloKitCrd) error { + if src.GetObjectKind().GroupVersionKind().Version == dst.GetObjectKind().GroupVersionKind().Version { + return crd.Copy(src, dst) + } + + switch t := src.(type) { + {{- range .Projects }} + {{- if .PreviousVersion }} + case *{{ .Version }}.{{ upper_camel $resourceName }}: + return c.convertDown(c.downConverter.From{{ upper_camel .Version }}To{{ upper_camel .PreviousVersion }}(t), dst) + {{- end }} + {{- end }} + } + return errors.UnrecognizedSourceType +} + +{{- end }} +`)) diff --git a/pkg/code-generator/codegen/templates/converter_test_template.go b/pkg/code-generator/codegen/templates/converter_test_template.go new file mode 100644 index 000000000..04a4a385c --- /dev/null +++ b/pkg/code-generator/codegen/templates/converter_test_template.go @@ -0,0 +1,83 @@ +package templates + +import ( + "text/template" +) + +var ConverterTestTemplate = template.Must(template.New("converter_test").Funcs(Funcs).Parse(`// +build solokit + +package {{ .ConversionGoPackageShort }}_test + +{{ $short_package := .ConversionGoPackageShort }} + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/solo-io/solo-kit/pkg/api/v1/clients/kube/crd" + "github.com/solo-io/solo-kit/pkg/api/v1/resources/core" + "{{ .ConversionGoPackage }}" + + {{- range .Conversions }} + {{- range .Projects }} + {{ .Version }} "{{ .GoPackage }}" + {{- end }} + {{- end }} +) + +var converter crd.Converter + +{{- range .Conversions }} +{{ $resource_name := .Name }} + +var _ = Describe("{{ upper_camel $resource_name }}Converter", func() { + BeforeEach(func() { + converter = {{ $short_package }}.New{{ upper_camel $resource_name }}Converter({{ lower_camel $resource_name }}UpConverter{}, {{ lower_camel $resource_name }}DownConverter{}) + }) + + Describe("Convert", func() { + It("works for noop conversions", func() { + src := &{{ (index .Projects 0).Version }}.{{ upper_camel $resource_name }}{Metadata: core.Metadata{Name: "test"}} + dst := &{{ (index .Projects 0).Version }}.{{ upper_camel $resource_name }}{} + err := converter.Convert(src, dst) + Expect(err).NotTo(HaveOccurred()) + Expect(dst.GetMetadata().Name).To(Equal("test")) + }) + + It("converts all the way up", func() { + src := &{{ (index .Projects 0).Version }}.{{ upper_camel $resource_name }}{} + dst := &{{ (index .Projects (add_int (len .Projects) -1)).Version }}.{{ upper_camel $resource_name }}{} + err := converter.Convert(src, dst) + Expect(err).NotTo(HaveOccurred()) + Expect(dst.GetMetadata().Name).To(Equal("{{ (index .Projects (add_int (len .Projects) -1)).Version }}")) + }) + + It("converts all the way down", func() { + src := &{{ (index .Projects (add_int (len .Projects) -1)).Version }}.{{ upper_camel $resource_name }}{} + dst := &{{ (index .Projects 0).Version }}.{{ upper_camel $resource_name }}{} + err := converter.Convert(src, dst) + Expect(err).NotTo(HaveOccurred()) + Expect(dst.GetMetadata().Name).To(Equal("{{ (index .Projects 0).Version }}")) + }) + }) +}) + +type {{ lower_camel $resource_name }}UpConverter struct{} +{{- range .Projects }} +{{- if .NextVersion }} +func ({{ lower_camel $resource_name }}UpConverter) From{{ upper_camel .Version }}To{{ upper_camel .NextVersion }}(src *{{ .Version }}.{{ upper_camel $resource_name }}) *{{ .NextVersion }}.{{ upper_camel $resource_name }} { + return &{{ .NextVersion }}.{{ upper_camel $resource_name }}{Metadata: core.Metadata{Name: "{{ .NextVersion }}"}} +} +{{- end }} +{{- end }} + +type {{ lower_camel $resource_name }}DownConverter struct{} +{{- range .Projects }} +{{- if .PreviousVersion }} +func ({{ lower_camel $resource_name }}DownConverter) From{{ upper_camel .Version }}To{{ upper_camel .PreviousVersion }}(src *{{ .Version }}.{{ upper_camel $resource_name }}) *{{ .PreviousVersion }}.{{ upper_camel $resource_name }} { + return &{{ .PreviousVersion }}.{{ upper_camel $resource_name }}{Metadata: core.Metadata{Name: "{{ .PreviousVersion }}"}} +} +{{- end }} +{{- end }} + +{{- end }} +`)) diff --git a/pkg/code-generator/codegen/templates/errors/errors.go b/pkg/code-generator/codegen/templates/errors/errors.go new file mode 100644 index 000000000..94cd7a783 --- /dev/null +++ b/pkg/code-generator/codegen/templates/errors/errors.go @@ -0,0 +1,7 @@ +package errors + +import "errors" + +var ( + UnrecognizedSourceType = errors.New("unrecognized source type; this should never happen") +) diff --git a/pkg/code-generator/codegen/templates/event_loop_template.go b/pkg/code-generator/codegen/templates/event_loop_template.go index ce4067fa3..141e73083 100644 --- a/pkg/code-generator/codegen/templates/event_loop_template.go +++ b/pkg/code-generator/codegen/templates/event_loop_template.go @@ -4,7 +4,7 @@ import ( "text/template" ) -var ResourceGroupEventLoopTemplate = template.Must(template.New("resource_group_event_loop").Funcs(Funcs).Parse(`package {{ .Project.ProjectConfig.Version }} +var ResourceGroupEventLoopTemplate = template.Must(template.New("resource_group_event_loop").Funcs(Funcs).Parse(`package {{ .ApiGroup.ResourceGroupGoPackageShort }} import ( "context" @@ -50,7 +50,7 @@ func New{{ .GoName }}EventLoop(emitter {{ .GoName }}Emitter, syncer {{ .GoName } func (el *{{ lower_camel .GoName }}EventLoop) Run(namespaces []string, opts clients.WatchOpts) (<-chan error, error) { opts = opts.WithDefaults() - opts.Ctx = contextutils.WithLogger(opts.Ctx, "{{ .Project.ProjectConfig.Version }}.event_loop") + opts.Ctx = contextutils.WithLogger(opts.Ctx, "{{ .ApiGroup.ResourceGroupGoPackageShort }}.event_loop") logger := contextutils.LoggerFrom(opts.Ctx) logger.Infof("event loop started") @@ -60,7 +60,7 @@ func (el *{{ lower_camel .GoName }}EventLoop) Run(namespaces []string, opts clie if err != nil { return nil, errors.Wrapf(err, "starting snapshot watch") } - go errutils.AggregateErrs(opts.Ctx, errs, emitterErrs, "{{ .Project.ProjectConfig.Version }}.emitter errors") + go errutils.AggregateErrs(opts.Ctx, errs, emitterErrs, "{{ .ApiGroup.ResourceGroupGoPackageShort }}.emitter errors") go func() { // create a new context for each loop, cancel it before each loop var cancel context.CancelFunc = func() {} diff --git a/pkg/code-generator/codegen/templates/event_loop_test_template.go b/pkg/code-generator/codegen/templates/event_loop_test_template.go index f3cbbe967..6b4c29b51 100644 --- a/pkg/code-generator/codegen/templates/event_loop_test_template.go +++ b/pkg/code-generator/codegen/templates/event_loop_test_template.go @@ -6,7 +6,7 @@ import ( var ResourceGroupEventLoopTestTemplate = template.Must(template.New("resource_group_event_loop_test").Funcs(Funcs).Parse(`// +build solokit -package {{ .Project.ProjectConfig.Version }} +package {{ .ApiGroup.ResourceGroupGoPackageShort }} {{- $clients := new_str_slice }} {{- range .Resources}} diff --git a/pkg/code-generator/codegen/templates/funcs.go b/pkg/code-generator/codegen/templates/funcs.go index 0285b013a..c2b38941a 100644 --- a/pkg/code-generator/codegen/templates/funcs.go +++ b/pkg/code-generator/codegen/templates/funcs.go @@ -82,6 +82,9 @@ var Funcs = template.FuncMap{ } return result }, + "add_int": func(a, b int) int { + return a + b + }, } func printPointer(format string, p *string) string { diff --git a/pkg/code-generator/codegen/templates/resource_client_template.go b/pkg/code-generator/codegen/templates/resource_client_template.go index 79be1d6df..1c5b2be3f 100644 --- a/pkg/code-generator/codegen/templates/resource_client_template.go +++ b/pkg/code-generator/codegen/templates/resource_client_template.go @@ -4,7 +4,7 @@ import ( "text/template" ) -var ResourceClientTemplate = template.Must(template.New("resource_reconciler").Funcs(Funcs).Parse(`package {{ .Project.ProjectConfig.Version }} +var ResourceClientTemplate = template.Must(template.New("resource_client").Funcs(Funcs).Parse(`package {{ .ParentVersion.VersionConfig.Version }} import ( "github.com/solo-io/solo-kit/pkg/api/v1/clients" diff --git a/pkg/code-generator/codegen/templates/resource_client_test_template.go b/pkg/code-generator/codegen/templates/resource_client_test_template.go index 0b684fe7c..cf572190c 100644 --- a/pkg/code-generator/codegen/templates/resource_client_test_template.go +++ b/pkg/code-generator/codegen/templates/resource_client_test_template.go @@ -6,7 +6,7 @@ import ( var ResourceClientTestTemplate = template.Must(template.New("resource_client_test").Funcs(Funcs).Parse(`// +build solokit -package {{ .Project.ProjectConfig.Version }} +package {{ .ParentVersion.VersionConfig.Version }} import ( "time" diff --git a/pkg/code-generator/codegen/templates/resource_reconciler_template.go b/pkg/code-generator/codegen/templates/resource_reconciler_template.go index de754b31b..ad5d2257e 100644 --- a/pkg/code-generator/codegen/templates/resource_reconciler_template.go +++ b/pkg/code-generator/codegen/templates/resource_reconciler_template.go @@ -4,7 +4,7 @@ import ( "text/template" ) -var ResourceReconcilerTemplate = template.Must(template.New("resource_client").Funcs(Funcs).Parse(`package {{ .Project.ProjectConfig.Version }} +var ResourceReconcilerTemplate = template.Must(template.New("resource_reconciler").Funcs(Funcs).Parse(`package {{ .ParentVersion.VersionConfig.Version }} import ( "github.com/solo-io/solo-kit/pkg/api/v1/clients" "github.com/solo-io/solo-kit/pkg/api/v1/reconcile" diff --git a/pkg/code-generator/codegen/templates/resource_template.go b/pkg/code-generator/codegen/templates/resource_template.go index 561d513b7..9b07796b4 100644 --- a/pkg/code-generator/codegen/templates/resource_template.go +++ b/pkg/code-generator/codegen/templates/resource_template.go @@ -4,7 +4,7 @@ import ( "text/template" ) -var ResourceTemplate = template.Must(template.New("resource").Funcs(Funcs).Parse(`package {{ .Project.ProjectConfig.Version }} +var ResourceTemplate = template.Must(template.New("resource").Funcs(Funcs).Parse(`package {{ .ParentVersion.VersionConfig.Version }} import ( "sort" @@ -185,9 +185,9 @@ func (list {{ .Name }}List) AsInterfaces() []interface{}{ return asInterfaces } -{{- $crdGroupName := .Project.ProtoPackage }} -{{- if ne .Project.ProjectConfig.CrdGroupOverride "" }} -{{- $crdGroupName = .Project.ProjectConfig.CrdGroupOverride }} +{{- $crdGroupName := .ParentVersion.ProtoPackage }} +{{- if ne .ParentVersion.VersionConfig.ApiGroup.CrdGroupOverride "" }} +{{- $crdGroupName = .ParentVersion.VersionConfig.ApiGroup.CrdGroupOverride }} {{- end}} {{- if not $.IsCustom }} @@ -203,7 +203,6 @@ func (o *{{ .Name }}) DeepCopyObject() runtime.Object { return resources.Clone(o).(*{{ .Name }}) } - var ( {{ .Name }}Crd = crd.NewCrd( "{{ lowercase (upper_camel .PluralName) }}", @@ -225,7 +224,7 @@ func init() { var ( {{ .Name }}GVK = schema.GroupVersionKind{ - Version: "{{ .Project.ProjectConfig.Version }}", + Version: "{{ .ParentVersion.VersionConfig.Version }}", Group: "{{ $crdGroupName }}", Kind: "{{ .Name }}", } diff --git a/pkg/code-generator/codegen/templates/simple_event_loop_template.go b/pkg/code-generator/codegen/templates/simple_event_loop_template.go index 038ab8995..1d8b5b709 100644 --- a/pkg/code-generator/codegen/templates/simple_event_loop_template.go +++ b/pkg/code-generator/codegen/templates/simple_event_loop_template.go @@ -4,7 +4,7 @@ import ( "text/template" ) -var SimpleEventLoopTemplate = template.Must(template.New("simple_event_loop").Funcs(Funcs).Parse(`package {{ .Project.ProjectConfig.Version }} +var SimpleEventLoopTemplate = template.Must(template.New("simple_event_loop").Funcs(Funcs).Parse(`package {{ .ApiGroup.ResourceGroupGoPackageShort }} import ( "context" @@ -49,7 +49,7 @@ func New{{ .GoName }}SimpleEventLoop(emitter {{ .GoName }}SimpleEmitter, syncers } func (el *{{ lower_camel .GoName }}SimpleEventLoop) Run(ctx context.Context) (<-chan error, error) { - ctx = contextutils.WithLogger(ctx, "{{ .Project.ProjectConfig.Version }}.event_loop") + ctx = contextutils.WithLogger(ctx, "{{ .ApiGroup.ResourceGroupGoPackageShort }}.event_loop") logger := contextutils.LoggerFrom(ctx) logger.Infof("event loop started") @@ -61,7 +61,7 @@ func (el *{{ lower_camel .GoName }}SimpleEventLoop) Run(ctx context.Context) (<- } - go errutils.AggregateErrs(ctx, errs, emitterErrs, "{{ .Project.ProjectConfig.Version }}.emitter errors") + go errutils.AggregateErrs(ctx, errs, emitterErrs, "{{ .ApiGroup.ResourceGroupGoPackageShort }}.emitter errors") go func() { // create a new context for each syncer for each loop, cancel each before each loop syncerCancels := make(map[{{ .GoName }}Syncer]context.CancelFunc) diff --git a/pkg/code-generator/codegen/templates/simple_test_suite_template.go b/pkg/code-generator/codegen/templates/simple_test_suite_template.go new file mode 100644 index 000000000..172782012 --- /dev/null +++ b/pkg/code-generator/codegen/templates/simple_test_suite_template.go @@ -0,0 +1,21 @@ +package templates + +import ( + "text/template" +) + +var SimpleTestSuiteTemplate = template.Must(template.New("project_template").Funcs(Funcs).Parse(`package {{ .PackageName }} + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +func Test{{ upper_camel .PackageName }}(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "{{ upper_camel .PackageName }} Suite") +} + +`)) diff --git a/pkg/code-generator/codegen/templates/snapshot_emitter_template.go b/pkg/code-generator/codegen/templates/snapshot_emitter_template.go index 2be15d730..5a30032c2 100644 --- a/pkg/code-generator/codegen/templates/snapshot_emitter_template.go +++ b/pkg/code-generator/codegen/templates/snapshot_emitter_template.go @@ -5,7 +5,7 @@ import ( ) var ResourceGroupEmitterTemplate = template.Must(template.New("resource_group_emitter").Funcs(Funcs).Parse( - `package {{ .Project.ProjectConfig.Version }} + `package {{ .ApiGroup.ResourceGroupGoPackageShort }} {{- $client_declarations := new_str_slice }} {{- $clients := new_str_slice }} diff --git a/pkg/code-generator/codegen/templates/snapshot_emitter_test_template.go b/pkg/code-generator/codegen/templates/snapshot_emitter_test_template.go index 390005ab8..8968d7b36 100644 --- a/pkg/code-generator/codegen/templates/snapshot_emitter_test_template.go +++ b/pkg/code-generator/codegen/templates/snapshot_emitter_test_template.go @@ -6,7 +6,7 @@ import ( var ResourceGroupEmitterTestTemplate = template.Must(template.New("resource_group_emitter_test").Funcs(Funcs).Parse(`// +build solokit -package {{ .Project.ProjectConfig.Version }} +package {{ .ApiGroup.ResourceGroupGoPackageShort }} {{- /* we need to know if the tests require a crd client or a regular clientset */ -}} {{- $clients := new_str_slice }} @@ -46,7 +46,7 @@ import ( _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" ) -var _ = Describe("{{ upper_camel .Project.ProjectConfig.Version }}Emitter", func() { +var _ = Describe("{{ upper_camel .ApiGroup.ResourceGroupGoPackageShort }}Emitter", func() { if os.Getenv("RUN_KUBE_TESTS") != "1" { log.Printf("This test creates kubernetes resources and is disabled by default. To enable, set RUN_KUBE_TESTS=1 in your env.") return diff --git a/pkg/code-generator/codegen/templates/snapshot_simple_emitter_template.go b/pkg/code-generator/codegen/templates/snapshot_simple_emitter_template.go index ec1effbaf..ecf1537c5 100644 --- a/pkg/code-generator/codegen/templates/snapshot_simple_emitter_template.go +++ b/pkg/code-generator/codegen/templates/snapshot_simple_emitter_template.go @@ -5,7 +5,7 @@ import ( ) var SimpleEmitterTemplate = template.Must(template.New("resource_group_emitter").Funcs(Funcs).Parse( - `package {{ .Project.ProjectConfig.Version }} + `package {{ .ApiGroup.ResourceGroupGoPackageShort }} import ( "context" diff --git a/pkg/code-generator/codegen/templates/snapshot_template.go b/pkg/code-generator/codegen/templates/snapshot_template.go index 7e8ffc565..c731be298 100644 --- a/pkg/code-generator/codegen/templates/snapshot_template.go +++ b/pkg/code-generator/codegen/templates/snapshot_template.go @@ -5,7 +5,7 @@ import ( ) var ResourceGroupSnapshotTemplate = template.Must(template.New("resource_group_snapshot").Funcs(Funcs).Parse( - `package {{ .Project.ProjectConfig.Version }} + `package {{ .ApiGroup.ResourceGroupGoPackageShort }} import ( "fmt" diff --git a/pkg/code-generator/codegen/templates/test_suite_template.go b/pkg/code-generator/codegen/templates/test_suite_template.go index f261b2242..142c1c6fc 100644 --- a/pkg/code-generator/codegen/templates/test_suite_template.go +++ b/pkg/code-generator/codegen/templates/test_suite_template.go @@ -4,7 +4,7 @@ import ( "text/template" ) -var ProjectTestSuiteTemplate = template.Must(template.New("project_template").Funcs(Funcs).Parse(`package {{ .ProjectConfig.Version }} +var ProjectTestSuiteTemplate = template.Must(template.New("project_test_suite_template").Funcs(Funcs).Parse(`package {{ .VersionConfig.Version }} {{- $uniqueCrds := new_str_slice }} {{- range .Resources}} @@ -27,9 +27,9 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -func Test{{ upper_camel .ProjectConfig.Name }}(t *testing.T) { +func Test{{ upper_camel .VersionConfig.ApiGroup.Name }}(t *testing.T) { RegisterFailHandler(Fail) - RunSpecs(t, "{{ upper_camel .ProjectConfig.Name }} Suite") + RunSpecs(t, "{{ upper_camel .VersionConfig.ApiGroup.Name }} Suite") } diff --git a/pkg/code-generator/codegen/templates/xds_template.go b/pkg/code-generator/codegen/templates/xds_template.go index 058cadfaa..bc6ae089c 100644 --- a/pkg/code-generator/codegen/templates/xds_template.go +++ b/pkg/code-generator/codegen/templates/xds_template.go @@ -4,7 +4,7 @@ import ( "text/template" ) -var XdsTemplate = template.Must(template.New("xds_template").Funcs(Funcs).Parse(`package {{ .Project.ProjectConfig.Version }} +var XdsTemplate = template.Must(template.New("xds_template").Funcs(Funcs).Parse(`package {{ .ParentVersion.VersionConfig.Version }} import ( "context" diff --git a/pkg/code-generator/docgen/funcs/template_funcs.go b/pkg/code-generator/docgen/funcs/template_funcs.go index 7c5ce5e02..71dfd9ef4 100644 --- a/pkg/code-generator/docgen/funcs/template_funcs.go +++ b/pkg/code-generator/docgen/funcs/template_funcs.go @@ -43,7 +43,7 @@ type templateFunctions struct { var magicCommentRegex = regexp.MustCompile("@solo-kit:.*") var githubProjectFileRegex = regexp.MustCompile(".*github.com/([^/]*)/([^/]*)/(.*)") -func TemplateFuncs(project *model.Project, docsOptions *options.DocsOptions) template.FuncMap { +func TemplateFuncs(version *model.Version, docsOptions *options.DocsOptions) template.FuncMap { funcs := &templateFunctions{} funcMap := template.FuncMap{ "join": strings.Join, @@ -54,13 +54,13 @@ func TemplateFuncs(project *model.Project, docsOptions *options.DocsOptions) tem "p": gendoc.PFilter, "para": gendoc.ParaFilter, "nobr": gendoc.NoBrFilter, - "fieldType": fieldType(project), + "fieldType": fieldType(version), "yamlType": yamlType, "noescape": noEscape, - "linkForField": linkForField(project, docsOptions), - "linkForResource": linkForResource(project, docsOptions), - "forEachMessage": funcs.forEachMessage(getMessageSkippingInfo(project)), - "resourceForMessage": resourceForMessage(project), + "linkForField": linkForField(version, docsOptions), + "linkForResource": linkForResource(version, docsOptions), + "forEachMessage": funcs.forEachMessage(getMessageSkippingInfo(version)), + "resourceForMessage": resourceForMessage(version), "getFileForMessage": func(msg *protokit.Descriptor) *protokit.FileDescriptor { return msg.GetFile() }, @@ -180,7 +180,7 @@ func noEscape(s string) htmltemplate.HTML { return htmltemplate.HTML(s) } -func fieldType(project *model.Project) func(field *protokit.FieldDescriptor) (string, error) { +func fieldType(version *model.Version) func(field *protokit.FieldDescriptor) (string, error) { return func(field *protokit.FieldDescriptor) (string, error) { fieldTypeStr := func() string { switch field.GetType() { @@ -198,7 +198,7 @@ func fieldType(project *model.Project) func(field *protokit.FieldDescriptor) (st fieldTypeStr = "[]" + strings.TrimPrefix(fieldTypeStr, ".") } if strings.HasSuffix(fieldTypeStr, "Entry") { - _, msg, enum, err := getFileAndTypeDefForField(project, field) + _, msg, enum, err := getFileAndTypeDefForField(version, field) if err != nil { return "", err } @@ -208,11 +208,11 @@ func fieldType(project *model.Project) func(field *protokit.FieldDescriptor) (st if len(msg.Field) != 2 { return "", errors.Errorf("message %v was Entry type, expected map", msg.GetName()) } - key, err := fieldType(project)(&protokit.FieldDescriptor{FieldDescriptorProto: msg.Field[0]}) + key, err := fieldType(version)(&protokit.FieldDescriptor{FieldDescriptorProto: msg.Field[0]}) if err != nil { return "", err } - val, err := fieldType(project)(&protokit.FieldDescriptor{FieldDescriptorProto: msg.Field[1]}) + val, err := fieldType(version)(&protokit.FieldDescriptor{FieldDescriptorProto: msg.Field[1]}) if err != nil { return "", err } @@ -230,16 +230,16 @@ func wellKnownProtoLink(typeName string) string { return wellKnown } -func linkForField(project *model.Project, docsOptions *options.DocsOptions) func(forFile *protokit.FileDescriptor, field *protokit.FieldDescriptor) (string, error) { +func linkForField(version *model.Version, docsOptions *options.DocsOptions) func(forFile *protokit.FileDescriptor, field *protokit.FieldDescriptor) (string, error) { return func(forFile *protokit.FileDescriptor, field *protokit.FieldDescriptor) (string, error) { - typeName, err := fieldType(project)(field) + typeName, err := fieldType(version)(field) if err != nil { return "", err } if _, ok := primitiveTypes[field.GetType()]; ok || strings.HasPrefix(typeName, "map<") { return "`" + typeName + "`", nil } - file, msg, enum, err := getFileAndTypeDefForField(project, field) + file, msg, enum, err := getFileAndTypeDefForField(version, field) if err != nil { return "", err } @@ -263,7 +263,7 @@ func linkForField(project *model.Project, docsOptions *options.DocsOptions) func } default: var linkedFile string - for _, toGenerate := range project.Request.FileToGenerate { + for _, toGenerate := range version.Request.FileToGenerate { if strings.HasSuffix(file.GetName(), toGenerate) { linkedFile = toGenerate break @@ -271,7 +271,7 @@ func linkForField(project *model.Project, docsOptions *options.DocsOptions) func } if linkedFile == "" { linkedFile = filepath.Base(file.GetName()) - //return "", errors.Errorf("failed to get generated file path for proto %v in list %v", file.GetName(), project.Request.FileToGenerate) + //return "", errors.Errorf("failed to get generated file path for proto %v in list %v", file.GetName(), version.Request.FileToGenerate) } linkedFile = relativeFilename(forFile.GetName(), linkedFile) @@ -293,8 +293,8 @@ func linkForField(project *model.Project, docsOptions *options.DocsOptions) func } } -func linkForResource(project *model.Project, docsOptions *options.DocsOptions) func(resource *model.Resource) (string, error) { - protoFiles := protokit.ParseCodeGenRequest(project.Request) +func linkForResource(version *model.Version, docsOptions *options.DocsOptions) func(resource *model.Resource) (string, error) { + protoFiles := protokit.ParseCodeGenRequest(version.Request) return func(resource *model.Resource) (string, error) { for _, file := range protoFiles { if file.GetName() == resource.Filename { @@ -314,14 +314,14 @@ func linkForResource(project *model.Project, docsOptions *options.DocsOptions) f return fmt.Sprintf("[%v](%v%v%v#%v)", resource.Name, prefix, resource.Filename, ext, name), nil } } - return "", errors.Errorf("internal error: could not find file for resource %v in project %v", - resource.Filename, project.ProjectConfig.Name) + return "", errors.Errorf("internal error: could not find file for resource %v in apigroup %v", + resource.Filename, version.VersionConfig.ApiGroup.Name) } } -func resourceForMessage(project *model.Project) func(msg *protokit.Descriptor) (*model.Resource, error) { +func resourceForMessage(version *model.Version) func(msg *protokit.Descriptor) (*model.Resource, error) { return func(msg *protokit.Descriptor) (*model.Resource, error) { - for _, res := range project.Resources { + for _, res := range version.Resources { if res.SkipDocsGen { continue } @@ -330,8 +330,8 @@ func resourceForMessage(project *model.Project) func(msg *protokit.Descriptor) ( } } return nil, nil - return nil, errors.Errorf("internal error: could not find file for resource for msg %v in project %v", - msg.GetName(), project.ProjectConfig.Name) + return nil, errors.Errorf("internal error: could not find file for resource for msg %v in apigroup %v", + msg.GetName(), version.VersionConfig.ApiGroup.Name) } } @@ -408,14 +408,14 @@ func commonPrefix(sep byte, paths ...string) string { return string(c) } -func getFileForField(project *model.Project, field *protokit.FieldDescriptor) (*descriptor.FileDescriptorProto, error) { +func getFileForField(version *model.Version, field *protokit.FieldDescriptor) (*descriptor.FileDescriptorProto, error) { parts := strings.Split(strings.TrimPrefix(field.GetTypeName(), "."), ".") if strings.HasSuffix(parts[len(parts)-1], "Entry") { parts = parts[:len(parts)-1] } messageName := parts[len(parts)-1] packageName := strings.Join(parts[:len(parts)-1], ".") - for _, protoFile := range project.Request.GetProtoFile() { + for _, protoFile := range version.Request.GetProtoFile() { if protoFile.GetPackage() == packageName { for _, msg := range protoFile.GetMessageType() { if messageName == msg.GetName() { @@ -424,7 +424,7 @@ func getFileForField(project *model.Project, field *protokit.FieldDescriptor) (* } } } - for _, protoFile := range project.Request.ProtoFile { + for _, protoFile := range version.Request.ProtoFile { // ilackarms: unlikely event of collision where the package name has the right prefix and a nested message type matches if strings.HasPrefix(packageName, protoFile.GetPackage()) { for _, msg := range protoFile.GetMessageType() { @@ -457,9 +457,9 @@ func splitTypeName(typeName string) (string, []string) { return packageName, parts[indexOfFirstUppercasePart:] } -func getFileAndTypeDefForField(project *model.Project, field *protokit.FieldDescriptor) (*descriptor.FileDescriptorProto, *descriptor.DescriptorProto, *descriptor.EnumDescriptorProto, error) { +func getFileAndTypeDefForField(version *model.Version, field *protokit.FieldDescriptor) (*descriptor.FileDescriptorProto, *descriptor.DescriptorProto, *descriptor.EnumDescriptorProto, error) { packageName, typeNameParts := splitTypeName(field.GetTypeName()) - for _, protoFile := range project.Request.ProtoFile { + for _, protoFile := range version.Request.ProtoFile { if protoFile.GetPackage() == packageName { if len(typeNameParts) == 1 { for _, enum := range protoFile.GetEnumType() { @@ -564,10 +564,10 @@ func (c *templateFunctions) forEachMessage(messagesToSkip map[string]bool) func( // Returns a map indicating which resources should be skipped during doc generation. // The keys are strings in the format .. -func getMessageSkippingInfo(project *model.Project) map[string]bool { +func getMessageSkippingInfo(version *model.Version) map[string]bool { // Build map for quick lookup of SkipDocsGen flag toSkip := make(map[string]bool) - for _, resource := range project.Resources { + for _, resource := range version.Resources { if resource.SkipDocsGen { continue } diff --git a/pkg/code-generator/docgen/generator.go b/pkg/code-generator/docgen/generator.go index d6383caa2..8e147f930 100644 --- a/pkg/code-generator/docgen/generator.go +++ b/pkg/code-generator/docgen/generator.go @@ -18,7 +18,7 @@ import ( type DocsGen struct { DocsOptions options.DocsOptions - Project *model.Project + Project *model.Version } // must ignore validate.proto from lyft @@ -89,8 +89,8 @@ func (d *DocsGen) GenerateFilesForProtoFiles(protoFiles []*protokit.FileDescript return v, nil } -func GenerateFiles(project *model.Project, docsOptions *options.DocsOptions) (code_generator.Files, error) { - protoFiles := protokit.ParseCodeGenRequest(project.Request) +func GenerateFiles(version *model.Version, docsOptions *options.DocsOptions) (code_generator.Files, error) { + protoFiles := protokit.ParseCodeGenRequest(version.Request) if docsOptions == nil { docsOptions = &options.DocsOptions{} } @@ -101,7 +101,7 @@ func GenerateFiles(project *model.Project, docsOptions *options.DocsOptions) (co docGenerator := DocsGen{ DocsOptions: *docsOptions, - Project: project, + Project: version, } files, err := docGenerator.GenerateFilesForProject() @@ -167,16 +167,16 @@ func (d *DocsGen) GenerateFilesForProject() (code_generator.Files, error) { return nil, err } v = append(v, code_generator.File{ - Filename: strcase.ToSnake(d.Project.ProjectConfig.Name) + suffix, + Filename: strcase.ToSnake(d.Project.VersionConfig.ApiGroup.Name) + suffix, Content: content, }) } return v, nil } -func generateProjectFile(project *model.Project, tmpl *template.Template) (string, error) { +func generateProjectFile(version *model.Version, tmpl *template.Template) (string, error) { buf := &bytes.Buffer{} - if err := tmpl.Execute(buf, project); err != nil { + if err := tmpl.Execute(buf, version); err != nil { return "", err } return buf.String(), nil diff --git a/pkg/code-generator/docgen/templates/markdown/project_template.go b/pkg/code-generator/docgen/templates/markdown/project_template.go index aec72bd63..f29bae3c5 100644 --- a/pkg/code-generator/docgen/templates/markdown/project_template.go +++ b/pkg/code-generator/docgen/templates/markdown/project_template.go @@ -9,14 +9,14 @@ import ( "github.com/solo-io/solo-kit/pkg/code-generator/model" ) -func ProjectDocsRootTemplate(project *model.Project, docsOptions *options.DocsOptions) *template.Template { +func ProjectDocsRootTemplate(version *model.Version, docsOptions *options.DocsOptions) *template.Template { str := ` -### API Reference for {{ .ProjectConfig.Title}} +### API Reference for {{ .VersionConfig.ApiGroup.SoloKitProject.Title}} -API Version: ` + "`{{ .ProjectConfig.Name }}.{{ .ProjectConfig.Version }}`" + ` +API Version: ` + "`{{ .VersionConfig.ApiGroup.Name }}.{{ .VersionConfig.Version }}`" + ` -{{ .ProjectConfig.Description }} +{{ .VersionConfig.ApiGroup.SoloKitProject.Description }} ### API Resources: {{- range .Resources}} @@ -29,5 +29,5 @@ API Version: ` + "`{{ .ProjectConfig.Name }}.{{ .ProjectConfig.Version }}`" + ` ` - return template.Must(template.New("pf").Funcs(funcs.TemplateFuncs(project, docsOptions)).Parse(str)) + return template.Must(template.New("markdown_project").Funcs(funcs.TemplateFuncs(version, docsOptions)).Parse(str)) } diff --git a/pkg/code-generator/docgen/templates/markdown/proto_file_template.go b/pkg/code-generator/docgen/templates/markdown/proto_file_template.go index 8db65db44..e22e6fdb4 100644 --- a/pkg/code-generator/docgen/templates/markdown/proto_file_template.go +++ b/pkg/code-generator/docgen/templates/markdown/proto_file_template.go @@ -8,7 +8,7 @@ import ( "github.com/solo-io/solo-kit/pkg/code-generator/model" ) -func ProtoFileTemplate(project *model.Project, docsOptions *options.DocsOptions) *template.Template { +func ProtoFileTemplate(version *model.Version, docsOptions *options.DocsOptions) *template.Template { str := ` {{ $File := . -}} @@ -107,5 +107,5 @@ Description: {{ remove_magic_comments .Comments.Leading }} ` - return template.Must(template.New("p").Funcs(funcs.TemplateFuncs(project, docsOptions)).Parse(str)) + return template.Must(template.New("p").Funcs(funcs.TemplateFuncs(version, docsOptions)).Parse(str)) } diff --git a/pkg/code-generator/docgen/templates/restructured/project_template.go b/pkg/code-generator/docgen/templates/restructured/project_template.go index 3152f547b..6c88e117b 100644 --- a/pkg/code-generator/docgen/templates/restructured/project_template.go +++ b/pkg/code-generator/docgen/templates/restructured/project_template.go @@ -9,16 +9,16 @@ import ( "github.com/solo-io/solo-kit/pkg/code-generator/model" ) -func ProjectDocsRootTemplate(project *model.Project, docsOptions *options.DocsOptions) *template.Template { - return template.Must(template.New("pf").Funcs(funcs.TemplateFuncs(project, docsOptions)).Parse(` +func ProjectDocsRootTemplate(version *model.Version, docsOptions *options.DocsOptions) *template.Template { + return template.Must(template.New("restructured_project").Funcs(funcs.TemplateFuncs(version, docsOptions)).Parse(` =========================================== -API Reference for {{ .ProjectConfig.Title}} +API Reference for {{ .VersionConfig.ApiGroup.SoloKitProject.Title }} =========================================== -.. _{{ .ProjectConfig.Title}}: +.. _{{ .VersionConfig.ApiGroup.SoloKitProject.Title }}: -API Version: ` + "`{{ .ProjectConfig.Name }}.{{ .ProjectConfig.Version }}`" + ` +API Version: ` + "`{{ .VersionConfig.ApiGroup.Name }}.{{ .VersionConfig.Version }}`" + ` -{{ .ProjectConfig.Description }} +{{ .VersionConfig.ApiGroup.SoloKitProject.Description }} API Resources: ~~~~~~~~~~~~~~ diff --git a/pkg/code-generator/docgen/templates/restructured/proto_file_template.go b/pkg/code-generator/docgen/templates/restructured/proto_file_template.go index 12333abd3..40d2993db 100644 --- a/pkg/code-generator/docgen/templates/restructured/proto_file_template.go +++ b/pkg/code-generator/docgen/templates/restructured/proto_file_template.go @@ -8,7 +8,7 @@ import ( "github.com/solo-io/solo-kit/pkg/code-generator/model" ) -func ProtoFileTemplate(project *model.Project, docsOptions *options.DocsOptions) *template.Template { +func ProtoFileTemplate(version *model.Version, docsOptions *options.DocsOptions) *template.Template { str := ` {{ $File := . -}} @@ -130,5 +130,5 @@ Description: {{ remove_magic_comments .Comments.Leading }} ` - return template.Must(template.New("p").Funcs(funcs.TemplateFuncs(project, docsOptions)).Parse(str)) + return template.Must(template.New("p").Funcs(funcs.TemplateFuncs(version, docsOptions)).Parse(str)) } diff --git a/pkg/code-generator/model/conversion.go b/pkg/code-generator/model/conversion.go new file mode 100644 index 000000000..0bd6db5f2 --- /dev/null +++ b/pkg/code-generator/model/conversion.go @@ -0,0 +1,15 @@ +package model + +// SOLO-KIT Descriptors from which code can be generated + +type Conversion struct { + Name string + Projects []*ConversionProject +} + +type ConversionProject struct { + Version string + NextVersion string + PreviousVersion string + GoPackage string +} diff --git a/pkg/code-generator/model/project.go b/pkg/code-generator/model/project.go index a6476fba2..8b2b85b13 100644 --- a/pkg/code-generator/model/project.go +++ b/pkg/code-generator/model/project.go @@ -18,33 +18,63 @@ const ProjectConfigFilename = "solo-kit.json" // SOLO-KIT Descriptors from which code can be generated -type ProjectConfig struct { - Title string `json:"title"` - Description string `json:"description"` - Name string `json:"name"` - Version string `json:"version"` - DocsDir string `json:"docs_dir"` - ResourceGroups map[string][]ResourceConfig `json:"resource_groups"` - // if set, this group will override the proto pacakge typically used +type SoloKitProject struct { + Title string `json:"title"` + Description string `json:"description"` + ApiGroup *ApiGroup `json:"api_group"` + + // set by load + ProjectFile string +} + +type ApiGroup struct { + Name string `json:"name"` + DocsDir string `json:"docs_dir"` + VersionConfigs []*VersionConfig `json:"version_configs"` + ResourceGroups map[string][]ResourceConfig `json:"resource_groups"` + ResourceGroupGoPackage string `json:"resource_group_go_package"` + ConversionGoPackage string `json:"conversion_go_package"` + + // if set, this group will override the proto package typically used // as the api group for the crd CrdGroupOverride string `json:"crd_group_override"` - // imported solokit projects + // imported solokit projects, used for resource groups Imports []string `json:"imports"` + // set by load + SoloKitProject *SoloKitProject + Conversions []*Conversion + // TODO joekelley improve name + ResourceGroupsFoo []*ResourceGroup + ConversionGoPackageShort string + ResourceGroupGoPackageShort string +} + +func (a ApiGroup) IsOurProto(protoFile string) bool { + for _, vc := range a.VersionConfigs { + if vc.IsOurProto(protoFile) { + return true + } + } + return false +} + +type VersionConfig struct { + Version string `json:"version"` + // define custom resources here CustomResources []CustomResourceConfig `json:"custom_resources"` - // set by load if not specified GoPackage string `json:"go_package"` // set by load - ProjectFile string - ProjectProtos []string + ApiGroup *ApiGroup + VersionProtos []string } -func (p ProjectConfig) IsOurProto(protoFile string) bool { - for _, file := range p.ProjectProtos { +func (p VersionConfig) IsOurProto(protoFile string) bool { + for _, file := range p.VersionProtos { if protoFile == file { return true } @@ -73,12 +103,11 @@ type CustomResourceConfig struct { Imported bool } -type Project struct { - ProjectConfig ProjectConfig - ProtoPackage string - Resources []*Resource - ResourceGroups []*ResourceGroup - XDSResources []*XDSResource +type Version struct { + VersionConfig VersionConfig + ProtoPackage string + Resources []*Resource + XDSResources []*XDSResource Request *plugin_go.CodeGeneratorRequest } @@ -108,7 +137,7 @@ type Resource struct { // resource groups i belong to ResourceGroups []*ResourceGroup // project i belong to - Project *Project + ParentVersion *Version Filename string // the proto file where this resource is contained Version string // set during parsing from this resource's solo-kit.json @@ -133,7 +162,7 @@ type ResourceGroup struct { Name string // eg. api.gloo.solo.io GoName string // will be Api Imports string // if this resource group contains any imports from other projects - Project *Project + ApiGroup *ApiGroup Resources []*Resource } @@ -143,40 +172,44 @@ type XDSResource struct { NameField string NoReferences bool - Project *Project - ProtoPackage string // eg. gloo.solo.io + ParentVersion *Version + ProtoPackage string // eg. gloo.solo.io Filename string // the proto file where this resource is contained } -func LoadProjectConfig(path string) (ProjectConfig, error) { +func LoadProjectConfig(path string) (SoloKitProject, error) { b, err := ioutil.ReadFile(path) if err != nil { - return ProjectConfig{}, err + return SoloKitProject{}, err } - var pc ProjectConfig - err = json.Unmarshal(b, &pc) + var skp SoloKitProject + err = json.Unmarshal(b, &skp) if err != nil { - return ProjectConfig{}, err + return SoloKitProject{}, err } - pc.ProjectFile = path - if pc.GoPackage == "" { - goPkg, err := detectGoPackageForProject(path) - if err != nil { - return ProjectConfig{}, err + + skp.ProjectFile = path + skp.ApiGroup.ResourceGroupGoPackageShort = filepath.Base(skp.ApiGroup.ResourceGroupGoPackage) + for _, vc := range skp.ApiGroup.VersionConfigs { + if vc.GoPackage == "" { + goPkg, err := detectGoPackageForVersion(filepath.Dir(skp.ProjectFile) + "/" + vc.Version) + if err != nil { + return SoloKitProject{}, err + } + vc.GoPackage = goPkg } - pc.GoPackage = goPkg } - return pc, err + + return skp, err } var goPackageStatementRegex = regexp.MustCompile(`option go_package.*=.*"(.*)";`) -// Returns the value of the 'go_package' option of the first .proto file found in the same directory as projectFile -func detectGoPackageForProject(projectFile string) (string, error) { +// Returns the value of the 'go_package' option of the first .proto file found in the version's directory +func detectGoPackageForVersion(versionDir string) (string, error) { var goPkg string - projectDir := filepath.Dir(projectFile) - if err := filepath.Walk(projectDir, func(protoFile string, info os.FileInfo, err error) error { + if err := filepath.Walk(versionDir, func(protoFile string, info os.FileInfo, err error) error { // already set if goPkg != "" { return nil @@ -185,7 +218,7 @@ func detectGoPackageForProject(projectFile string) (string, error) { return nil } // search for go_package on protos in the same dir as the project.json - if projectDir != filepath.Dir(protoFile) { + if versionDir != filepath.Dir(protoFile) { return nil } content, err := ioutil.ReadFile(protoFile) @@ -209,7 +242,7 @@ func detectGoPackageForProject(projectFile string) (string, error) { return "", err } if goPkg == "" { - return "", errors.Errorf("no go_package statement found in root dir of project %v", projectFile) + return "", errors.Errorf("no go_package statement found in root dir of version %v", versionDir) } return goPkg, nil } diff --git a/pkg/code-generator/model/simple_test_suite.go b/pkg/code-generator/model/simple_test_suite.go new file mode 100644 index 000000000..adc1bffdc --- /dev/null +++ b/pkg/code-generator/model/simple_test_suite.go @@ -0,0 +1,5 @@ +package model + +type TestSuite struct { + PackageName string +} diff --git a/pkg/code-generator/parser/parser.go b/pkg/code-generator/parser/parser.go index 56660cb4e..ecfb2f5a5 100644 --- a/pkg/code-generator/parser/parser.go +++ b/pkg/code-generator/parser/parser.go @@ -13,7 +13,7 @@ import ( "github.com/solo-io/solo-kit/pkg/code-generator/model" ) -func ProcessDescriptors(projectConfig *model.ProjectConfig, allProjectConfigs []*model.ProjectConfig, descriptors []*descriptor.FileDescriptorProto) (*model.Project, error) { +func ProcessDescriptors(versionConfig *model.VersionConfig, apiGroup *model.ApiGroup, descriptors []*descriptor.FileDescriptorProto) (*model.Version, error) { req := &plugin_go.CodeGeneratorRequest{} for _, file := range descriptors { var added bool @@ -28,11 +28,11 @@ func ProcessDescriptors(projectConfig *model.ProjectConfig, allProjectConfigs [] req.FileToGenerate = append(req.FileToGenerate, file.GetName()) req.ProtoFile = append(req.ProtoFile, file) } - return parseRequest(projectConfig, allProjectConfigs, req) + return parseRequest(versionConfig, apiGroup, req) } -func parseRequest(projectConfig *model.ProjectConfig, allProjectConfigs []*model.ProjectConfig, req *plugin_go.CodeGeneratorRequest) (*model.Project, error) { - log.Printf("project config: %v", projectConfig) +func parseRequest(versionConfig *model.VersionConfig, apiGroup *model.ApiGroup, req *plugin_go.CodeGeneratorRequest) (*model.Version, error) { + log.Printf("version config: %v", versionConfig) descriptors := protokit.ParseCodeGenRequest(req) var messages []ProtoMessageWrapper @@ -54,26 +54,25 @@ func parseRequest(projectConfig *model.ProjectConfig, allProjectConfigs []*model services = append(services, file.GetServices()...) } - project := &model.Project{ - ProjectConfig: *projectConfig, - ProtoPackage: projectConfig.Name, + version := &model.Version{ + VersionConfig: *versionConfig, + ProtoPackage: versionConfig.ApiGroup.Name, Request: req, } - resources, resourceGroups, err := getResources(project, allProjectConfigs, messages) + resources, err := getResources(version, apiGroup, messages) if err != nil { return nil, err } - xdsResources, err := getXdsResources(project, messages, services) + xdsResources, err := getXdsResources(version, messages, services) if err != nil { return nil, err } - project.Resources = resources - project.ResourceGroups = resourceGroups - project.XDSResources = xdsResources + version.Resources = resources + version.XDSResources = xdsResources - return project, nil + return version, nil } func goName(n string) string { diff --git a/pkg/code-generator/parser/parser_resource.go b/pkg/code-generator/parser/parser_resource.go index 6a47bcd72..c03be36e0 100644 --- a/pkg/code-generator/parser/parser_resource.go +++ b/pkg/code-generator/parser/parser_resource.go @@ -24,7 +24,7 @@ const ( shortNameDeclaration = "@solo-kit:resource.short_name=" // Deprecated, use Message Option (core.solo.io.resource).plural_name pluralNameDeclaration = "@solo-kit:resource.plural_name=" - // Deprecated, use projectConfig.ResourceGroups + // Deprecated, use versionConfig.ResourceGroups resourceGroupsDeclaration = "@solo-kit:resource.resource_groups=" ) @@ -34,16 +34,9 @@ type ProtoMessageWrapper struct { Message *protokit.Descriptor } -func getResource(resources []*model.Resource, project model.ProjectConfig, cfg model.ResourceConfig) (*model.Resource, error) { +func getResource(resources []*model.Resource, cfg model.ResourceConfig) (*model.Resource, error) { matches := func(res *model.Resource) bool { - if res.Name == cfg.ResourceName && - (res.ProtoPackage == cfg.ResourcePackage || res.GoPackage == cfg.ResourcePackage) { - if cfg.ResourceVersion == "" { - return true - } - return cfg.ResourceVersion == res.Version - } - return false + return res.Name == cfg.ResourceName && (res.ProtoPackage == cfg.ResourcePackage || res.GoPackage == cfg.ResourcePackage) } // collect all resources that match on package and name @@ -53,46 +46,37 @@ func getResource(resources []*model.Resource, project model.ProjectConfig, cfg m possibleResources = append(possibleResources, res) } } - switch len(possibleResources) { - case 1: - return possibleResources[0], nil - case 0: + if len(possibleResources) == 0 { return nil, errors.Errorf("getting resource: message %v not found", cfg) } - // default to using the version matching the project itself - // only works for this project's resources - for _, res := range possibleResources { - if res.GoPackage == project.GoPackage { - return res, nil - } - } - return nil, errors.Errorf("found %v resources found which match %v, try specifying a version", len(possibleResources), cfg) + + return possibleResources[0], nil } -func getResources(project *model.Project, allProjectConfigs []*model.ProjectConfig, messages []ProtoMessageWrapper) ([]*model.Resource, []*model.ResourceGroup, error) { +func getResources(version *model.Version, apiGroup *model.ApiGroup, messages []ProtoMessageWrapper) ([]*model.Resource, error) { var ( resources []*model.Resource ) for _, msg := range messages { resource, err := describeResource(msg) if err != nil { - return nil, nil, err + return nil, err } if resource == nil { // not a solo-kit resource, ignore continue } - for _, projectCfg := range allProjectConfigs { - if projectCfg.IsOurProto(resource.Filename) { - resource.Version = projectCfg.Version + for _, vc := range apiGroup.VersionConfigs { + if vc.IsOurProto(resource.Filename) { + resource.Version = vc.Version break } } - resource.Project = project + resource.ParentVersion = version resources = append(resources, resource) } - for _, custom := range project.ProjectConfig.CustomResources { + for _, custom := range version.VersionConfig.CustomResources { impPrefix := strings.Replace(custom.Package, "/", "_", -1) impPrefix = strings.Replace(impPrefix, ".", "_", -1) impPrefix = strings.Replace(impPrefix, "-", "_", -1) @@ -104,29 +88,32 @@ func getResources(project *model.Project, allProjectConfigs []*model.ProjectConf ClusterScoped: custom.ClusterScoped, CustomImportPrefix: impPrefix, SkipDocsGen: true, - Project: project, + ParentVersion: version, IsCustom: true, CustomResource: custom, }) } + return resources, nil +} + +func GetResourceGroups(apiGroup *model.ApiGroup, resources []*model.Resource) ([]*model.ResourceGroup, error) { var ( resourceGroups []*model.ResourceGroup ) - for groupName, resourcesCfg := range project.ProjectConfig.ResourceGroups { + for groupName, resourcesCfg := range apiGroup.ResourceGroups { var resourcesForGroup []*model.Resource for _, resourceCfg := range resourcesCfg { - resource, err := getResource(resources, project.ProjectConfig, resourceCfg) + resource, err := getResource(resources, resourceCfg) if err != nil { - return nil, nil, err + return nil, err } var importPrefix string - if !project.ProjectConfig.IsOurProto(resource.Filename) && !resource.IsCustom { - importPrefix = resource.ProtoPackage - } else if resource.IsCustom && resource.CustomResource.Imported { - // If is custom resource from a different project use import prefix + if !resource.IsCustom { + importPrefix = resource.ProtoPackage + "_" + resource.ParentVersion.VersionConfig.Version + } else { importPrefix = resource.CustomImportPrefix } @@ -140,7 +127,7 @@ func getResources(project *model.Project, allProjectConfigs []*model.ProjectConf rg := &model.ResourceGroup{ Name: groupName, GoName: goName(groupName), - Project: project, + ApiGroup: apiGroup, Resources: resourcesForGroup, } for _, res := range resourcesForGroup { @@ -150,7 +137,7 @@ func getResources(project *model.Project, allProjectConfigs []*model.ProjectConf imports := make(map[string]string) for _, res := range rg.Resources { // only generate files for the resources in our group, otherwise we import - if res.GoPackage != rg.Project.ProjectConfig.GoPackage { + if res.GoPackage != rg.ApiGroup.ResourceGroupGoPackage { // add import imports[strings.TrimSuffix(res.ImportPrefix, ".")] = res.GoPackage } @@ -179,7 +166,7 @@ func getResources(project *model.Project, allProjectConfigs []*model.ProjectConf sort.SliceStable(resourceGroups, func(i, j int) bool { return resourceGroups[i].Name < resourceGroups[j].Name }) - return resources, resourceGroups, nil + return resourceGroups, nil } func describeResource(messageWrapper ProtoMessageWrapper) (*model.Resource, error) { diff --git a/pkg/code-generator/parser/parser_xds.go b/pkg/code-generator/parser/parser_xds.go index e5dcb1acc..a50acd0a3 100644 --- a/pkg/code-generator/parser/parser_xds.go +++ b/pkg/code-generator/parser/parser_xds.go @@ -32,7 +32,7 @@ type xdsMessage struct { fileName string } -func getXdsResources(project *model.Project, messages []ProtoMessageWrapper, services []*protokit.ServiceDescriptor) ([]*model.XDSResource, error) { +func getXdsResources(version *model.Version, messages []ProtoMessageWrapper, services []*protokit.ServiceDescriptor) ([]*model.XDSResource, error) { var msgs []*xdsMessage var svcs []*xdsService @@ -45,7 +45,7 @@ func getXdsResources(project *model.Project, messages []ProtoMessageWrapper, ser // message is not a resource continue } - if msg.protoPackage != project.ProtoPackage { + if msg.protoPackage != version.ProtoPackage { continue } msgs = append(msgs, msg) @@ -59,7 +59,7 @@ func getXdsResources(project *model.Project, messages []ProtoMessageWrapper, ser // message is not a resource continue } - if service.protoPackage != project.ProtoPackage { + if service.protoPackage != version.ProtoPackage { continue } svcs = append(svcs, service) @@ -67,10 +67,10 @@ func getXdsResources(project *model.Project, messages []ProtoMessageWrapper, ser // match time! // for every service, match it with a config message. - return processMessagesAndServices(project, msgs, svcs) + return processMessagesAndServices(version, msgs, svcs) } -func processMessagesAndServices(project *model.Project, msgs []*xdsMessage, svcs []*xdsService) ([]*model.XDSResource, error) { +func processMessagesAndServices(version *model.Version, msgs []*xdsMessage, svcs []*xdsService) ([]*model.XDSResource, error) { var resources []*model.XDSResource for _, svc := range svcs { var message *xdsMessage @@ -86,13 +86,13 @@ func processMessagesAndServices(project *model.Project, msgs []*xdsMessage, svcs } resources = append(resources, &model.XDSResource{ - MessageType: message.name, - Name: svc.name, - NameField: message.nameField, - NoReferences: message.noReferences, - ProtoPackage: message.protoPackage, - Filename: message.fileName, - Project: project, + MessageType: message.name, + Name: svc.name, + NameField: message.nameField, + NoReferences: message.noReferences, + ProtoPackage: message.protoPackage, + Filename: message.fileName, + ParentVersion: version, }) } diff --git a/pkg/multicluster/group/group_suite_test.go b/pkg/multicluster/group/group_suite_test.go new file mode 100644 index 000000000..8d2ddf537 --- /dev/null +++ b/pkg/multicluster/group/group_suite_test.go @@ -0,0 +1,15 @@ +// Code generated by solo-kit. DO NOT EDIT. + +package group + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +func TestGroup(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Group Suite") +} diff --git a/pkg/multicluster/v1/kubeconfigs_event_loop.sk.go b/pkg/multicluster/group/kubeconfigs_event_loop.sk.go similarity index 93% rename from pkg/multicluster/v1/kubeconfigs_event_loop.sk.go rename to pkg/multicluster/group/kubeconfigs_event_loop.sk.go index 3fe79e1a9..994b3229d 100644 --- a/pkg/multicluster/v1/kubeconfigs_event_loop.sk.go +++ b/pkg/multicluster/group/kubeconfigs_event_loop.sk.go @@ -1,6 +1,6 @@ // Code generated by solo-kit. DO NOT EDIT. -package v1 +package group import ( "context" @@ -46,7 +46,7 @@ func NewKubeconfigsEventLoop(emitter KubeconfigsEmitter, syncer KubeconfigsSynce func (el *kubeconfigsEventLoop) Run(namespaces []string, opts clients.WatchOpts) (<-chan error, error) { opts = opts.WithDefaults() - opts.Ctx = contextutils.WithLogger(opts.Ctx, "v1.event_loop") + opts.Ctx = contextutils.WithLogger(opts.Ctx, "group.event_loop") logger := contextutils.LoggerFrom(opts.Ctx) logger.Infof("event loop started") @@ -56,7 +56,7 @@ func (el *kubeconfigsEventLoop) Run(namespaces []string, opts clients.WatchOpts) if err != nil { return nil, errors.Wrapf(err, "starting snapshot watch") } - go errutils.AggregateErrs(opts.Ctx, errs, emitterErrs, "v1.emitter errors") + go errutils.AggregateErrs(opts.Ctx, errs, emitterErrs, "group.emitter errors") go func() { // create a new context for each loop, cancel it before each loop var cancel context.CancelFunc = func() {} diff --git a/pkg/multicluster/v1/kubeconfigs_event_loop_test.go b/pkg/multicluster/group/kubeconfigs_event_loop_test.go similarity index 78% rename from pkg/multicluster/v1/kubeconfigs_event_loop_test.go rename to pkg/multicluster/group/kubeconfigs_event_loop_test.go index 5e0573c93..1531804d6 100644 --- a/pkg/multicluster/v1/kubeconfigs_event_loop_test.go +++ b/pkg/multicluster/group/kubeconfigs_event_loop_test.go @@ -2,13 +2,15 @@ // +build solokit -package v1 +package group import ( "context" "sync" "time" + github_com_solo_io_solo_kit_api_multicluster_v1 "github.com/solo-io/solo-kit/api/multicluster/v1" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/solo-io/solo-kit/pkg/api/v1/clients" @@ -28,13 +30,13 @@ var _ = Describe("KubeconfigsEventLoop", func() { kubeConfigClientFactory := &factory.MemoryResourceClientFactory{ Cache: memory.NewInMemoryResourceCache(), } - kubeConfigClient, err := NewKubeConfigClient(kubeConfigClientFactory) + kubeConfigClient, err := github_com_solo_io_solo_kit_api_multicluster_v1.NewKubeConfigClient(kubeConfigClientFactory) Expect(err).NotTo(HaveOccurred()) emitter = NewKubeconfigsEmitter(kubeConfigClient) }) It("runs sync function on a new snapshot", func() { - _, err = emitter.KubeConfig().Write(NewKubeConfig(namespace, "jerry"), clients.WriteOpts{}) + _, err = emitter.KubeConfig().Write(github_com_solo_io_solo_kit_api_multicluster_v1.NewKubeConfig(namespace, "jerry"), clients.WriteOpts{}) Expect(err).NotTo(HaveOccurred()) sync := &mockKubeconfigsSyncer{} el := NewKubeconfigsEventLoop(emitter, sync) diff --git a/pkg/multicluster/v1/kubeconfigs_simple_event_loop.sk.go b/pkg/multicluster/group/kubeconfigs_simple_event_loop.sk.go similarity index 95% rename from pkg/multicluster/v1/kubeconfigs_simple_event_loop.sk.go rename to pkg/multicluster/group/kubeconfigs_simple_event_loop.sk.go index 658724dd9..46cf4ff4e 100644 --- a/pkg/multicluster/v1/kubeconfigs_simple_event_loop.sk.go +++ b/pkg/multicluster/group/kubeconfigs_simple_event_loop.sk.go @@ -1,6 +1,6 @@ // Code generated by solo-kit. DO NOT EDIT. -package v1 +package group import ( "context" @@ -43,7 +43,7 @@ func NewKubeconfigsSimpleEventLoop(emitter KubeconfigsSimpleEmitter, syncers ... } func (el *kubeconfigsSimpleEventLoop) Run(ctx context.Context) (<-chan error, error) { - ctx = contextutils.WithLogger(ctx, "v1.event_loop") + ctx = contextutils.WithLogger(ctx, "group.event_loop") logger := contextutils.LoggerFrom(ctx) logger.Infof("event loop started") @@ -54,7 +54,7 @@ func (el *kubeconfigsSimpleEventLoop) Run(ctx context.Context) (<-chan error, er return nil, errors.Wrapf(err, "starting snapshot watch") } - go errutils.AggregateErrs(ctx, errs, emitterErrs, "v1.emitter errors") + go errutils.AggregateErrs(ctx, errs, emitterErrs, "group.emitter errors") go func() { // create a new context for each syncer for each loop, cancel each before each loop syncerCancels := make(map[KubeconfigsSyncer]context.CancelFunc) diff --git a/pkg/multicluster/v1/kubeconfigs_snapshot.sk.go b/pkg/multicluster/group/kubeconfigs_snapshot.sk.go similarity index 87% rename from pkg/multicluster/v1/kubeconfigs_snapshot.sk.go rename to pkg/multicluster/group/kubeconfigs_snapshot.sk.go index 46ad8201c..adf1b0d70 100644 --- a/pkg/multicluster/v1/kubeconfigs_snapshot.sk.go +++ b/pkg/multicluster/group/kubeconfigs_snapshot.sk.go @@ -1,16 +1,18 @@ // Code generated by solo-kit. DO NOT EDIT. -package v1 +package group import ( "fmt" + github_com_solo_io_solo_kit_api_multicluster_v1 "github.com/solo-io/solo-kit/api/multicluster/v1" + "github.com/solo-io/go-utils/hashutils" "go.uber.org/zap" ) type KubeconfigsSnapshot struct { - Kubeconfigs KubeConfigList + Kubeconfigs github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigList } func (s KubeconfigsSnapshot) Clone() KubeconfigsSnapshot { diff --git a/pkg/multicluster/v1/kubeconfigs_snapshot_emitter.sk.go b/pkg/multicluster/group/kubeconfigs_snapshot_emitter.sk.go similarity index 84% rename from pkg/multicluster/v1/kubeconfigs_snapshot_emitter.sk.go rename to pkg/multicluster/group/kubeconfigs_snapshot_emitter.sk.go index c11268612..e87dc7980 100644 --- a/pkg/multicluster/v1/kubeconfigs_snapshot_emitter.sk.go +++ b/pkg/multicluster/group/kubeconfigs_snapshot_emitter.sk.go @@ -1,11 +1,13 @@ // Code generated by solo-kit. DO NOT EDIT. -package v1 +package group import ( "sync" "time" + github_com_solo_io_solo_kit_api_multicluster_v1 "github.com/solo-io/solo-kit/api/multicluster/v1" + "go.opencensus.io/stats" "go.opencensus.io/stats/view" "go.opencensus.io/tag" @@ -49,15 +51,15 @@ func init() { type KubeconfigsEmitter interface { Register() error - KubeConfig() KubeConfigClient + KubeConfig() github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigClient Snapshots(watchNamespaces []string, opts clients.WatchOpts) (<-chan *KubeconfigsSnapshot, <-chan error, error) } -func NewKubeconfigsEmitter(kubeConfigClient KubeConfigClient) KubeconfigsEmitter { +func NewKubeconfigsEmitter(kubeConfigClient github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigClient) KubeconfigsEmitter { return NewKubeconfigsEmitterWithEmit(kubeConfigClient, make(chan struct{})) } -func NewKubeconfigsEmitterWithEmit(kubeConfigClient KubeConfigClient, emit <-chan struct{}) KubeconfigsEmitter { +func NewKubeconfigsEmitterWithEmit(kubeConfigClient github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigClient, emit <-chan struct{}) KubeconfigsEmitter { return &kubeconfigsEmitter{ kubeConfig: kubeConfigClient, forceEmit: emit, @@ -66,7 +68,7 @@ func NewKubeconfigsEmitterWithEmit(kubeConfigClient KubeConfigClient, emit <-cha type kubeconfigsEmitter struct { forceEmit <-chan struct{} - kubeConfig KubeConfigClient + kubeConfig github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigClient } func (c *kubeconfigsEmitter) Register() error { @@ -76,7 +78,7 @@ func (c *kubeconfigsEmitter) Register() error { return nil } -func (c *kubeconfigsEmitter) KubeConfig() KubeConfigClient { +func (c *kubeconfigsEmitter) KubeConfig() github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigClient { return c.kubeConfig } @@ -98,12 +100,12 @@ func (c *kubeconfigsEmitter) Snapshots(watchNamespaces []string, opts clients.Wa ctx := opts.Ctx /* Create channel for KubeConfig */ type kubeConfigListWithNamespace struct { - list KubeConfigList + list github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigList namespace string } kubeConfigChan := make(chan kubeConfigListWithNamespace) - var initialKubeConfigList KubeConfigList + var initialKubeConfigList github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigList currentSnapshot := KubeconfigsSnapshot{} @@ -169,7 +171,7 @@ func (c *kubeconfigsEmitter) Snapshots(watchNamespaces []string, opts clients.Wa stats.Record(ctx, mKubeconfigsSnapshotMissed.M(1)) } } - kubeconfigsByNamespace := make(map[string]KubeConfigList) + kubeconfigsByNamespace := make(map[string]github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigList) for { record := func() { stats.Record(ctx, mKubeconfigsSnapshotIn.M(1)) } @@ -192,7 +194,7 @@ func (c *kubeconfigsEmitter) Snapshots(watchNamespaces []string, opts clients.Wa // merge lists by namespace kubeconfigsByNamespace[namespace] = kubeConfigNamespacedList.list - var kubeConfigList KubeConfigList + var kubeConfigList github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigList for _, kubeconfigs := range kubeconfigsByNamespace { kubeConfigList = append(kubeConfigList, kubeconfigs...) } diff --git a/pkg/multicluster/v1/kubeconfigs_snapshot_emitter_test.go b/pkg/multicluster/group/kubeconfigs_snapshot_emitter_test.go similarity index 64% rename from pkg/multicluster/v1/kubeconfigs_snapshot_emitter_test.go rename to pkg/multicluster/group/kubeconfigs_snapshot_emitter_test.go index aa576b20c..6f0c13562 100644 --- a/pkg/multicluster/v1/kubeconfigs_snapshot_emitter_test.go +++ b/pkg/multicluster/group/kubeconfigs_snapshot_emitter_test.go @@ -2,13 +2,15 @@ // +build solokit -package v1 +package group import ( "context" "os" "time" + github_com_solo_io_solo_kit_api_multicluster_v1 "github.com/solo-io/solo-kit/api/multicluster/v1" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/solo-io/go-utils/kubeutils" @@ -26,7 +28,7 @@ import ( _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" ) -var _ = Describe("V1Emitter", func() { +var _ = Describe("GroupEmitter", func() { if os.Getenv("RUN_KUBE_TESTS") != "1" { log.Printf("This test creates kubernetes resources and is disabled by default. To enable, set RUN_KUBE_TESTS=1 in your env.") return @@ -37,7 +39,7 @@ var _ = Describe("V1Emitter", func() { name1, name2 = "angela" + helpers.RandString(3), "bob" + helpers.RandString(3) kube kubernetes.Interface emitter KubeconfigsEmitter - kubeConfigClient KubeConfigClient + kubeConfigClient github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigClient ) BeforeEach(func() { @@ -51,7 +53,7 @@ var _ = Describe("V1Emitter", func() { Cache: memory.NewInMemoryResourceCache(), } - kubeConfigClient, err = NewKubeConfigClient(kubeConfigClientFactory) + kubeConfigClient, err = github_com_solo_io_solo_kit_api_multicluster_v1.NewKubeConfigClient(kubeConfigClientFactory) Expect(err).NotTo(HaveOccurred()) emitter = NewKubeconfigsEmitter(kubeConfigClient) }) @@ -76,7 +78,7 @@ var _ = Describe("V1Emitter", func() { KubeConfig */ - assertSnapshotkubeconfigs := func(expectkubeconfigs KubeConfigList, unexpectkubeconfigs KubeConfigList) { + assertSnapshotkubeconfigs := func(expectkubeconfigs github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigList, unexpectkubeconfigs github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigList) { drain: for { select { @@ -102,32 +104,32 @@ var _ = Describe("V1Emitter", func() { } } } - kubeConfig1a, err := kubeConfigClient.Write(NewKubeConfig(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + kubeConfig1a, err := kubeConfigClient.Write(github_com_solo_io_solo_kit_api_multicluster_v1.NewKubeConfig(namespace1, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - kubeConfig1b, err := kubeConfigClient.Write(NewKubeConfig(namespace2, name1), clients.WriteOpts{Ctx: ctx}) + kubeConfig1b, err := kubeConfigClient.Write(github_com_solo_io_solo_kit_api_multicluster_v1.NewKubeConfig(namespace2, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotkubeconfigs(KubeConfigList{kubeConfig1a, kubeConfig1b}, nil) - kubeConfig2a, err := kubeConfigClient.Write(NewKubeConfig(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + assertSnapshotkubeconfigs(github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigList{kubeConfig1a, kubeConfig1b}, nil) + kubeConfig2a, err := kubeConfigClient.Write(github_com_solo_io_solo_kit_api_multicluster_v1.NewKubeConfig(namespace1, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - kubeConfig2b, err := kubeConfigClient.Write(NewKubeConfig(namespace2, name2), clients.WriteOpts{Ctx: ctx}) + kubeConfig2b, err := kubeConfigClient.Write(github_com_solo_io_solo_kit_api_multicluster_v1.NewKubeConfig(namespace2, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotkubeconfigs(KubeConfigList{kubeConfig1a, kubeConfig1b, kubeConfig2a, kubeConfig2b}, nil) + assertSnapshotkubeconfigs(github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigList{kubeConfig1a, kubeConfig1b, kubeConfig2a, kubeConfig2b}, nil) err = kubeConfigClient.Delete(kubeConfig2a.GetMetadata().Namespace, kubeConfig2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) err = kubeConfigClient.Delete(kubeConfig2b.GetMetadata().Namespace, kubeConfig2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotkubeconfigs(KubeConfigList{kubeConfig1a, kubeConfig1b}, KubeConfigList{kubeConfig2a, kubeConfig2b}) + assertSnapshotkubeconfigs(github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigList{kubeConfig1a, kubeConfig1b}, github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigList{kubeConfig2a, kubeConfig2b}) err = kubeConfigClient.Delete(kubeConfig1a.GetMetadata().Namespace, kubeConfig1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) err = kubeConfigClient.Delete(kubeConfig1b.GetMetadata().Namespace, kubeConfig1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotkubeconfigs(nil, KubeConfigList{kubeConfig1a, kubeConfig1b, kubeConfig2a, kubeConfig2b}) + assertSnapshotkubeconfigs(nil, github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigList{kubeConfig1a, kubeConfig1b, kubeConfig2a, kubeConfig2b}) }) It("tracks snapshots on changes to any resource using AllNamespace", func() { ctx := context.Background() @@ -146,7 +148,7 @@ var _ = Describe("V1Emitter", func() { KubeConfig */ - assertSnapshotkubeconfigs := func(expectkubeconfigs KubeConfigList, unexpectkubeconfigs KubeConfigList) { + assertSnapshotkubeconfigs := func(expectkubeconfigs github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigList, unexpectkubeconfigs github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigList) { drain: for { select { @@ -172,31 +174,31 @@ var _ = Describe("V1Emitter", func() { } } } - kubeConfig1a, err := kubeConfigClient.Write(NewKubeConfig(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + kubeConfig1a, err := kubeConfigClient.Write(github_com_solo_io_solo_kit_api_multicluster_v1.NewKubeConfig(namespace1, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - kubeConfig1b, err := kubeConfigClient.Write(NewKubeConfig(namespace2, name1), clients.WriteOpts{Ctx: ctx}) + kubeConfig1b, err := kubeConfigClient.Write(github_com_solo_io_solo_kit_api_multicluster_v1.NewKubeConfig(namespace2, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotkubeconfigs(KubeConfigList{kubeConfig1a, kubeConfig1b}, nil) - kubeConfig2a, err := kubeConfigClient.Write(NewKubeConfig(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + assertSnapshotkubeconfigs(github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigList{kubeConfig1a, kubeConfig1b}, nil) + kubeConfig2a, err := kubeConfigClient.Write(github_com_solo_io_solo_kit_api_multicluster_v1.NewKubeConfig(namespace1, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - kubeConfig2b, err := kubeConfigClient.Write(NewKubeConfig(namespace2, name2), clients.WriteOpts{Ctx: ctx}) + kubeConfig2b, err := kubeConfigClient.Write(github_com_solo_io_solo_kit_api_multicluster_v1.NewKubeConfig(namespace2, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotkubeconfigs(KubeConfigList{kubeConfig1a, kubeConfig1b, kubeConfig2a, kubeConfig2b}, nil) + assertSnapshotkubeconfigs(github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigList{kubeConfig1a, kubeConfig1b, kubeConfig2a, kubeConfig2b}, nil) err = kubeConfigClient.Delete(kubeConfig2a.GetMetadata().Namespace, kubeConfig2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) err = kubeConfigClient.Delete(kubeConfig2b.GetMetadata().Namespace, kubeConfig2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotkubeconfigs(KubeConfigList{kubeConfig1a, kubeConfig1b}, KubeConfigList{kubeConfig2a, kubeConfig2b}) + assertSnapshotkubeconfigs(github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigList{kubeConfig1a, kubeConfig1b}, github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigList{kubeConfig2a, kubeConfig2b}) err = kubeConfigClient.Delete(kubeConfig1a.GetMetadata().Namespace, kubeConfig1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) err = kubeConfigClient.Delete(kubeConfig1b.GetMetadata().Namespace, kubeConfig1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotkubeconfigs(nil, KubeConfigList{kubeConfig1a, kubeConfig1b, kubeConfig2a, kubeConfig2b}) + assertSnapshotkubeconfigs(nil, github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfigList{kubeConfig1a, kubeConfig1b, kubeConfig2a, kubeConfig2b}) }) }) diff --git a/pkg/multicluster/v1/kubeconfigs_snapshot_simple_emitter.sk.go b/pkg/multicluster/group/kubeconfigs_snapshot_simple_emitter.sk.go similarity index 93% rename from pkg/multicluster/v1/kubeconfigs_snapshot_simple_emitter.sk.go rename to pkg/multicluster/group/kubeconfigs_snapshot_simple_emitter.sk.go index 4d9518ea2..a23ec9680 100644 --- a/pkg/multicluster/v1/kubeconfigs_snapshot_simple_emitter.sk.go +++ b/pkg/multicluster/group/kubeconfigs_snapshot_simple_emitter.sk.go @@ -1,12 +1,14 @@ // Code generated by solo-kit. DO NOT EDIT. -package v1 +package group import ( "context" "fmt" "time" + github_com_solo_io_solo_kit_api_multicluster_v1 "github.com/solo-io/solo-kit/api/multicluster/v1" + "go.opencensus.io/stats" "github.com/solo-io/go-utils/errutils" @@ -81,7 +83,7 @@ func (c *kubeconfigsSimpleEmitter) Snapshots(ctx context.Context) (<-chan *Kubec currentSnapshot = KubeconfigsSnapshot{} for _, res := range untypedList { switch typed := res.(type) { - case *KubeConfig: + case *github_com_solo_io_solo_kit_api_multicluster_v1.KubeConfig: currentSnapshot.Kubeconfigs = append(currentSnapshot.Kubeconfigs, typed) default: select { diff --git a/pkg/multicluster/v1/multicluster.solo.io_suite_test.go b/pkg/multicluster/v1/multicluster.solo.io_suite_test.go index cfb6e05a4..a4d66f02d 100644 --- a/pkg/multicluster/v1/multicluster.solo.io_suite_test.go +++ b/pkg/multicluster/v1/multicluster.solo.io_suite_test.go @@ -36,13 +36,13 @@ var ( Expect(err).NotTo(HaveOccurred()) clientset, err := apiexts.NewForConfig(cfg) Expect(err).NotTo(HaveOccurred()) - err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("anothermockresources.testing.solo.io", &metav1.DeleteOptions{}) - testutils.ErrorNotOccuredOrNotFound(err) - err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("clusterresources.testing.solo.io", &metav1.DeleteOptions{}) + err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("mocks.testing.solo.io", &metav1.DeleteOptions{}) testutils.ErrorNotOccuredOrNotFound(err) err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("fakes.testing.solo.io", &metav1.DeleteOptions{}) testutils.ErrorNotOccuredOrNotFound(err) - err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("mocks.testing.solo.io", &metav1.DeleteOptions{}) + err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("anothermockresources.testing.solo.io", &metav1.DeleteOptions{}) + testutils.ErrorNotOccuredOrNotFound(err) + err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("clusterresources.testing.solo.io", &metav1.DeleteOptions{}) testutils.ErrorNotOccuredOrNotFound(err) Expect(lock.ReleaseLock()).NotTo(HaveOccurred()) }) diff --git a/test/mocks/api/doc/testing.solo.io.project.sk.md b/test/mocks/api/doc/testing.solo.io.project.sk.md deleted file mode 100644 index cfc780b2f..000000000 --- a/test/mocks/api/doc/testing.solo.io.project.sk.md +++ /dev/null @@ -1,25 +0,0 @@ - ---- -title: "testing.solo.io.project" -weight: 5 ---- - - - - - -### API Reference for Solo-Kit Testing - -API Version: `testing.solo.io.v1` - - - -### API Resources: -- [AnotherMockResource](../github.com/solo-io/solo-kit/test/mocks/api/v1/more_mock_resources.proto.sk#anothermockresource) -- [ClusterResource](../github.com/solo-io/solo-kit/test/mocks/api/v1/more_mock_resources.proto.sk#clusterresource) -- [FakeResource](../github.com/solo-io/solo-kit/test/mocks/api/v1/mock_resources.proto.sk#fakeresource) -- [MockResource](../github.com/solo-io/solo-kit/test/mocks/api/v1/mock_resources.proto.sk#mockresource) - - - - diff --git a/test/mocks/api/solo-kit.json b/test/mocks/api/solo-kit.json new file mode 100644 index 000000000..1b49e96df --- /dev/null +++ b/test/mocks/api/solo-kit.json @@ -0,0 +1,66 @@ +{ + "title": "Solo-Kit Testing", + "description": "mock solo-kit project", + "api_group": { + "name": "testing.solo.io", + "docs_dir": "test/mocks/docs", + "conversion_go_package": "github.com/solo-io/solo-kit/test/mocks/conversion", + "resource_group_go_package": "github.com/solo-io/solo-kit/test/mocks/group", + "imports": [ + "github.com/solo-io/solo-kit/api/external/kubernetes", + "github.com/solo-io/solo-kit/test/mocks/api" + ], + "resource_groups": { + "testing.solo.io": [ + { + "name": "MockResource", + "package": "testing.solo.io", + "version": "v1" + }, + { + "name": "FakeResource", + "package": "testing.solo.io", + "version": "v1alpha1" + }, + { + "name": "AnotherMockResource", + "package": "testing.solo.io", + "version": "v1" + }, + { + "name": "ClusterResource", + "package": "testing.solo.io", + "version": "v1" + }, + { + "name": "MockCustomType", + "package": "github.com/solo-io/solo-kit/test/mocks/v1" + }, + { + "name": "Pod", + "package": "github.com/solo-io/solo-kit/pkg/api/v1/resources/common/kubernetes" + } + ] + }, + "version_configs": [ + { + "version": "v2alpha1" + }, + { + "version": "v1alpha1", + "crd_group_override": "crds.testing.solo.io" + }, + { + "version": "v1", + "custom_resources": [ + { + "package": "github.com/solo-io/solo-kit/test/mocks/api/v1/customtype", + "type": "MockCustomType", + "plural_name": "mcts", + "short_name": "mct" + } + ] + } + ] + } +} \ No newline at end of file diff --git a/test/mocks/api/v1/mock_resources.proto b/test/mocks/api/v1/mock_resources.proto index 575def583..f4e7de8b1 100644 --- a/test/mocks/api/v1/mock_resources.proto +++ b/test/mocks/api/v1/mock_resources.proto @@ -63,6 +63,7 @@ message FakeResource { uint32 count = 1; core.solo.io.Metadata metadata = 7 [(gogoproto.nullable) = false]; + core.solo.io.Status status = 6 [(gogoproto.nullable) = false]; } /* diff --git a/test/mocks/api/v1/solo-kit.json b/test/mocks/api/v1/solo-kit.json deleted file mode 100644 index 801367bc9..000000000 --- a/test/mocks/api/v1/solo-kit.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "title": "Solo-Kit Testing", - "name": "testing.solo.io", - "version": "v1", - "docs_dir": "../doc", - "imports": [ - "github.com/solo-io/solo-kit/api/external/kubernetes" - ], - "custom_resources": [ - { - "package": "github.com/solo-io/solo-kit/test/mocks/api/v1/customtype", - "type": "MockCustomType", - "plural_name": "mcts", - "short_name": "mct" - } - ], - "resource_groups": { - "testing.solo.io": [ - { - "name": "MockResource", - "package": "testing.solo.io" - }, - { - "name": "FakeResource", - "package": "testing.solo.io" - }, - { - "name": "AnotherMockResource", - "package": "testing.solo.io" - }, - { - "name": "ClusterResource", - "package": "testing.solo.io" - }, - { - "name": "MockCustomType", - "package": "github.com/solo-io/solo-kit/test/mocks/api/v1/customtype" - }, - { - "name": "Pod", - "package": "github.com/solo-io/solo-kit/pkg/api/v1/resources/common/kubernetes" - } - ] - } -} \ No newline at end of file diff --git a/test/mocks/api/v1alpha1/solo-kit.json b/test/mocks/api/v1alpha1/solo-kit.json deleted file mode 100644 index c90ef0c26..000000000 --- a/test/mocks/api/v1alpha1/solo-kit.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "title": "Solo-Kit Testing", - "name": "testing.solo.io", - "version": "v1alpha1", - "docs_dir": "../doc", - "crd_group_override": "crds.testing.solo.io", - "resource_groups": { - "testing.solo.io": [ - { - "name": "MockResource", - "package": "testing.solo.io" - } - ] - } -} \ No newline at end of file diff --git a/test/mocks/api/v2alpha1/solo-kit.json b/test/mocks/api/v2alpha1/solo-kit.json deleted file mode 100644 index fd99b3e8a..000000000 --- a/test/mocks/api/v2alpha1/solo-kit.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "title": "Solo-Kit Testing v2alpha1", - "name": "testing.solo.io", - "version": "v2alpha1", - "resource_groups": { - "testing.solo.io": [ - { - "name": "MockResource", - "package": "testing.solo.io", - "version": "v2alpha1" - }, - { - "name": "FakeResource", - "package": "testing.solo.io", - "version": "v1" - } - ] - } -} \ No newline at end of file diff --git a/test/mocks/conversion/conversion_suite_test.go b/test/mocks/conversion/conversion_suite_test.go new file mode 100644 index 000000000..ea9e7b2f1 --- /dev/null +++ b/test/mocks/conversion/conversion_suite_test.go @@ -0,0 +1,15 @@ +// Code generated by solo-kit. DO NOT EDIT. + +package conversion + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +func TestConversion(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Conversion Suite") +} diff --git a/test/mocks/conversion/resource_converter.sk.go b/test/mocks/conversion/resource_converter.sk.go new file mode 100644 index 000000000..790c74e57 --- /dev/null +++ b/test/mocks/conversion/resource_converter.sk.go @@ -0,0 +1,142 @@ +// Code generated by solo-kit. DO NOT EDIT. + +package conversion + +import ( + "github.com/solo-io/go-utils/versionutils/kubeapi" + "github.com/solo-io/solo-kit/pkg/api/v1/clients/kube/crd" + "github.com/solo-io/solo-kit/pkg/code-generator/codegen/templates/errors" + v1 "github.com/solo-io/solo-kit/test/mocks/v1" + v1alpha1 "github.com/solo-io/solo-kit/test/mocks/v1alpha1" + v2alpha1 "github.com/solo-io/solo-kit/test/mocks/v2alpha1" +) + +type FakeResourceUpConverter interface { + FromV1Alpha1ToV1(src *v1alpha1.FakeResource) *v1.FakeResource +} + +type FakeResourceDownConverter interface { + FromV1ToV1Alpha1(src *v1.FakeResource) *v1alpha1.FakeResource +} + +type fakeResourceConverter struct { + upConverter FakeResourceUpConverter + downConverter FakeResourceDownConverter +} + +func NewFakeResourceConverter(u FakeResourceUpConverter, d FakeResourceDownConverter) crd.Converter { + return &fakeResourceConverter{ + upConverter: u, + downConverter: d, + } +} + +func (c *fakeResourceConverter) Convert(src, dst crd.SoloKitCrd) error { + srcVersion, err := kubeapi.ParseVersion(src.GetObjectKind().GroupVersionKind().Version) + if err != nil { + return err + } + dstVersion, err := kubeapi.ParseVersion(dst.GetObjectKind().GroupVersionKind().Version) + if err != nil { + return err + } + + if srcVersion.GreaterThan(dstVersion) { + return c.convertDown(src, dst) + } else if srcVersion.LessThan(dstVersion) { + return c.convertUp(src, dst) + } + return crd.Copy(src, dst) +} + +func (c *fakeResourceConverter) convertUp(src, dst crd.SoloKitCrd) error { + if src.GetObjectKind().GroupVersionKind().Version == dst.GetObjectKind().GroupVersionKind().Version { + return crd.Copy(src, dst) + } + + switch t := src.(type) { + case *v1alpha1.FakeResource: + return c.convertUp(c.upConverter.FromV1Alpha1ToV1(t), dst) + } + return errors.UnrecognizedSourceType +} + +func (c *fakeResourceConverter) convertDown(src, dst crd.SoloKitCrd) error { + if src.GetObjectKind().GroupVersionKind().Version == dst.GetObjectKind().GroupVersionKind().Version { + return crd.Copy(src, dst) + } + + switch t := src.(type) { + case *v1.FakeResource: + return c.convertDown(c.downConverter.FromV1ToV1Alpha1(t), dst) + } + return errors.UnrecognizedSourceType +} + +type MockResourceUpConverter interface { + FromV1Alpha1ToV1(src *v1alpha1.MockResource) *v1.MockResource + FromV1ToV2Alpha1(src *v1.MockResource) *v2alpha1.MockResource +} + +type MockResourceDownConverter interface { + FromV1ToV1Alpha1(src *v1.MockResource) *v1alpha1.MockResource + FromV2Alpha1ToV1(src *v2alpha1.MockResource) *v1.MockResource +} + +type mockResourceConverter struct { + upConverter MockResourceUpConverter + downConverter MockResourceDownConverter +} + +func NewMockResourceConverter(u MockResourceUpConverter, d MockResourceDownConverter) crd.Converter { + return &mockResourceConverter{ + upConverter: u, + downConverter: d, + } +} + +func (c *mockResourceConverter) Convert(src, dst crd.SoloKitCrd) error { + srcVersion, err := kubeapi.ParseVersion(src.GetObjectKind().GroupVersionKind().Version) + if err != nil { + return err + } + dstVersion, err := kubeapi.ParseVersion(dst.GetObjectKind().GroupVersionKind().Version) + if err != nil { + return err + } + + if srcVersion.GreaterThan(dstVersion) { + return c.convertDown(src, dst) + } else if srcVersion.LessThan(dstVersion) { + return c.convertUp(src, dst) + } + return crd.Copy(src, dst) +} + +func (c *mockResourceConverter) convertUp(src, dst crd.SoloKitCrd) error { + if src.GetObjectKind().GroupVersionKind().Version == dst.GetObjectKind().GroupVersionKind().Version { + return crd.Copy(src, dst) + } + + switch t := src.(type) { + case *v1alpha1.MockResource: + return c.convertUp(c.upConverter.FromV1Alpha1ToV1(t), dst) + case *v1.MockResource: + return c.convertUp(c.upConverter.FromV1ToV2Alpha1(t), dst) + } + return errors.UnrecognizedSourceType +} + +func (c *mockResourceConverter) convertDown(src, dst crd.SoloKitCrd) error { + if src.GetObjectKind().GroupVersionKind().Version == dst.GetObjectKind().GroupVersionKind().Version { + return crd.Copy(src, dst) + } + + switch t := src.(type) { + case *v1.MockResource: + return c.convertDown(c.downConverter.FromV1ToV1Alpha1(t), dst) + case *v2alpha1.MockResource: + return c.convertDown(c.downConverter.FromV2Alpha1ToV1(t), dst) + } + return errors.UnrecognizedSourceType +} diff --git a/test/mocks/conversion/resource_converter_test.go b/test/mocks/conversion/resource_converter_test.go new file mode 100644 index 000000000..9656dbdfe --- /dev/null +++ b/test/mocks/conversion/resource_converter_test.go @@ -0,0 +1,112 @@ +// Code generated by solo-kit. DO NOT EDIT. + +// +build solokit + +package conversion_test + +import ( + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/solo-io/solo-kit/pkg/api/v1/clients/kube/crd" + "github.com/solo-io/solo-kit/pkg/api/v1/resources/core" + "github.com/solo-io/solo-kit/test/mocks/conversion" + v1 "github.com/solo-io/solo-kit/test/mocks/v1" + v1alpha1 "github.com/solo-io/solo-kit/test/mocks/v1alpha1" + v2alpha1 "github.com/solo-io/solo-kit/test/mocks/v2alpha1" +) + +var converter crd.Converter + +var _ = Describe("FakeResourceConverter", func() { + BeforeEach(func() { + converter = conversion.NewFakeResourceConverter(fakeResourceUpConverter{}, fakeResourceDownConverter{}) + }) + + Describe("Convert", func() { + It("works for noop conversions", func() { + src := &v1alpha1.FakeResource{Metadata: core.Metadata{Name: "test"}} + dst := &v1alpha1.FakeResource{} + err := converter.Convert(src, dst) + Expect(err).NotTo(HaveOccurred()) + Expect(dst.GetMetadata().Name).To(Equal("test")) + }) + + It("converts all the way up", func() { + src := &v1alpha1.FakeResource{} + dst := &v1.FakeResource{} + err := converter.Convert(src, dst) + Expect(err).NotTo(HaveOccurred()) + Expect(dst.GetMetadata().Name).To(Equal("v1")) + }) + + It("converts all the way down", func() { + src := &v1.FakeResource{} + dst := &v1alpha1.FakeResource{} + err := converter.Convert(src, dst) + Expect(err).NotTo(HaveOccurred()) + Expect(dst.GetMetadata().Name).To(Equal("v1alpha1")) + }) + }) +}) + +type fakeResourceUpConverter struct{} + +func (fakeResourceUpConverter) FromV1Alpha1ToV1(src *v1alpha1.FakeResource) *v1.FakeResource { + return &v1.FakeResource{Metadata: core.Metadata{Name: "v1"}} +} + +type fakeResourceDownConverter struct{} + +func (fakeResourceDownConverter) FromV1ToV1Alpha1(src *v1.FakeResource) *v1alpha1.FakeResource { + return &v1alpha1.FakeResource{Metadata: core.Metadata{Name: "v1alpha1"}} +} + +var _ = Describe("MockResourceConverter", func() { + BeforeEach(func() { + converter = conversion.NewMockResourceConverter(mockResourceUpConverter{}, mockResourceDownConverter{}) + }) + + Describe("Convert", func() { + It("works for noop conversions", func() { + src := &v1alpha1.MockResource{Metadata: core.Metadata{Name: "test"}} + dst := &v1alpha1.MockResource{} + err := converter.Convert(src, dst) + Expect(err).NotTo(HaveOccurred()) + Expect(dst.GetMetadata().Name).To(Equal("test")) + }) + + It("converts all the way up", func() { + src := &v1alpha1.MockResource{} + dst := &v2alpha1.MockResource{} + err := converter.Convert(src, dst) + Expect(err).NotTo(HaveOccurred()) + Expect(dst.GetMetadata().Name).To(Equal("v2alpha1")) + }) + + It("converts all the way down", func() { + src := &v2alpha1.MockResource{} + dst := &v1alpha1.MockResource{} + err := converter.Convert(src, dst) + Expect(err).NotTo(HaveOccurred()) + Expect(dst.GetMetadata().Name).To(Equal("v1alpha1")) + }) + }) +}) + +type mockResourceUpConverter struct{} + +func (mockResourceUpConverter) FromV1Alpha1ToV1(src *v1alpha1.MockResource) *v1.MockResource { + return &v1.MockResource{Metadata: core.Metadata{Name: "v1"}} +} +func (mockResourceUpConverter) FromV1ToV2Alpha1(src *v1.MockResource) *v2alpha1.MockResource { + return &v2alpha1.MockResource{Metadata: core.Metadata{Name: "v2alpha1"}} +} + +type mockResourceDownConverter struct{} + +func (mockResourceDownConverter) FromV1ToV1Alpha1(src *v1.MockResource) *v1alpha1.MockResource { + return &v1alpha1.MockResource{Metadata: core.Metadata{Name: "v1alpha1"}} +} +func (mockResourceDownConverter) FromV2Alpha1ToV1(src *v2alpha1.MockResource) *v1.MockResource { + return &v1.MockResource{Metadata: core.Metadata{Name: "v1"}} +} diff --git a/test/mocks/api/doc/envoy/api/v2/core/base.proto.sk.md b/test/mocks/docs/envoy/api/v2/core/base.proto.sk.md similarity index 85% rename from test/mocks/api/doc/envoy/api/v2/core/base.proto.sk.md rename to test/mocks/docs/envoy/api/v2/core/base.proto.sk.md index 36f29783c..518b83d42 100644 --- a/test/mocks/api/doc/envoy/api/v2/core/base.proto.sk.md +++ b/test/mocks/docs/envoy/api/v2/core/base.proto.sk.md @@ -1,29 +1,22 @@ - ---- -title: "base.proto" -weight: 5 ---- - - ### Package: `envoy.api.v2.core` #### Types: -- [Locality](#locality) -- [Node](#node) -- [Metadata](#metadata) -- [RuntimeUInt32](#runtimeuint32) -- [HeaderValue](#headervalue) -- [HeaderValueOption](#headervalueoption) -- [HeaderMap](#headermap) -- [DataSource](#datasource) -- [TransportSocket](#transportsocket) -- [SocketOption](#socketoption) -- [SocketState](#socketstate) -- [RuntimeFractionalPercent](#runtimefractionalpercent) -- [ControlPlane](#controlplane) +- [Locality](#Locality) +- [Node](#Node) +- [Metadata](#Metadata) +- [RuntimeUInt32](#RuntimeUInt32) +- [HeaderValue](#HeaderValue) +- [HeaderValueOption](#HeaderValueOption) +- [HeaderMap](#HeaderMap) +- [DataSource](#DataSource) +- [TransportSocket](#TransportSocket) +- [SocketOption](#SocketOption) +- [SocketState](#SocketState) +- [RuntimeFractionalPercent](#RuntimeFractionalPercent) +- [ControlPlane](#ControlPlane) @@ -31,8 +24,8 @@ weight: 5 ##### Enums: - - [RoutingPriority](#routingpriority) - - [RequestMethod](#requestmethod) + - [RoutingPriority](#RoutingPriority) + - [RequestMethod](#RequestMethod) @@ -43,7 +36,7 @@ weight: 5 --- -### Locality +### Locality Identifies location of where either Envoy runs or where upstream hosts run. @@ -65,7 +58,7 @@ Identifies location of where either Envoy runs or where upstream hosts run. --- -### Node +### Node Identifies a specific Envoy instance. The node identifier is presented to the @@ -86,14 +79,14 @@ configuration for serving. | `id` | `string` | An opaque node identifier for the Envoy node. This also provides the local service node name. It should be set if any of the following features are used: :ref:`statsd `, :ref:`CDS `, and :ref:`HTTP tracing `, either in this message or via :option:`--service-node`. | | | `cluster` | `string` | Defines the local service cluster name where Envoy is running. Though optional, it should be set if any of the following features are used: :ref:`statsd `, :ref:`health check cluster verification `, :ref:`runtime override directory `, :ref:`user agent addition `, :ref:`HTTP global rate limiting `, :ref:`CDS `, and :ref:`HTTP tracing `, either in this message or via :option:`--service-cluster`. | | | `metadata` | [.google.protobuf.Struct](https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/struct) | Opaque metadata extending the node identifier. Envoy will pass this directly to the management server. | | -| `locality` | [.envoy.api.v2.core.Locality](../base.proto.sk#locality) | Locality specifying where the Envoy instance is running. | | +| `locality` | [.envoy.api.v2.core.Locality](base.proto.sk.md#Locality) | Locality specifying where the Envoy instance is running. | | | `buildVersion` | `string` | This is motivated by informing a management server during canary which version of Envoy is being tested in a heterogeneous fleet. This will be set by Envoy in management server RPCs. | | --- -### Metadata +### Metadata Metadata provides additional inputs to filters based on matched listeners, @@ -131,7 +124,7 @@ this purpose: --- -### RuntimeUInt32 +### RuntimeUInt32 Runtime derived uint32 with a default when not specified. @@ -151,7 +144,7 @@ Runtime derived uint32 with a default when not specified. --- -### HeaderValue +### HeaderValue Header name/value pair. @@ -171,7 +164,7 @@ Header name/value pair. --- -### HeaderValueOption +### HeaderValueOption Header name/value pair plus option to control append behavior. @@ -184,14 +177,14 @@ Header name/value pair plus option to control append behavior. | Field | Type | Description | Default | | ----- | ---- | ----------- |----------- | -| `header` | [.envoy.api.v2.core.HeaderValue](../base.proto.sk#headervalue) | Header name/value pair that this option applies to. | | +| `header` | [.envoy.api.v2.core.HeaderValue](base.proto.sk.md#HeaderValue) | Header name/value pair that this option applies to. | | | `append` | [.google.protobuf.BoolValue](https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/bool-value) | Should the value be appended? If true (default), the value is appended to existing values. | | --- -### HeaderMap +### HeaderMap Wrapper for a set of headers. @@ -203,13 +196,13 @@ Wrapper for a set of headers. | Field | Type | Description | Default | | ----- | ---- | ----------- |----------- | -| `headers` | [[]envoy.api.v2.core.HeaderValue](../base.proto.sk#headervalue) | | | +| `headers` | [[]envoy.api.v2.core.HeaderValue](base.proto.sk.md#HeaderValue) | | | --- -### DataSource +### DataSource Data source consisting of either a file or an inline value. @@ -231,7 +224,7 @@ Data source consisting of either a file or an inline value. --- -### TransportSocket +### TransportSocket Configuration for transport socket in :ref:`listeners ` and @@ -256,7 +249,7 @@ chosen based on the platform and existence of tls_context. --- -### SocketOption +### SocketOption Generic socket option message. This would be used to set socket options that @@ -279,13 +272,13 @@ might not exist in upstream kernels or precompiled Envoy binaries. | `name` | `int` | The numeric name as passed to setsockopt | | | `intValue` | `int` | Because many sockopts take an int value. | | | `bufValue` | `bytes` | Otherwise it's a byte buffer. | | -| `state` | [.envoy.api.v2.core.SocketOption.SocketState](../base.proto.sk#socketstate) | The state in which the option will be applied. When used in BindConfig STATE_PREBIND is currently the only valid value. | | +| `state` | [.envoy.api.v2.core.SocketOption.SocketState](base.proto.sk.md#SocketState) | The state in which the option will be applied. When used in BindConfig STATE_PREBIND is currently the only valid value. | | --- -### SocketState +### SocketState @@ -299,7 +292,7 @@ might not exist in upstream kernels or precompiled Envoy binaries. --- -### RuntimeFractionalPercent +### RuntimeFractionalPercent Runtime derived FractionalPercent with defaults for when the numerator or denominator is not @@ -313,14 +306,14 @@ specified via a runtime key. | Field | Type | Description | Default | | ----- | ---- | ----------- |----------- | -| `defaultValue` | [.envoy.type.FractionalPercent](../../../../type/percent.proto.sk#fractionalpercent) | Default value if the runtime value's for the numerator/denominator keys are not available. | | +| `defaultValue` | [.envoy.type.FractionalPercent](../../../../github.com/solo-io/solo-kit/api/external/envoy/type/percent.proto.sk.md#FractionalPercent) | Default value if the runtime value's for the numerator/denominator keys are not available. | | | `runtimeKey` | `string` | Runtime key for a YAML representation of a FractionalPercent. | | --- -### ControlPlane +### ControlPlane Identifies a specific ControlPlane instance that Envoy is connected to. @@ -337,7 +330,7 @@ Identifies a specific ControlPlane instance that Envoy is connected to. -### RoutingPriority +### RoutingPriority Description: Envoy supports :ref:`upstream priority routing ` both at the route and the virtual @@ -352,7 +345,7 @@ over a single upstream connection. | DEFAULT | | | HIGH | | -### RequestMethod +### RequestMethod Description: HTTP request method. diff --git a/test/mocks/docs/github.com/solo-io/solo-kit/api/external/envoy/api/v2/core/base.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/envoy/api/v2/core/base.proto.sk.md new file mode 100644 index 000000000..d1b9d73bd --- /dev/null +++ b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/envoy/api/v2/core/base.proto.sk.md @@ -0,0 +1,367 @@ + + +### Package: `envoy.api.v2.core` +#### Types: + + +- [Locality](#Locality) +- [Node](#Node) +- [Metadata](#Metadata) +- [RuntimeUInt32](#RuntimeUInt32) +- [HeaderValue](#HeaderValue) +- [HeaderValueOption](#HeaderValueOption) +- [HeaderMap](#HeaderMap) +- [DataSource](#DataSource) +- [TransportSocket](#TransportSocket) +- [SocketOption](#SocketOption) +- [SocketState](#SocketState) +- [RuntimeFractionalPercent](#RuntimeFractionalPercent) +- [ControlPlane](#ControlPlane) + + + + +##### Enums: + + + - [RoutingPriority](#RoutingPriority) + - [RequestMethod](#RequestMethod) + + + +##### Source File: [github.com/solo-io/solo-kit/api/external/envoy/api/v2/core/base.proto](https://github.com/solo-io/solo-kit/blob/master/api/external/envoy/api/v2/core/base.proto) + + + + + +--- +### Locality + + +Identifies location of where either Envoy runs or where upstream hosts run. + +```yaml +"region": string +"zone": string +"subZone": string + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `region` | `string` | Region this :ref:`zone ` belongs to. | | +| `zone` | `string` | Defines the local service zone where Envoy is running. Though optional, it should be set if discovery service routing is used and the discovery service exposes :ref:`zone data `, either in this message or via :option:`--service-zone`. The meaning of zone is context dependent, e.g. `Availability Zone (AZ) `_ on AWS, `Zone `_ on GCP, etc. | | +| `subZone` | `string` | When used for locality of upstream hosts, this field further splits zone into smaller chunks of sub-zones so they can be load balanced independently. | | + + + + +--- +### Node + + +Identifies a specific Envoy instance. The node identifier is presented to the +management server, which may use this identifier to distinguish per Envoy +configuration for serving. + +```yaml +"id": string +"cluster": string +"metadata": .google.protobuf.Struct +"locality": .envoy.api.v2.core.Locality +"buildVersion": string + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `id` | `string` | An opaque node identifier for the Envoy node. This also provides the local service node name. It should be set if any of the following features are used: :ref:`statsd `, :ref:`CDS `, and :ref:`HTTP tracing `, either in this message or via :option:`--service-node`. | | +| `cluster` | `string` | Defines the local service cluster name where Envoy is running. Though optional, it should be set if any of the following features are used: :ref:`statsd `, :ref:`health check cluster verification `, :ref:`runtime override directory `, :ref:`user agent addition `, :ref:`HTTP global rate limiting `, :ref:`CDS `, and :ref:`HTTP tracing `, either in this message or via :option:`--service-cluster`. | | +| `metadata` | [.google.protobuf.Struct](https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/struct) | Opaque metadata extending the node identifier. Envoy will pass this directly to the management server. | | +| `locality` | [.envoy.api.v2.core.Locality](base.proto.sk.md#Locality) | Locality specifying where the Envoy instance is running. | | +| `buildVersion` | `string` | This is motivated by informing a management server during canary which version of Envoy is being tested in a heterogeneous fleet. This will be set by Envoy in management server RPCs. | | + + + + +--- +### Metadata + + +Metadata provides additional inputs to filters based on matched listeners, +filter chains, routes and endpoints. It is structured as a map, usually from +filter name (in reverse DNS format) to metadata specific to the filter. Metadata +key-values for a filter are merged as connection and request handling occurs, +with later values for the same key overriding earlier values. + +An example use of metadata is providing additional values to +http_connection_manager in the envoy.http_connection_manager.access_log +namespace. + +Another example use of metadata is to per service config info in cluster metadata, which may get +consumed by multiple filters. + +For load balancing, Metadata provides a means to subset cluster endpoints. +Endpoints have a Metadata object associated and routes contain a Metadata +object to match against. There are some well defined metadata used today for +this purpose: + +* ``{"envoy.lb": {"canary": }}`` This indicates the canary status of an + endpoint and is also used during header processing + (x-envoy-upstream-canary) and for stats purposes. + +```yaml +"filterMetadata": map + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `filterMetadata` | `map` | Key is the reverse DNS filter name, e.g. com.acme.widget. The envoy.* namespace is reserved for Envoy's built-in filters. | | + + + + +--- +### RuntimeUInt32 + + +Runtime derived uint32 with a default when not specified. + +```yaml +"defaultValue": int +"runtimeKey": string + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `defaultValue` | `int` | Default value if runtime value is not available. | | +| `runtimeKey` | `string` | Runtime key to get value for comparison. This value is used if defined. | | + + + + +--- +### HeaderValue + + +Header name/value pair. + +```yaml +"key": string +"value": string + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `key` | `string` | Header name. | | +| `value` | `string` | Header value. The same :ref:`format specifier ` as used for :ref:`HTTP access logging ` applies here, however unknown header values are replaced with the empty string instead of `-`. | | + + + + +--- +### HeaderValueOption + + +Header name/value pair plus option to control append behavior. + +```yaml +"header": .envoy.api.v2.core.HeaderValue +"append": .google.protobuf.BoolValue + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `header` | [.envoy.api.v2.core.HeaderValue](base.proto.sk.md#HeaderValue) | Header name/value pair that this option applies to. | | +| `append` | [.google.protobuf.BoolValue](https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/bool-value) | Should the value be appended? If true (default), the value is appended to existing values. | | + + + + +--- +### HeaderMap + + +Wrapper for a set of headers. + +```yaml +"headers": []envoy.api.v2.core.HeaderValue + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `headers` | [[]envoy.api.v2.core.HeaderValue](base.proto.sk.md#HeaderValue) | | | + + + + +--- +### DataSource + + +Data source consisting of either a file or an inline value. + +```yaml +"filename": string +"inlineBytes": bytes +"inlineString": string + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `filename` | `string` | Local filesystem data source. | | +| `inlineBytes` | `bytes` | Bytes inlined in the configuration. | | +| `inlineString` | `string` | String inlined in the configuration. | | + + + + +--- +### TransportSocket + + +Configuration for transport socket in :ref:`listeners ` and +:ref:`clusters `. If the configuration is +empty, a default transport socket implementation and configuration will be +chosen based on the platform and existence of tls_context. + +```yaml +"name": string +"config": .google.protobuf.Struct +"typedConfig": .google.protobuf.Any + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `name` | `string` | The name of the transport socket to instantiate. The name must match a supported transport socket implementation. | | +| `config` | [.google.protobuf.Struct](https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/struct) | | | +| `typedConfig` | [.google.protobuf.Any](https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/any) | | | + + + + +--- +### SocketOption + + +Generic socket option message. This would be used to set socket options that +might not exist in upstream kernels or precompiled Envoy binaries. + +```yaml +"description": string +"level": int +"name": int +"intValue": int +"bufValue": bytes +"state": .envoy.api.v2.core.SocketOption.SocketState + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `description` | `string` | An optional name to give this socket option for debugging, etc. Uniqueness is not required and no special meaning is assumed. | | +| `level` | `int` | Corresponding to the level value passed to setsockopt, such as IPPROTO_TCP | | +| `name` | `int` | The numeric name as passed to setsockopt | | +| `intValue` | `int` | Because many sockopts take an int value. | | +| `bufValue` | `bytes` | Otherwise it's a byte buffer. | | +| `state` | [.envoy.api.v2.core.SocketOption.SocketState](base.proto.sk.md#SocketState) | The state in which the option will be applied. When used in BindConfig STATE_PREBIND is currently the only valid value. | | + + + + +--- +### SocketState + + + +| Name | Description | +| ----- | ----------- | +| `STATE_PREBIND` | Socket options are applied after socket creation but before binding the socket to a port | +| `STATE_BOUND` | Socket options are applied after binding the socket to a port but before calling listen() | +| `STATE_LISTENING` | Socket options are applied after calling listen() | + + + + +--- +### RuntimeFractionalPercent + + +Runtime derived FractionalPercent with defaults for when the numerator or denominator is not +specified via a runtime key. + +```yaml +"defaultValue": .envoy.type.FractionalPercent +"runtimeKey": string + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `defaultValue` | [.envoy.type.FractionalPercent](../../../type/percent.proto.sk.md#FractionalPercent) | Default value if the runtime value's for the numerator/denominator keys are not available. | | +| `runtimeKey` | `string` | Runtime key for a YAML representation of a FractionalPercent. | | + + + + +--- +### ControlPlane + + +Identifies a specific ControlPlane instance that Envoy is connected to. + +```yaml +"identifier": string + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `identifier` | `string` | An opaque control plane identifier that uniquely identifies an instance of control plane. This can be used to identify which control plane instance, the Envoy is connected to. | | + + + + +### RoutingPriority + +Description: Envoy supports :ref:`upstream priority routing +` both at the route and the virtual +cluster level. The current priority implementation uses different connection +pool and circuit breaking settings for each priority level. This means that +even for HTTP/2 requests, two physical connections will be used to an +upstream host. In the future Envoy will likely support true HTTP/2 priority +over a single upstream connection. + +| Name | Description | +| ----- | ----------- | +| DEFAULT | | +| HIGH | | + +### RequestMethod + +Description: HTTP request method. + +| Name | Description | +| ----- | ----------- | +| METHOD_UNSPECIFIED | | +| GET | | +| HEAD | | +| POST | | +| PUT | | +| DELETE | | +| CONNECT | | +| OPTIONS | | +| TRACE | | + + + + + diff --git a/test/mocks/api/doc/envoy/api/v2/discovery.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/envoy/api/v2/discovery.proto.sk.md similarity index 86% rename from test/mocks/api/doc/envoy/api/v2/discovery.proto.sk.md rename to test/mocks/docs/github.com/solo-io/solo-kit/api/external/envoy/api/v2/discovery.proto.sk.md index 8fdf09be3..6591be92e 100644 --- a/test/mocks/api/doc/envoy/api/v2/discovery.proto.sk.md +++ b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/envoy/api/v2/discovery.proto.sk.md @@ -1,33 +1,26 @@ - ---- -title: "discovery.proto" -weight: 5 ---- - - ### Package: `envoy.api.v2` #### Types: -- [DiscoveryRequest](#discoveryrequest) -- [DiscoveryResponse](#discoveryresponse) -- [DeltaDiscoveryRequest](#deltadiscoveryrequest) -- [DeltaDiscoveryResponse](#deltadiscoveryresponse) -- [Resource](#resource) +- [DiscoveryRequest](#DiscoveryRequest) +- [DiscoveryResponse](#DiscoveryResponse) +- [DeltaDiscoveryRequest](#DeltaDiscoveryRequest) +- [DeltaDiscoveryResponse](#DeltaDiscoveryResponse) +- [Resource](#Resource) -##### Source File: `envoy/api/v2/discovery.proto` +##### Source File: [github.com/solo-io/solo-kit/api/external/envoy/api/v2/discovery.proto](https://github.com/solo-io/solo-kit/blob/master/api/external/envoy/api/v2/discovery.proto) --- -### DiscoveryRequest +### DiscoveryRequest A DiscoveryRequest requests a set of versioned resources of the same type for @@ -46,17 +39,17 @@ a given Envoy node on some API. | Field | Type | Description | Default | | ----- | ---- | ----------- |----------- | | `versionInfo` | `string` | The version_info provided in the request messages will be the version_info received with the most recent successfully processed response or empty on the first request. It is expected that no new request is sent after a response is received until the Envoy instance is ready to ACK/NACK the new configuration. ACK/NACK takes place by returning the new API config version as applied or the previous API config version respectively. Each type_url (see below) has an independent version associated with it. | | -| `node` | [.envoy.api.v2.core.Node](../core/base.proto.sk#node) | The node making the request. | | +| `node` | [.envoy.api.v2.core.Node](core/base.proto.sk.md#Node) | The node making the request. | | | `resourceNames` | `[]string` | List of resources to subscribe to, e.g. list of cluster names or a route configuration name. If this is empty, all resources for the API are returned. LDS/CDS expect empty resource_names, since this is global discovery for the Envoy instance. The LDS and CDS responses will then imply a number of resources that need to be fetched via EDS/RDS, which will be explicitly enumerated in resource_names. | | | `typeUrl` | `string` | Type of the resource that is being requested, e.g. "type.googleapis.com/envoy.api.v2.ClusterLoadAssignment". This is implicit in requests made via singleton xDS APIs such as CDS, LDS, etc. but is required for ADS. | | | `responseNonce` | `string` | nonce corresponding to DiscoveryResponse being ACK/NACKed. See above discussion on version_info and the DiscoveryResponse nonce comment. This may be empty if no nonce is available, e.g. at startup or for non-stream xDS implementations. | | -| `errorDetail` | [.google.rpc.Status](../../../../google/rpc/status.proto.sk#status) | This is populated when the previous :ref:`DiscoveryResponse ` failed to update configuration. The *message* field in *error_details* provides the Envoy internal exception related to the failure. It is only intended for consumption during manual debugging, the string provided is not guaranteed to be stable across Envoy versions. | | +| `errorDetail` | [.google.rpc.Status](../../../google/rpc/status.proto.sk.md#Status) | This is populated when the previous :ref:`DiscoveryResponse ` failed to update configuration. The *message* field in *error_details* provides the Envoy internal exception related to the failure. It is only intended for consumption during manual debugging, the string provided is not guaranteed to be stable across Envoy versions. | | --- -### DiscoveryResponse +### DiscoveryResponse @@ -73,17 +66,17 @@ a given Envoy node on some API. | Field | Type | Description | Default | | ----- | ---- | ----------- |----------- | | `versionInfo` | `string` | The version of the response data. | | -| `resources` | [[]google.protobuf.Any](../../../../google/protobuf/any.proto.sk#any) | The response resources. These resources are typed and depend on the API being called. | | +| `resources` | [[]google.protobuf.Any](../../../../../../../../google/protobuf/any.proto.sk.md#Any) | The response resources. These resources are typed and depend on the API being called. | | | `canary` | `bool` | [#not-implemented-hide:] Canary is used to support two Envoy command line flags: * --terminate-on-canary-transition-failure. When set, Envoy is able to terminate if it detects that configuration is stuck at canary. Consider this example sequence of updates: - Management server applies a canary config successfully. - Management server rolls back to a production config. - Envoy rejects the new production config. Since there is no sensible way to continue receiving configuration updates, Envoy will then terminate and apply production config from a clean slate. * --dry-run-canary. When set, a canary response will never be applied, only validated via a dry run. | | | `typeUrl` | `string` | Type URL for resources. This must be consistent with the type_url in the Any messages for resources if resources is non-empty. This effectively identifies the xDS API when muxing over ADS. | | | `nonce` | `string` | For gRPC based subscriptions, the nonce provides a way to explicitly ack a specific DiscoveryResponse in a following DiscoveryRequest. Additional messages may have been sent by Envoy to the management server for the previous version on the stream prior to this DiscoveryResponse, that were unprocessed at response send time. The nonce allows the management server to ignore any further DiscoveryRequests for the previous version until a DiscoveryRequest bearing the nonce. The nonce is optional and is not required for non-stream based xDS implementations. | | -| `controlPlane` | [.envoy.api.v2.core.ControlPlane](../core/base.proto.sk#controlplane) | [#not-implemented-hide:] The control plane instance that sent the response. | | +| `controlPlane` | [.envoy.api.v2.core.ControlPlane](core/base.proto.sk.md#ControlPlane) | [#not-implemented-hide:] The control plane instance that sent the response. | | --- -### DeltaDiscoveryRequest +### DeltaDiscoveryRequest DeltaDiscoveryRequest and DeltaDiscoveryResponse are used in a new gRPC @@ -125,19 +118,19 @@ DeltaDiscoveryRequest can be sent in 3 situations: | Field | Type | Description | Default | | ----- | ---- | ----------- |----------- | -| `node` | [.envoy.api.v2.core.Node](../core/base.proto.sk#node) | The node making the request. | | +| `node` | [.envoy.api.v2.core.Node](core/base.proto.sk.md#Node) | The node making the request. | | | `typeUrl` | `string` | Type of the resource that is being requested, e.g. "type.googleapis.com/envoy.api.v2.ClusterLoadAssignment". This is implicit in requests made via singleton xDS APIs such as CDS, LDS, etc. but is required for ADS. | | | `resourceNamesSubscribe` | `[]string` | DeltaDiscoveryRequests allow the client to add or remove individual resources to the set of tracked resources in the context of a stream. All resource names in the resource_names_subscribe list are added to the set of tracked resources and all resource names in the resource_names_unsubscribe list are removed from the set of tracked resources. Unlike in state-of-the-world xDS, an empty resource_names_subscribe or resource_names_unsubscribe list simply means that no resources are to be added or removed to the resource list. The xDS server must send updates for all tracked resources but can also send updates for resources the client has not subscribed to. This behavior is similar to state-of-the-world xDS. These two fields can be set for all types of DeltaDiscoveryRequests (initial, ACK/NACK or spontaneous). A list of Resource names to add to the list of tracked resources. | | | `resourceNamesUnsubscribe` | `[]string` | A list of Resource names to remove from the list of tracked resources. | | | `initialResourceVersions` | `map` | This map must be populated when the DeltaDiscoveryRequest is the first in a stream (assuming there are any resources - this field's purpose is to enable a session to continue in a reconnected gRPC stream, and so will not be used in the very first stream of a session). The keys are the resources names of the xDS resources known to the xDS client. The values in the map are the associated resource level version info. | | | `responseNonce` | `string` | When the DeltaDiscoveryRequest is a ACK or NACK message in response to a previous DeltaDiscoveryResponse, the response_nonce must be the nonce in the DeltaDiscoveryResponse. Otherwise response_nonce must be omitted. | | -| `errorDetail` | [.google.rpc.Status](../../../../google/rpc/status.proto.sk#status) | This is populated when the previous :ref:`DiscoveryResponse ` failed to update configuration. The *message* field in *error_details* provides the Envoy internal exception related to the failure. | | +| `errorDetail` | [.google.rpc.Status](../../../google/rpc/status.proto.sk.md#Status) | This is populated when the previous :ref:`DiscoveryResponse ` failed to update configuration. The *message* field in *error_details* provides the Envoy internal exception related to the failure. | | --- -### DeltaDiscoveryResponse +### DeltaDiscoveryResponse @@ -152,7 +145,7 @@ DeltaDiscoveryRequest can be sent in 3 situations: | Field | Type | Description | Default | | ----- | ---- | ----------- |----------- | | `systemVersionInfo` | `string` | The version of the response data (used for debugging). | | -| `resources` | [[]envoy.api.v2.Resource](../discovery.proto.sk#resource) | The response resources. These are typed resources that match the type url in the DeltaDiscoveryRequest. | | +| `resources` | [[]envoy.api.v2.Resource](discovery.proto.sk.md#Resource) | The response resources. These are typed resources that match the type url in the DeltaDiscoveryRequest. | | | `removedResources` | `[]string` | Resources names of resources that have be deleted and to be removed from the xDS Client. Removed resources for missing resources can be ignored. | | | `nonce` | `string` | The nonce provides a way for DeltaDiscoveryRequests to uniquely reference a DeltaDiscoveryResponse. The nonce is required. | | @@ -160,7 +153,7 @@ DeltaDiscoveryRequest can be sent in 3 situations: --- -### Resource +### Resource diff --git a/test/mocks/api/doc/envoy/type/percent.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/envoy/type/percent.proto.sk.md similarity index 76% rename from test/mocks/api/doc/envoy/type/percent.proto.sk.md rename to test/mocks/docs/github.com/solo-io/solo-kit/api/external/envoy/type/percent.proto.sk.md index 145675fb4..756d49b18 100644 --- a/test/mocks/api/doc/envoy/type/percent.proto.sk.md +++ b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/envoy/type/percent.proto.sk.md @@ -1,31 +1,24 @@ - ---- -title: "percent.proto" -weight: 5 ---- - - ### Package: `envoy.type` #### Types: -- [Percent](#percent) -- [FractionalPercent](#fractionalpercent) -- [DenominatorType](#denominatortype) +- [Percent](#Percent) +- [FractionalPercent](#FractionalPercent) +- [DenominatorType](#DenominatorType) -##### Source File: `envoy/type/percent.proto` +##### Source File: [github.com/solo-io/solo-kit/api/external/envoy/type/percent.proto](https://github.com/solo-io/solo-kit/blob/master/api/external/envoy/type/percent.proto) --- -### Percent +### Percent Identifies a percentage, in the range [0.0, 100.0]. @@ -43,7 +36,7 @@ Identifies a percentage, in the range [0.0, 100.0]. --- -### FractionalPercent +### FractionalPercent A fractional percentage is used in cases in which for performance reasons performing floating @@ -62,13 +55,13 @@ both a numerator and denominator that together determine the final fractional va | Field | Type | Description | Default | | ----- | ---- | ----------- |----------- | | `numerator` | `int` | Specifies the numerator. Defaults to 0. | | -| `denominator` | [.envoy.type.FractionalPercent.DenominatorType](../percent.proto.sk#denominatortype) | Specifies the denominator. If the denominator specified is less than the numerator, the final fractional percentage is capped at 1 (100%). | | +| `denominator` | [.envoy.type.FractionalPercent.DenominatorType](percent.proto.sk.md#DenominatorType) | Specifies the denominator. If the denominator specified is less than the numerator, the final fractional percentage is capped at 1 (100%). | | --- -### DenominatorType +### DenominatorType Fraction percentages support several fixed denominator values. diff --git a/test/mocks/api/doc/gogoproto/gogo.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/gogoproto/gogo.proto.sk.md similarity index 90% rename from test/mocks/api/doc/gogoproto/gogo.proto.sk.md rename to test/mocks/docs/github.com/solo-io/solo-kit/api/external/gogoproto/gogo.proto.sk.md index 47c3fc0b8..d42b69d5f 100644 --- a/test/mocks/api/doc/gogoproto/gogo.proto.sk.md +++ b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/gogoproto/gogo.proto.sk.md @@ -1,12 +1,5 @@ - ---- -title: "gogo.proto" -weight: 5 ---- - - ### Package: `gogoproto` Protocol Buffers for Go with Gadgets @@ -39,7 +32,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -##### Source File: `gogoproto/gogo.proto` +##### Source File: [github.com/solo-io/solo-kit/api/external/gogoproto/gogo.proto](https://github.com/solo-io/solo-kit/blob/master/api/external/gogoproto/gogo.proto) diff --git a/test/mocks/api/doc/google/api/annotations.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/api/annotations.proto.sk.md similarity index 82% rename from test/mocks/api/doc/google/api/annotations.proto.sk.md rename to test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/api/annotations.proto.sk.md index 88ca011ec..0a4e481a4 100644 --- a/test/mocks/api/doc/google/api/annotations.proto.sk.md +++ b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/api/annotations.proto.sk.md @@ -1,12 +1,5 @@ - ---- -title: "annotations.proto" -weight: 5 ---- - - ### Package: `google.api` Copyright (c) 2015, Google Inc. @@ -25,7 +18,7 @@ limitations under the License. -##### Source File: `google/api/annotations.proto` +##### Source File: [github.com/solo-io/solo-kit/api/external/google/api/annotations.proto](https://github.com/solo-io/solo-kit/blob/master/api/external/google/api/annotations.proto) diff --git a/test/mocks/api/doc/google/api/http.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/api/http.proto.sk.md similarity index 94% rename from test/mocks/api/doc/google/api/http.proto.sk.md rename to test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/api/http.proto.sk.md index 051dfd26a..9a8ca8c60 100644 --- a/test/mocks/api/doc/google/api/http.proto.sk.md +++ b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/api/http.proto.sk.md @@ -1,12 +1,5 @@ - ---- -title: "http.proto" -weight: 5 ---- - - ### Package: `google.api` Copyright 2018 Google LLC @@ -27,21 +20,21 @@ limitations under the License. #### Types: -- [Http](#http) -- [HttpRule](#httprule) -- [CustomHttpPattern](#customhttppattern) +- [Http](#Http) +- [HttpRule](#HttpRule) +- [CustomHttpPattern](#CustomHttpPattern) -##### Source File: `google/api/http.proto` +##### Source File: [github.com/solo-io/solo-kit/api/external/google/api/http.proto](https://github.com/solo-io/solo-kit/blob/master/api/external/google/api/http.proto) --- -### Http +### Http Defines the HTTP configuration for an API service. It contains a list of @@ -56,14 +49,14 @@ to one or more HTTP REST API methods. | Field | Type | Description | Default | | ----- | ---- | ----------- |----------- | -| `rules` | [[]google.api.HttpRule](../http.proto.sk#httprule) | A list of HTTP configuration rules that apply to individual API methods. **NOTE:** All service configuration rules follow "last one wins" order. | | +| `rules` | [[]google.api.HttpRule](http.proto.sk.md#HttpRule) | A list of HTTP configuration rules that apply to individual API methods. **NOTE:** All service configuration rules follow "last one wins" order. | | | `fullyDecodeReservedExpansion` | `bool` | When set to true, URL path parmeters will be fully URI-decoded except in cases of single segment matches in reserved expansion, where "%2F" will be left encoded. The default behavior is to not decode RFC 6570 reserved characters in multi segment matches. | | --- -### HttpRule +### HttpRule `HttpRule` defines the mapping of an RPC method to one or more HTTP @@ -305,15 +298,15 @@ repeated fields or map fields. | `post` | `string` | Used for creating a resource. | | | `delete` | `string` | Used for deleting a resource. | | | `patch` | `string` | Used for updating a resource. | | -| `custom` | [.google.api.CustomHttpPattern](../http.proto.sk#customhttppattern) | The custom pattern is used for specifying an HTTP method that is not included in the `pattern` field, such as HEAD, or "*" to leave the HTTP method unspecified for this rule. The wild-card rule is useful for services that provide content to Web (HTML) clients. | | +| `custom` | [.google.api.CustomHttpPattern](http.proto.sk.md#CustomHttpPattern) | The custom pattern is used for specifying an HTTP method that is not included in the `pattern` field, such as HEAD, or "*" to leave the HTTP method unspecified for this rule. The wild-card rule is useful for services that provide content to Web (HTML) clients. | | | `body` | `string` | The name of the request field whose value is mapped to the HTTP body, or `*` for mapping all fields not captured by the path pattern to the HTTP body. NOTE: the referred field must not be a repeated field and must be present at the top-level of request message type. | | -| `additionalBindings` | [[]google.api.HttpRule](../http.proto.sk#httprule) | Additional HTTP bindings for the selector. Nested bindings must not contain an `additional_bindings` field themselves (that is, the nesting may only be one level deep). | | +| `additionalBindings` | [[]google.api.HttpRule](http.proto.sk.md#HttpRule) | Additional HTTP bindings for the selector. Nested bindings must not contain an `additional_bindings` field themselves (that is, the nesting may only be one level deep). | | --- -### CustomHttpPattern +### CustomHttpPattern A custom pattern is used for defining custom HTTP verb. diff --git a/test/mocks/api/doc/google/protobuf/descriptor.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/protobuf/descriptor.proto.sk.md similarity index 87% rename from test/mocks/api/doc/google/protobuf/descriptor.proto.sk.md rename to test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/protobuf/descriptor.proto.sk.md index e837aad9d..a4f7351ac 100644 --- a/test/mocks/api/doc/google/protobuf/descriptor.proto.sk.md +++ b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/protobuf/descriptor.proto.sk.md @@ -1,12 +1,5 @@ - ---- -title: "descriptor.proto" -weight: 5 ---- - - ### Package: `google.protobuf` Protocol Buffers - Google's data interchange format Copyright 2008 Google Inc. All rights reserved. @@ -50,49 +43,49 @@ without any other information (e.g. without reading its imports). #### Types: -- [FileDescriptorSet](#filedescriptorset) -- [FileDescriptorProto](#filedescriptorproto) -- [DescriptorProto](#descriptorproto) -- [ExtensionRange](#extensionrange) -- [ReservedRange](#reservedrange) -- [FieldDescriptorProto](#fielddescriptorproto) -- [Type](#type) -- [Label](#label) -- [OneofDescriptorProto](#oneofdescriptorproto) -- [EnumDescriptorProto](#enumdescriptorproto) -- [EnumValueDescriptorProto](#enumvaluedescriptorproto) -- [ServiceDescriptorProto](#servicedescriptorproto) -- [MethodDescriptorProto](#methoddescriptorproto) -- [FileOptions](#fileoptions) -- [OptimizeMode](#optimizemode) -- [MessageOptions](#messageoptions) -- [FieldOptions](#fieldoptions) -- [CType](#ctype) -- [JSType](#jstype) -- [OneofOptions](#oneofoptions) -- [EnumOptions](#enumoptions) -- [EnumValueOptions](#enumvalueoptions) -- [ServiceOptions](#serviceoptions) -- [MethodOptions](#methodoptions) -- [IdempotencyLevel](#idempotencylevel) -- [UninterpretedOption](#uninterpretedoption) -- [NamePart](#namepart) -- [SourceCodeInfo](#sourcecodeinfo) -- [Location](#location) -- [GeneratedCodeInfo](#generatedcodeinfo) -- [Annotation](#annotation) +- [FileDescriptorSet](#FileDescriptorSet) +- [FileDescriptorProto](#FileDescriptorProto) +- [DescriptorProto](#DescriptorProto) +- [ExtensionRange](#ExtensionRange) +- [ReservedRange](#ReservedRange) +- [FieldDescriptorProto](#FieldDescriptorProto) +- [Type](#Type) +- [Label](#Label) +- [OneofDescriptorProto](#OneofDescriptorProto) +- [EnumDescriptorProto](#EnumDescriptorProto) +- [EnumValueDescriptorProto](#EnumValueDescriptorProto) +- [ServiceDescriptorProto](#ServiceDescriptorProto) +- [MethodDescriptorProto](#MethodDescriptorProto) +- [FileOptions](#FileOptions) +- [OptimizeMode](#OptimizeMode) +- [MessageOptions](#MessageOptions) +- [FieldOptions](#FieldOptions) +- [CType](#CType) +- [JSType](#JSType) +- [OneofOptions](#OneofOptions) +- [EnumOptions](#EnumOptions) +- [EnumValueOptions](#EnumValueOptions) +- [ServiceOptions](#ServiceOptions) +- [MethodOptions](#MethodOptions) +- [IdempotencyLevel](#IdempotencyLevel) +- [UninterpretedOption](#UninterpretedOption) +- [NamePart](#NamePart) +- [SourceCodeInfo](#SourceCodeInfo) +- [Location](#Location) +- [GeneratedCodeInfo](#GeneratedCodeInfo) +- [Annotation](#Annotation) -##### Source File: `google/protobuf/descriptor.proto` +##### Source File: [github.com/solo-io/solo-kit/api/external/google/protobuf/descriptor.proto](https://github.com/solo-io/solo-kit/blob/master/api/external/google/protobuf/descriptor.proto) --- -### FileDescriptorSet +### FileDescriptorSet The protocol compiler can output a FileDescriptorSet containing the .proto @@ -105,13 +98,13 @@ files it parses. | Field | Type | Description | Default | | ----- | ---- | ----------- |----------- | -| `file` | [[]google.protobuf.FileDescriptorProto](../descriptor.proto.sk#filedescriptorproto) | | | +| `file` | [[]google.protobuf.FileDescriptorProto](descriptor.proto.sk.md#FileDescriptorProto) | | | --- -### FileDescriptorProto +### FileDescriptorProto Describes a complete .proto file. @@ -139,10 +132,10 @@ Describes a complete .proto file. | `dependency` | `[]string` | Names of files imported by this file. | | | `publicDependency` | `[]int` | Indexes of the public imported files in the dependency list above. | | | `weakDependency` | `[]int` | Indexes of the weak imported files in the dependency list. For Google-internal migration only. Do not use. | | -| `messageType` | [[]google.protobuf.DescriptorProto](../descriptor.proto.sk#descriptorproto) | All top-level definitions in this file. | | -| `enumType` | [[]google.protobuf.EnumDescriptorProto](../descriptor.proto.sk#enumdescriptorproto) | | | -| `service` | [[]google.protobuf.ServiceDescriptorProto](../descriptor.proto.sk#servicedescriptorproto) | | | -| `extension` | [[]google.protobuf.FieldDescriptorProto](../descriptor.proto.sk#fielddescriptorproto) | | | +| `messageType` | [[]google.protobuf.DescriptorProto](descriptor.proto.sk.md#DescriptorProto) | All top-level definitions in this file. | | +| `enumType` | [[]google.protobuf.EnumDescriptorProto](descriptor.proto.sk.md#EnumDescriptorProto) | | | +| `service` | [[]google.protobuf.ServiceDescriptorProto](descriptor.proto.sk.md#ServiceDescriptorProto) | | | +| `extension` | [[]google.protobuf.FieldDescriptorProto](descriptor.proto.sk.md#FieldDescriptorProto) | | | | `options` | [.google.protobuf.FileOptions](https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/file-options) | | | | `sourceCodeInfo` | [.google.protobuf.SourceCodeInfo](https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/source-code-info) | This field contains optional information about the original source code. You may safely remove this entire field without harming runtime functionality of the descriptors -- the information is needed only by development tools. | | | `syntax` | `string` | The syntax of the proto file. The supported values are "proto2" and "proto3". | | @@ -151,7 +144,7 @@ Describes a complete .proto file. --- -### DescriptorProto +### DescriptorProto Describes a message type. @@ -173,21 +166,21 @@ Describes a message type. | Field | Type | Description | Default | | ----- | ---- | ----------- |----------- | | `name` | `string` | | | -| `field` | [[]google.protobuf.FieldDescriptorProto](../descriptor.proto.sk#fielddescriptorproto) | | | -| `extension` | [[]google.protobuf.FieldDescriptorProto](../descriptor.proto.sk#fielddescriptorproto) | | | -| `nestedType` | [[]google.protobuf.DescriptorProto](../descriptor.proto.sk#descriptorproto) | | | -| `enumType` | [[]google.protobuf.EnumDescriptorProto](../descriptor.proto.sk#enumdescriptorproto) | | | -| `extensionRange` | [[]google.protobuf.DescriptorProto.ExtensionRange](../descriptor.proto.sk#extensionrange) | | | -| `oneofDecl` | [[]google.protobuf.OneofDescriptorProto](../descriptor.proto.sk#oneofdescriptorproto) | | | +| `field` | [[]google.protobuf.FieldDescriptorProto](descriptor.proto.sk.md#FieldDescriptorProto) | | | +| `extension` | [[]google.protobuf.FieldDescriptorProto](descriptor.proto.sk.md#FieldDescriptorProto) | | | +| `nestedType` | [[]google.protobuf.DescriptorProto](descriptor.proto.sk.md#DescriptorProto) | | | +| `enumType` | [[]google.protobuf.EnumDescriptorProto](descriptor.proto.sk.md#EnumDescriptorProto) | | | +| `extensionRange` | [[]google.protobuf.DescriptorProto.ExtensionRange](descriptor.proto.sk.md#ExtensionRange) | | | +| `oneofDecl` | [[]google.protobuf.OneofDescriptorProto](descriptor.proto.sk.md#OneofDescriptorProto) | | | | `options` | [.google.protobuf.MessageOptions](https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/message-options) | | | -| `reservedRange` | [[]google.protobuf.DescriptorProto.ReservedRange](../descriptor.proto.sk#reservedrange) | | | +| `reservedRange` | [[]google.protobuf.DescriptorProto.ReservedRange](descriptor.proto.sk.md#ReservedRange) | | | | `reservedName` | `[]string` | Reserved field names, which may not be used by fields in the same message. A given name may only be reserved once. | | --- -### ExtensionRange +### ExtensionRange @@ -206,7 +199,7 @@ Describes a message type. --- -### ReservedRange +### ReservedRange Range of reserved tag numbers. Reserved tag numbers may not be used by @@ -228,7 +221,7 @@ not overlap. --- -### FieldDescriptorProto +### FieldDescriptorProto Describes a field within a message. @@ -264,7 +257,7 @@ Describes a field within a message. --- -### Type +### Type @@ -293,7 +286,7 @@ Describes a field within a message. --- -### Label +### Label @@ -307,7 +300,7 @@ Describes a field within a message. --- -### OneofDescriptorProto +### OneofDescriptorProto Describes a oneof. @@ -327,7 +320,7 @@ Describes a oneof. --- -### EnumDescriptorProto +### EnumDescriptorProto Describes an enum type. @@ -342,14 +335,14 @@ Describes an enum type. | Field | Type | Description | Default | | ----- | ---- | ----------- |----------- | | `name` | `string` | | | -| `value` | [[]google.protobuf.EnumValueDescriptorProto](../descriptor.proto.sk#enumvaluedescriptorproto) | | | +| `value` | [[]google.protobuf.EnumValueDescriptorProto](descriptor.proto.sk.md#EnumValueDescriptorProto) | | | | `options` | [.google.protobuf.EnumOptions](https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/enum-options) | | | --- -### EnumValueDescriptorProto +### EnumValueDescriptorProto Describes a value within an enum. @@ -371,7 +364,7 @@ Describes a value within an enum. --- -### ServiceDescriptorProto +### ServiceDescriptorProto Describes a service. @@ -386,14 +379,14 @@ Describes a service. | Field | Type | Description | Default | | ----- | ---- | ----------- |----------- | | `name` | `string` | | | -| `method` | [[]google.protobuf.MethodDescriptorProto](../descriptor.proto.sk#methoddescriptorproto) | | | +| `method` | [[]google.protobuf.MethodDescriptorProto](descriptor.proto.sk.md#MethodDescriptorProto) | | | | `options` | [.google.protobuf.ServiceOptions](https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/service-options) | | | --- -### MethodDescriptorProto +### MethodDescriptorProto Describes a method of a service. @@ -421,7 +414,7 @@ Describes a method of a service. --- -### FileOptions +### FileOptions @@ -464,13 +457,13 @@ Describes a method of a service. | `csharpNamespace` | `string` | Namespace for generated classes; defaults to the package. | | | `swiftPrefix` | `string` | By default Swift generators will take the proto package and CamelCase it replacing '.' with underscore and use that to prefix the types/symbols defined. When this options is provided, they will use this value instead to prefix the types/symbols defined. | | | `phpClassPrefix` | `string` | Sets the php class prefix which is prepended to all php generated classes from this .proto. Default is empty. | | -| `uninterpretedOption` | [[]google.protobuf.UninterpretedOption](../descriptor.proto.sk#uninterpretedoption) | The parser stores options it doesn't recognize here. See above. | | +| `uninterpretedOption` | [[]google.protobuf.UninterpretedOption](descriptor.proto.sk.md#UninterpretedOption) | The parser stores options it doesn't recognize here. See above. | | --- -### OptimizeMode +### OptimizeMode Generated classes can be optimized for speed or code size. @@ -485,7 +478,7 @@ Generated classes can be optimized for speed or code size. --- -### MessageOptions +### MessageOptions @@ -504,13 +497,13 @@ Generated classes can be optimized for speed or code size. | `noStandardDescriptorAccessor` | `bool` | Disables the generation of the standard "descriptor()" accessor, which can conflict with a field of the same name. This is meant to make migration from proto1 easier; new code should avoid fields named "descriptor". | Default: false | | `deprecated` | `bool` | Is this message deprecated? Depending on the target platform, this can emit Deprecated annotations for the message, or it will be completely ignored; in the very least, this is a formalization for deprecating messages. | Default: false | | `mapEntry` | `bool` | Whether the message is an automatically generated map entry type for the maps field. For maps fields: map map_field = 1; The parsed descriptor looks like: message MapFieldEntry { option map_entry = true; optional KeyType key = 1; optional ValueType value = 2; } repeated MapFieldEntry map_field = 1; Implementations may choose not to generate the map_entry=true message, but use a native map in the target language to hold the keys and values. The reflection APIs in such implementions still need to work as if the field is a repeated message field. NOTE: Do not set the option in .proto files. Always use the maps syntax instead. The option should only be implicitly set by the proto compiler parser. | | -| `uninterpretedOption` | [[]google.protobuf.UninterpretedOption](../descriptor.proto.sk#uninterpretedoption) | The parser stores options it doesn't recognize here. See above. | | +| `uninterpretedOption` | [[]google.protobuf.UninterpretedOption](descriptor.proto.sk.md#UninterpretedOption) | The parser stores options it doesn't recognize here. See above. | | --- -### FieldOptions +### FieldOptions @@ -533,13 +526,13 @@ Generated classes can be optimized for speed or code size. | `lazy` | `bool` | Should this field be parsed lazily? Lazy applies only to message-type fields. It means that when the outer message is initially parsed, the inner message's contents will not be parsed but instead stored in encoded form. The inner message will actually be parsed when it is first accessed. This is only a hint. Implementations are free to choose whether to use eager or lazy parsing regardless of the value of this option. However, setting this option true suggests that the protocol author believes that using lazy parsing on this field is worth the additional bookkeeping overhead typically needed to implement it. This option does not affect the public interface of any generated code; all method signatures remain the same. Furthermore, thread-safety of the interface is not affected by this option; const methods remain safe to call from multiple threads concurrently, while non-const methods continue to require exclusive access. Note that implementations may choose not to check required fields within a lazy sub-message. That is, calling IsInitialized() on the outer message may return true even if the inner message has missing required fields. This is necessary because otherwise the inner message would have to be parsed in order to perform the check, defeating the purpose of lazy parsing. An implementation which chooses not to check required fields must be consistent about it. That is, for any particular sub-message, the implementation must either *always* check its required fields, or *never* check its required fields, regardless of whether or not the message has been parsed. | Default: false | | `deprecated` | `bool` | Is this field deprecated? Depending on the target platform, this can emit Deprecated annotations for accessors, or it will be completely ignored; in the very least, this is a formalization for deprecating fields. | Default: false | | `weak` | `bool` | For Google-internal migration only. Do not use. | Default: false | -| `uninterpretedOption` | [[]google.protobuf.UninterpretedOption](../descriptor.proto.sk#uninterpretedoption) | The parser stores options it doesn't recognize here. See above. | | +| `uninterpretedOption` | [[]google.protobuf.UninterpretedOption](descriptor.proto.sk.md#UninterpretedOption) | The parser stores options it doesn't recognize here. See above. | | --- -### CType +### CType @@ -553,7 +546,7 @@ Generated classes can be optimized for speed or code size. --- -### JSType +### JSType @@ -567,7 +560,7 @@ Generated classes can be optimized for speed or code size. --- -### OneofOptions +### OneofOptions @@ -578,13 +571,13 @@ Generated classes can be optimized for speed or code size. | Field | Type | Description | Default | | ----- | ---- | ----------- |----------- | -| `uninterpretedOption` | [[]google.protobuf.UninterpretedOption](../descriptor.proto.sk#uninterpretedoption) | The parser stores options it doesn't recognize here. See above. | | +| `uninterpretedOption` | [[]google.protobuf.UninterpretedOption](descriptor.proto.sk.md#UninterpretedOption) | The parser stores options it doesn't recognize here. See above. | | --- -### EnumOptions +### EnumOptions @@ -599,13 +592,13 @@ Generated classes can be optimized for speed or code size. | ----- | ---- | ----------- |----------- | | `allowAlias` | `bool` | Set this option to true to allow mapping different tag names to the same value. | | | `deprecated` | `bool` | Is this enum deprecated? Depending on the target platform, this can emit Deprecated annotations for the enum, or it will be completely ignored; in the very least, this is a formalization for deprecating enums. | Default: false | -| `uninterpretedOption` | [[]google.protobuf.UninterpretedOption](../descriptor.proto.sk#uninterpretedoption) | The parser stores options it doesn't recognize here. See above. | | +| `uninterpretedOption` | [[]google.protobuf.UninterpretedOption](descriptor.proto.sk.md#UninterpretedOption) | The parser stores options it doesn't recognize here. See above. | | --- -### EnumValueOptions +### EnumValueOptions @@ -618,13 +611,13 @@ Generated classes can be optimized for speed or code size. | Field | Type | Description | Default | | ----- | ---- | ----------- |----------- | | `deprecated` | `bool` | Is this enum value deprecated? Depending on the target platform, this can emit Deprecated annotations for the enum value, or it will be completely ignored; in the very least, this is a formalization for deprecating enum values. | Default: false | -| `uninterpretedOption` | [[]google.protobuf.UninterpretedOption](../descriptor.proto.sk#uninterpretedoption) | The parser stores options it doesn't recognize here. See above. | | +| `uninterpretedOption` | [[]google.protobuf.UninterpretedOption](descriptor.proto.sk.md#UninterpretedOption) | The parser stores options it doesn't recognize here. See above. | | --- -### ServiceOptions +### ServiceOptions @@ -637,13 +630,13 @@ Generated classes can be optimized for speed or code size. | Field | Type | Description | Default | | ----- | ---- | ----------- |----------- | | `deprecated` | `bool` | Is this service deprecated? Depending on the target platform, this can emit Deprecated annotations for the service, or it will be completely ignored; in the very least, this is a formalization for deprecating services. | Default: false | -| `uninterpretedOption` | [[]google.protobuf.UninterpretedOption](../descriptor.proto.sk#uninterpretedoption) | The parser stores options it doesn't recognize here. See above. | | +| `uninterpretedOption` | [[]google.protobuf.UninterpretedOption](descriptor.proto.sk.md#UninterpretedOption) | The parser stores options it doesn't recognize here. See above. | | --- -### MethodOptions +### MethodOptions @@ -658,13 +651,13 @@ Generated classes can be optimized for speed or code size. | ----- | ---- | ----------- |----------- | | `deprecated` | `bool` | Is this method deprecated? Depending on the target platform, this can emit Deprecated annotations for the method, or it will be completely ignored; in the very least, this is a formalization for deprecating methods. | Default: false | | `idempotencyLevel` | [.google.protobuf.MethodOptions.IdempotencyLevel](https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/method-options.-idempotency-level) | | Default: IDEMPOTENCY_UNKNOWN | -| `uninterpretedOption` | [[]google.protobuf.UninterpretedOption](../descriptor.proto.sk#uninterpretedoption) | The parser stores options it doesn't recognize here. See above. | | +| `uninterpretedOption` | [[]google.protobuf.UninterpretedOption](descriptor.proto.sk.md#UninterpretedOption) | The parser stores options it doesn't recognize here. See above. | | --- -### IdempotencyLevel +### IdempotencyLevel Is this method side-effect-free (or safe in HTTP parlance), or idempotent, @@ -681,7 +674,7 @@ methods, and PUT verb for idempotent methods instead of the default POST. --- -### UninterpretedOption +### UninterpretedOption A message representing a option the parser does not recognize. This only @@ -704,7 +697,7 @@ in them. | Field | Type | Description | Default | | ----- | ---- | ----------- |----------- | -| `name` | [[]google.protobuf.UninterpretedOption.NamePart](../descriptor.proto.sk#namepart) | | | +| `name` | [[]google.protobuf.UninterpretedOption.NamePart](descriptor.proto.sk.md#NamePart) | | | | `identifierValue` | `string` | The value of the uninterpreted option, in whatever type the tokenizer identified it as during parsing. Exactly one of these should be set. | | | `positiveIntValue` | `int` | | | | `negativeIntValue` | `int` | | | @@ -716,7 +709,7 @@ in them. --- -### NamePart +### NamePart The name of the uninterpreted option. Each string represents a segment in @@ -740,7 +733,7 @@ E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents --- -### SourceCodeInfo +### SourceCodeInfo Encapsulates information about the original source file from which a @@ -753,13 +746,13 @@ FileDescriptorProto was generated. | Field | Type | Description | Default | | ----- | ---- | ----------- |----------- | -| `location` | [[]google.protobuf.SourceCodeInfo.Location](../descriptor.proto.sk#location) | A Location identifies a piece of source code in a .proto file which corresponds to a particular definition. This information is intended to be useful to IDEs, code indexers, documentation generators, and similar tools. For example, say we have a file like: message Foo { optional string foo = 1; } Let's look at just the field definition: optional string foo = 1; ^ ^^ ^^ ^ ^^^ a bc de f ghi We have the following locations: span path represents [a,i) [ 4, 0, 2, 0 ] The whole field definition. [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). [c,d) [ 4, 0, 2, 0, 5 ] The type (string). [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). [g,h) [ 4, 0, 2, 0, 3 ] The number (1). Notes: - A location may refer to a repeated field itself (i.e. not to any particular index within it). This is used whenever a set of elements are logically enclosed in a single code segment. For example, an entire extend block (possibly containing multiple extension definitions) will have an outer location whose path refers to the "extensions" repeated field without an index. - Multiple locations may have the same path. This happens when a single logical declaration is spread out across multiple places. The most obvious example is the "extend" block again -- there may be multiple extend blocks in the same scope, each of which will have the same path. - A location's span is not always a subset of its parent's span. For example, the "extendee" of an extension declaration appears at the beginning of the "extend" block and is shared by all extensions within the block. - Just because a location's span is a subset of some other location's span does not mean that it is a descendent. For example, a "group" defines both a type and a field in a single declaration. Thus, the locations corresponding to the type and field and their components will overlap. - Code which tries to interpret locations should probably be designed to ignore those that it doesn't understand, as more types of locations could be recorded in the future. | | +| `location` | [[]google.protobuf.SourceCodeInfo.Location](descriptor.proto.sk.md#Location) | A Location identifies a piece of source code in a .proto file which corresponds to a particular definition. This information is intended to be useful to IDEs, code indexers, documentation generators, and similar tools. For example, say we have a file like: message Foo { optional string foo = 1; } Let's look at just the field definition: optional string foo = 1; ^ ^^ ^^ ^ ^^^ a bc de f ghi We have the following locations: span path represents [a,i) [ 4, 0, 2, 0 ] The whole field definition. [a,b) [ 4, 0, 2, 0, 4 ] The label (optional). [c,d) [ 4, 0, 2, 0, 5 ] The type (string). [e,f) [ 4, 0, 2, 0, 1 ] The name (foo). [g,h) [ 4, 0, 2, 0, 3 ] The number (1). Notes: - A location may refer to a repeated field itself (i.e. not to any particular index within it). This is used whenever a set of elements are logically enclosed in a single code segment. For example, an entire extend block (possibly containing multiple extension definitions) will have an outer location whose path refers to the "extensions" repeated field without an index. - Multiple locations may have the same path. This happens when a single logical declaration is spread out across multiple places. The most obvious example is the "extend" block again -- there may be multiple extend blocks in the same scope, each of which will have the same path. - A location's span is not always a subset of its parent's span. For example, the "extendee" of an extension declaration appears at the beginning of the "extend" block and is shared by all extensions within the block. - Just because a location's span is a subset of some other location's span does not mean that it is a descendent. For example, a "group" defines both a type and a field in a single declaration. Thus, the locations corresponding to the type and field and their components will overlap. - Code which tries to interpret locations should probably be designed to ignore those that it doesn't understand, as more types of locations could be recorded in the future. | | --- -### Location +### Location @@ -784,7 +777,7 @@ FileDescriptorProto was generated. --- -### GeneratedCodeInfo +### GeneratedCodeInfo Describes the relationship between generated code and its original source @@ -798,13 +791,13 @@ source file, but may contain references to different source .proto files. | Field | Type | Description | Default | | ----- | ---- | ----------- |----------- | -| `annotation` | [[]google.protobuf.GeneratedCodeInfo.Annotation](../descriptor.proto.sk#annotation) | An Annotation connects some span of text in generated code to an element of its generating .proto file. | | +| `annotation` | [[]google.protobuf.GeneratedCodeInfo.Annotation](descriptor.proto.sk.md#Annotation) | An Annotation connects some span of text in generated code to an element of its generating .proto file. | | --- -### Annotation +### Annotation diff --git a/test/mocks/api/doc/google/protobuf/duration.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/protobuf/duration.proto.sk.md similarity index 95% rename from test/mocks/api/doc/google/protobuf/duration.proto.sk.md rename to test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/protobuf/duration.proto.sk.md index 774281e52..3cfe758ca 100644 --- a/test/mocks/api/doc/google/protobuf/duration.proto.sk.md +++ b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/protobuf/duration.proto.sk.md @@ -1,12 +1,5 @@ - ---- -title: "duration.proto" -weight: 5 ---- - - ### Package: `google.protobuf` Protocol Buffers - Google's data interchange format Copyright 2008 Google Inc. All rights reserved. @@ -43,19 +36,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #### Types: -- [Duration](#duration) +- [Duration](#Duration) -##### Source File: `google/protobuf/duration.proto` +##### Source File: [github.com/solo-io/solo-kit/api/external/google/protobuf/duration.proto](https://github.com/solo-io/solo-kit/blob/master/api/external/google/protobuf/duration.proto) --- -### Duration +### Duration A Duration represents a signed, fixed-length span of time represented diff --git a/test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/protobuf/empty.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/protobuf/empty.proto.sk.md new file mode 100644 index 000000000..de3c38367 --- /dev/null +++ b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/protobuf/empty.proto.sk.md @@ -0,0 +1,77 @@ + + +### Package: `google.protobuf` +Protocol Buffers - Google's data interchange format +Copyright 2008 Google Inc. All rights reserved. +https://developers.google.com/protocol-buffers/ + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + + +#### Types: + + +- [Empty](#Empty) + + + + +##### Source File: [github.com/solo-io/solo-kit/api/external/google/protobuf/empty.proto](https://github.com/solo-io/solo-kit/blob/master/api/external/google/protobuf/empty.proto) + + + + + +--- +### Empty + + +A generic empty message that you can re-use to avoid defining duplicated +empty messages in your APIs. A typical example is to use it as the request +or the response type of an API method. For instance: + + service Foo { + rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty); + } + +The JSON representation for `Empty` is empty JSON object `{}`. + +```yaml + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | + + + + + + + + diff --git a/test/mocks/api/doc/google/protobuf/struct.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/protobuf/struct.proto.sk.md similarity index 90% rename from test/mocks/api/doc/google/protobuf/struct.proto.sk.md rename to test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/protobuf/struct.proto.sk.md index 27237edd3..fd94e7dff 100644 --- a/test/mocks/api/doc/google/protobuf/struct.proto.sk.md +++ b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/protobuf/struct.proto.sk.md @@ -1,12 +1,5 @@ - ---- -title: "struct.proto" -weight: 5 ---- - - ### Package: `google.protobuf` Protocol Buffers - Google's data interchange format Copyright 2008 Google Inc. All rights reserved. @@ -43,9 +36,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #### Types: -- [Struct](#struct) -- [Value](#value) -- [ListValue](#listvalue) +- [Struct](#Struct) +- [Value](#Value) +- [ListValue](#ListValue) @@ -53,18 +46,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ##### Enums: - - [NullValue](#nullvalue) + - [NullValue](#NullValue) -##### Source File: `google/protobuf/struct.proto` +##### Source File: [github.com/solo-io/solo-kit/api/external/google/protobuf/struct.proto](https://github.com/solo-io/solo-kit/blob/master/api/external/google/protobuf/struct.proto) --- -### Struct +### Struct `Struct` represents a structured data value, consisting of fields @@ -89,7 +82,7 @@ The JSON representation for `Struct` is JSON object. --- -### Value +### Value `Value` represents a dynamically typed value which can be either @@ -122,7 +115,7 @@ The JSON representation for `Value` is JSON value. --- -### ListValue +### ListValue `ListValue` is a wrapper around a repeated field of values. @@ -136,12 +129,12 @@ The JSON representation for `ListValue` is JSON array. | Field | Type | Description | Default | | ----- | ---- | ----------- |----------- | -| `values` | [[]google.protobuf.Value](../struct.proto.sk#value) | Repeated field of dynamically typed values. | | +| `values` | [[]google.protobuf.Value](struct.proto.sk.md#Value) | Repeated field of dynamically typed values. | | -### NullValue +### NullValue Description: `NullValue` is a singleton enumeration to represent the null value for the `Value` type union. diff --git a/test/mocks/api/doc/google/protobuf/timestamp.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/protobuf/timestamp.proto.sk.md similarity index 95% rename from test/mocks/api/doc/google/protobuf/timestamp.proto.sk.md rename to test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/protobuf/timestamp.proto.sk.md index b714bfd37..91f6c55ac 100644 --- a/test/mocks/api/doc/google/protobuf/timestamp.proto.sk.md +++ b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/protobuf/timestamp.proto.sk.md @@ -1,12 +1,5 @@ - ---- -title: "timestamp.proto" -weight: 5 ---- - - ### Package: `google.protobuf` Protocol Buffers - Google's data interchange format Copyright 2008 Google Inc. All rights reserved. @@ -43,19 +36,19 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #### Types: -- [Timestamp](#timestamp) +- [Timestamp](#Timestamp) -##### Source File: `google/protobuf/timestamp.proto` +##### Source File: [github.com/solo-io/solo-kit/api/external/google/protobuf/timestamp.proto](https://github.com/solo-io/solo-kit/blob/master/api/external/google/protobuf/timestamp.proto) --- -### Timestamp +### Timestamp A Timestamp represents a point in time independent of any time zone diff --git a/test/mocks/api/doc/google/protobuf/wrappers.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/protobuf/wrappers.proto.sk.md similarity index 84% rename from test/mocks/api/doc/google/protobuf/wrappers.proto.sk.md rename to test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/protobuf/wrappers.proto.sk.md index 2947f9779..de47661f7 100644 --- a/test/mocks/api/doc/google/protobuf/wrappers.proto.sk.md +++ b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/protobuf/wrappers.proto.sk.md @@ -1,12 +1,5 @@ - ---- -title: "wrappers.proto" -weight: 5 ---- - - ### Package: `google.protobuf` Protocol Buffers - Google's data interchange format Copyright 2008 Google Inc. All rights reserved. @@ -47,27 +40,27 @@ typed field and its default value. #### Types: -- [DoubleValue](#doublevalue) -- [FloatValue](#floatvalue) -- [Int64Value](#int64value) -- [UInt64Value](#uint64value) -- [Int32Value](#int32value) -- [UInt32Value](#uint32value) -- [BoolValue](#boolvalue) -- [StringValue](#stringvalue) -- [BytesValue](#bytesvalue) +- [DoubleValue](#DoubleValue) +- [FloatValue](#FloatValue) +- [Int64Value](#Int64Value) +- [UInt64Value](#UInt64Value) +- [Int32Value](#Int32Value) +- [UInt32Value](#UInt32Value) +- [BoolValue](#BoolValue) +- [StringValue](#StringValue) +- [BytesValue](#BytesValue) -##### Source File: `google/protobuf/wrappers.proto` +##### Source File: [github.com/solo-io/solo-kit/api/external/google/protobuf/wrappers.proto](https://github.com/solo-io/solo-kit/blob/master/api/external/google/protobuf/wrappers.proto) --- -### DoubleValue +### DoubleValue Wrapper message for `double`. @@ -87,7 +80,7 @@ The JSON representation for `DoubleValue` is JSON number. --- -### FloatValue +### FloatValue Wrapper message for `float`. @@ -107,7 +100,7 @@ The JSON representation for `FloatValue` is JSON number. --- -### Int64Value +### Int64Value Wrapper message for `int64`. @@ -127,7 +120,7 @@ The JSON representation for `Int64Value` is JSON string. --- -### UInt64Value +### UInt64Value Wrapper message for `uint64`. @@ -147,7 +140,7 @@ The JSON representation for `UInt64Value` is JSON string. --- -### Int32Value +### Int32Value Wrapper message for `int32`. @@ -167,7 +160,7 @@ The JSON representation for `Int32Value` is JSON number. --- -### UInt32Value +### UInt32Value Wrapper message for `uint32`. @@ -187,7 +180,7 @@ The JSON representation for `UInt32Value` is JSON number. --- -### BoolValue +### BoolValue Wrapper message for `bool`. @@ -207,7 +200,7 @@ The JSON representation for `BoolValue` is JSON `true` and `false`. --- -### StringValue +### StringValue Wrapper message for `string`. @@ -227,7 +220,7 @@ The JSON representation for `StringValue` is JSON string. --- -### BytesValue +### BytesValue Wrapper message for `bytes`. diff --git a/test/mocks/api/doc/google/rpc/status.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/rpc/status.proto.sk.md similarity index 89% rename from test/mocks/api/doc/google/rpc/status.proto.sk.md rename to test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/rpc/status.proto.sk.md index 54fa7c418..c8e82bd53 100644 --- a/test/mocks/api/doc/google/rpc/status.proto.sk.md +++ b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/google/rpc/status.proto.sk.md @@ -1,12 +1,5 @@ - ---- -title: "status.proto" -weight: 5 ---- - - ### Package: `google.rpc` Copyright 2017 Google Inc. @@ -27,19 +20,19 @@ limitations under the License. #### Types: -- [Status](#status) +- [Status](#Status) -##### Source File: `google/rpc/status.proto` +##### Source File: [github.com/solo-io/solo-kit/api/external/google/rpc/status.proto](https://github.com/solo-io/solo-kit/blob/master/api/external/google/rpc/status.proto) --- -### Status +### Status The `Status` type defines a logical error model that is suitable for different @@ -106,7 +99,7 @@ Example uses of this error model include: | ----- | ---- | ----------- |----------- | | `code` | `int` | The status code, which should be an enum value of [google.rpc.Code][google.rpc.Code]. | | | `message` | `string` | A developer-facing error message, which should be in English. Any user-facing error message should be localized and sent in the [google.rpc.Status.details][google.rpc.Status.details] field, or localized by the client. | | -| `details` | [[]google.protobuf.Any](../../protobuf/any.proto.sk#any) | A list of messages that carry the error details. There is a common set of message types for APIs to use. | | +| `details` | [[]google.protobuf.Any](../../../../../../../google/protobuf/any.proto.sk.md#Any) | A list of messages that carry the error details. There is a common set of message types for APIs to use. | | diff --git a/test/mocks/docs/github.com/solo-io/solo-kit/api/external/metrics.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/metrics.proto.sk.md new file mode 100644 index 000000000..87d3a1a9c --- /dev/null +++ b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/metrics.proto.sk.md @@ -0,0 +1,266 @@ + + +### Package: `io.prometheus.client` +Copyright 2013 Prometheus Team +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + + +#### Types: + + +- [LabelPair](#LabelPair) +- [Gauge](#Gauge) +- [Counter](#Counter) +- [Quantile](#Quantile) +- [Summary](#Summary) +- [Untyped](#Untyped) +- [Histogram](#Histogram) +- [Bucket](#Bucket) +- [Metric](#Metric) +- [MetricFamily](#MetricFamily) + + + + +##### Enums: + + + - [MetricType](#MetricType) + + + +##### Source File: [github.com/solo-io/solo-kit/api/external/metrics.proto](https://github.com/solo-io/solo-kit/blob/master/api/external/metrics.proto) + + + + + +--- +### LabelPair + + + +```yaml +"name": string +"value": string + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `name` | `string` | | | +| `value` | `string` | | | + + + + +--- +### Gauge + + + +```yaml +"value": float + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `value` | `float` | | | + + + + +--- +### Counter + + + +```yaml +"value": float + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `value` | `float` | | | + + + + +--- +### Quantile + + + +```yaml +"quantile": float +"value": float + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `quantile` | `float` | | | +| `value` | `float` | | | + + + + +--- +### Summary + + + +```yaml +"sampleCount": int +"sampleSum": float +"quantile": []io.prometheus.client.Quantile + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `sampleCount` | `int` | | | +| `sampleSum` | `float` | | | +| `quantile` | [[]io.prometheus.client.Quantile](metrics.proto.sk.md#Quantile) | | | + + + + +--- +### Untyped + + + +```yaml +"value": float + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `value` | `float` | | | + + + + +--- +### Histogram + + + +```yaml +"sampleCount": int +"sampleSum": float +"bucket": []io.prometheus.client.Bucket + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `sampleCount` | `int` | | | +| `sampleSum` | `float` | | | +| `bucket` | [[]io.prometheus.client.Bucket](metrics.proto.sk.md#Bucket) | | | + + + + +--- +### Bucket + + + +```yaml +"cumulativeCount": int +"upperBound": float + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `cumulativeCount` | `int` | | | +| `upperBound` | `float` | | | + + + + +--- +### Metric + + + +```yaml +"label": []io.prometheus.client.LabelPair +"gauge": .io.prometheus.client.Gauge +"counter": .io.prometheus.client.Counter +"summary": .io.prometheus.client.Summary +"untyped": .io.prometheus.client.Untyped +"histogram": .io.prometheus.client.Histogram +"timestampMs": int + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `label` | [[]io.prometheus.client.LabelPair](metrics.proto.sk.md#LabelPair) | | | +| `gauge` | [.io.prometheus.client.Gauge](metrics.proto.sk.md#Gauge) | | | +| `counter` | [.io.prometheus.client.Counter](metrics.proto.sk.md#Counter) | | | +| `summary` | [.io.prometheus.client.Summary](metrics.proto.sk.md#Summary) | | | +| `untyped` | [.io.prometheus.client.Untyped](metrics.proto.sk.md#Untyped) | | | +| `histogram` | [.io.prometheus.client.Histogram](metrics.proto.sk.md#Histogram) | | | +| `timestampMs` | `int` | | | + + + + +--- +### MetricFamily + + + +```yaml +"name": string +"help": string +"type": .io.prometheus.client.MetricType +"metric": []io.prometheus.client.Metric + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `name` | `string` | | | +| `help` | `string` | | | +| `type` | [.io.prometheus.client.MetricType](metrics.proto.sk.md#MetricType) | | | +| `metric` | [[]io.prometheus.client.Metric](metrics.proto.sk.md#Metric) | | | + + + + +### MetricType + +Description: + +| Name | Description | +| ----- | ----------- | +| COUNTER | | +| GAUGE | | +| SUMMARY | | +| UNTYPED | | +| HISTOGRAM | | + + + + + diff --git a/test/mocks/docs/github.com/solo-io/solo-kit/api/external/trace.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/trace.proto.sk.md new file mode 100644 index 000000000..63b55919a --- /dev/null +++ b/test/mocks/docs/github.com/solo-io/solo-kit/api/external/trace.proto.sk.md @@ -0,0 +1,467 @@ + + +### Package: `opencensus.proto.trace` +Copyright 2017, OpenCensus Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + + + +#### Types: + + +- [Span](#Span) +- [Attributes](#Attributes) +- [TimeEvent](#TimeEvent) +- [Annotation](#Annotation) +- [MessageEvent](#MessageEvent) +- [Type](#Type) +- [TimeEvents](#TimeEvents) +- [Link](#Link) +- [Type](#Type) +- [Links](#Links) +- [SpanKind](#SpanKind) +- [Status](#Status) +- [AttributeValue](#AttributeValue) +- [StackTrace](#StackTrace) +- [StackFrame](#StackFrame) +- [StackFrames](#StackFrames) +- [Module](#Module) +- [TruncatableString](#TruncatableString) + + + + +##### Source File: [github.com/solo-io/solo-kit/api/external/trace.proto](https://github.com/solo-io/solo-kit/blob/master/api/external/trace.proto) + + + + + +--- +### Span + + +A span represents a single operation within a trace. Spans can be +nested to form a trace tree. Often, a trace contains a root span +that describes the end-to-end latency, and one or more subspans for +its sub-operations. A trace can also contain multiple root spans, +or none at all. Spans do not need to be contiguous - there may be +gaps or overlaps between spans in a trace. + +The next id is 15. +TODO(bdrutu): Add an example. + +```yaml +"traceId": bytes +"spanId": bytes +"parentSpanId": bytes +"name": .opencensus.proto.trace.TruncatableString +"kind": .opencensus.proto.trace.Span.SpanKind +"startTime": .google.protobuf.Timestamp +"endTime": .google.protobuf.Timestamp +"attributes": .opencensus.proto.trace.Span.Attributes +"stackTrace": .opencensus.proto.trace.StackTrace +"timeEvents": .opencensus.proto.trace.Span.TimeEvents +"links": .opencensus.proto.trace.Span.Links +"status": .opencensus.proto.trace.Status +"sameProcessAsParentSpan": .google.protobuf.BoolValue +"childSpanCount": .google.protobuf.UInt32Value + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `traceId` | `bytes` | A unique identifier for a trace. All spans from the same trace share the same `trace_id`. The ID is a 16-byte array. This field is required. | | +| `spanId` | `bytes` | A unique identifier for a span within a trace, assigned when the span is created. The ID is an 8-byte array. This field is required. | | +| `parentSpanId` | `bytes` | The `span_id` of this span's parent span. If this is a root span, then this field must be empty. The ID is an 8-byte array. | | +| `name` | [.opencensus.proto.trace.TruncatableString](trace.proto.sk.md#TruncatableString) | A description of the span's operation. For example, the name can be a qualified method name or a file name and a line number where the operation is called. A best practice is to use the same display name at the same call point in an application. This makes it easier to correlate spans in different traces. This field is required. | | +| `kind` | [.opencensus.proto.trace.Span.SpanKind](trace.proto.sk.md#SpanKind) | Distinguishes between spans generated in a particular context. For example, two spans with the same name may be distinguished using `CLIENT` and `SERVER` to identify queueing latency associated with the span. | | +| `startTime` | [.google.protobuf.Timestamp](https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/timestamp) | The start time of the span. On the client side, this is the time kept by the local machine where the span execution starts. On the server side, this is the time when the server's application handler starts running. | | +| `endTime` | [.google.protobuf.Timestamp](https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/timestamp) | The end time of the span. On the client side, this is the time kept by the local machine where the span execution ends. On the server side, this is the time when the server application handler stops running. | | +| `attributes` | [.opencensus.proto.trace.Span.Attributes](trace.proto.sk.md#Attributes) | A set of attributes on the span. | | +| `stackTrace` | [.opencensus.proto.trace.StackTrace](trace.proto.sk.md#StackTrace) | A stack trace captured at the start of the span. | | +| `timeEvents` | [.opencensus.proto.trace.Span.TimeEvents](trace.proto.sk.md#TimeEvents) | The included time events. | | +| `links` | [.opencensus.proto.trace.Span.Links](trace.proto.sk.md#Links) | The inclued links. | | +| `status` | [.opencensus.proto.trace.Status](trace.proto.sk.md#Status) | An optional final status for this span. | | +| `sameProcessAsParentSpan` | [.google.protobuf.BoolValue](https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/bool-value) | A highly recommended but not required flag that identifies when a trace crosses a process boundary. True when the parent_span belongs to the same process as the current span. | | +| `childSpanCount` | [.google.protobuf.UInt32Value](https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/u-int-32-value) | An optional number of child spans that were generated while this span was active. If set, allows an implementation to detect missing child spans. | | + + + + +--- +### Attributes + + +A set of attributes, each with a key and a value. + +```yaml +"attributeMap": map +"droppedAttributesCount": int + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `attributeMap` | `map` | The set of attributes. The value can be a string, an integer, or the Boolean values `true` and `false`. For example: "/instance_id": "my-instance" "/http/user_agent": "" "/http/server_latency": 300 "abc.com/myattribute": true | | +| `droppedAttributesCount` | `int` | The number of attributes that were discarded. Attributes can be discarded because their keys are too long or because there are too many attributes. If this value is 0, then no attributes were dropped. | | + + + + +--- +### TimeEvent + + +A time-stamped annotation or message event in the Span. + +```yaml +"time": .google.protobuf.Timestamp +"annotation": .opencensus.proto.trace.Span.TimeEvent.Annotation +"messageEvent": .opencensus.proto.trace.Span.TimeEvent.MessageEvent + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `time` | [.google.protobuf.Timestamp](https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/timestamp) | The time the event occurred. | | +| `annotation` | [.opencensus.proto.trace.Span.TimeEvent.Annotation](trace.proto.sk.md#Annotation) | A text annotation with a set of attributes. | | +| `messageEvent` | [.opencensus.proto.trace.Span.TimeEvent.MessageEvent](trace.proto.sk.md#MessageEvent) | An event describing a message sent/received between Spans. | | + + + + +--- +### Annotation + + +A text annotation with a set of attributes. + +```yaml +"description": .opencensus.proto.trace.TruncatableString +"attributes": .opencensus.proto.trace.Span.Attributes + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `description` | [.opencensus.proto.trace.TruncatableString](trace.proto.sk.md#TruncatableString) | A user-supplied message describing the event. | | +| `attributes` | [.opencensus.proto.trace.Span.Attributes](trace.proto.sk.md#Attributes) | A set of attributes on the annotation. | | + + + + +--- +### MessageEvent + + +An event describing a message sent/received between Spans. + +```yaml +"type": .opencensus.proto.trace.Span.TimeEvent.MessageEvent.Type +"id": int +"uncompressedSize": int +"compressedSize": int + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `type` | [.opencensus.proto.trace.Span.TimeEvent.MessageEvent.Type](trace.proto.sk.md#Type) | The type of MessageEvent. Indicates whether the message was sent or received. | | +| `id` | `int` | An identifier for the MessageEvent's message that can be used to match SENT and RECEIVED MessageEvents. For example, this field could represent a sequence ID for a streaming RPC. It is recommended to be unique within a Span. | | +| `uncompressedSize` | `int` | The number of uncompressed bytes sent or received. | | +| `compressedSize` | `int` | The number of compressed bytes sent or received. If zero, assumed to be the same size as uncompressed. | | + + + + +--- +### Type + + +Indicates whether the message was sent or received. + +| Name | Description | +| ----- | ----------- | +| `TYPE_UNSPECIFIED` | Unknown event type. | +| `SENT` | Indicates a sent message. | +| `RECEIVED` | Indicates a received message. | + + + + +--- +### TimeEvents + + +A collection of `TimeEvent`s. A `TimeEvent` is a time-stamped annotation +on the span, consisting of either user-supplied key-value pairs, or +details of a message sent/received between Spans. + +```yaml +"timeEvent": []opencensus.proto.trace.Span.TimeEvent +"droppedAnnotationsCount": int +"droppedMessageEventsCount": int + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `timeEvent` | [[]opencensus.proto.trace.Span.TimeEvent](trace.proto.sk.md#TimeEvent) | A collection of `TimeEvent`s. | | +| `droppedAnnotationsCount` | `int` | The number of dropped annotations in all the included time events. If the value is 0, then no annotations were dropped. | | +| `droppedMessageEventsCount` | `int` | The number of dropped message events in all the included time events. If the value is 0, then no message events were dropped. | | + + + + +--- +### Link + + +A pointer from the current span to another span in the same trace or in a +different trace. For example, this can be used in batching operations, +where a single batch handler processes multiple requests from different +traces or when the handler receives a request from a different project. + +```yaml +"traceId": bytes +"spanId": bytes +"type": .opencensus.proto.trace.Span.Link.Type +"attributes": .opencensus.proto.trace.Span.Attributes + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `traceId` | `bytes` | A unique identifier for a trace. All spans from the same trace share the same `trace_id`. The ID is a 16-byte array. | | +| `spanId` | `bytes` | A unique identifier for a span within a trace, assigned when the span is created. The ID is an 8-byte array. | | +| `type` | [.opencensus.proto.trace.Span.Link.Type](trace.proto.sk.md#Type) | The relationship of the current span relative to the linked span. | | +| `attributes` | [.opencensus.proto.trace.Span.Attributes](trace.proto.sk.md#Attributes) | A set of attributes on the link. | | + + + + +--- +### Type + + +The relationship of the current span relative to the linked span: child, +parent, or unspecified. + +| Name | Description | +| ----- | ----------- | +| `TYPE_UNSPECIFIED` | The relationship of the two spans is unknown, or known but other than parent-child. | +| `CHILD_LINKED_SPAN` | The linked span is a child of the current span. | +| `PARENT_LINKED_SPAN` | The linked span is a parent of the current span. | + + + + +--- +### Links + + +A collection of links, which are references from this span to a span +in the same or different trace. + +```yaml +"link": []opencensus.proto.trace.Span.Link +"droppedLinksCount": int + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `link` | [[]opencensus.proto.trace.Span.Link](trace.proto.sk.md#Link) | A collection of links. | | +| `droppedLinksCount` | `int` | The number of dropped links after the maximum size was enforced. If this value is 0, then no links were dropped. | | + + + + +--- +### SpanKind + + +Type of span. Can be used to specify additional relationships between spans +in addition to a parent/child relationship. + +| Name | Description | +| ----- | ----------- | +| `SPAN_KIND_UNSPECIFIED` | Unspecified. | +| `SERVER` | Indicates that the span covers server-side handling of an RPC or other remote network request. | +| `CLIENT` | Indicates that the span covers the client-side wrapper around an RPC or other remote request. | + + + + +--- +### Status + + +The `Status` type defines a logical error model that is suitable for different +programming environments, including REST APIs and RPC APIs. This proto's fields +are a subset of those of +[google.rpc.Status](https://github.com/googleapis/googleapis/blob/master/google/rpc/status.proto), +which is used by [gRPC](https://github.com/grpc). + +```yaml +"code": int +"message": string + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `code` | `int` | The status code. | | +| `message` | `string` | A developer-facing error message, which should be in English. | | + + + + +--- +### AttributeValue + + +The value of an Attribute. + +```yaml +"stringValue": .opencensus.proto.trace.TruncatableString +"intValue": int +"boolValue": bool + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `stringValue` | [.opencensus.proto.trace.TruncatableString](trace.proto.sk.md#TruncatableString) | A string up to 256 bytes long. | | +| `intValue` | `int` | A 64-bit signed integer. | | +| `boolValue` | `bool` | A Boolean value represented by `true` or `false`. | | + + + + +--- +### StackTrace + + +The call stack which originated this span. + +```yaml +"stackFrames": .opencensus.proto.trace.StackTrace.StackFrames +"stackTraceHashId": int + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `stackFrames` | [.opencensus.proto.trace.StackTrace.StackFrames](trace.proto.sk.md#StackFrames) | Stack frames in this stack trace. | | +| `stackTraceHashId` | `int` | The hash ID is used to conserve network bandwidth for duplicate stack traces within a single trace. Often multiple spans will have identical stack traces. The first occurrence of a stack trace should contain both `stack_frames` and a value in `stack_trace_hash_id`. Subsequent spans within the same request can refer to that stack trace by setting only `stack_trace_hash_id`. TODO: describe how to deal with the case where stack_trace_hash_id is zero because it was not set. | | + + + + +--- +### StackFrame + + +A single stack frame in a stack trace. + +```yaml +"functionName": .opencensus.proto.trace.TruncatableString +"originalFunctionName": .opencensus.proto.trace.TruncatableString +"fileName": .opencensus.proto.trace.TruncatableString +"lineNumber": int +"columnNumber": int +"loadModule": .opencensus.proto.trace.Module +"sourceVersion": .opencensus.proto.trace.TruncatableString + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `functionName` | [.opencensus.proto.trace.TruncatableString](trace.proto.sk.md#TruncatableString) | The fully-qualified name that uniquely identifies the function or method that is active in this frame. | | +| `originalFunctionName` | [.opencensus.proto.trace.TruncatableString](trace.proto.sk.md#TruncatableString) | An un-mangled function name, if `function_name` is [mangled](http://www.avabodh.com/cxxin/namemangling.html). The name can be fully qualified. | | +| `fileName` | [.opencensus.proto.trace.TruncatableString](trace.proto.sk.md#TruncatableString) | The name of the source file where the function call appears. | | +| `lineNumber` | `int` | The line number in `file_name` where the function call appears. | | +| `columnNumber` | `int` | The column number where the function call appears, if available. This is important in JavaScript because of its anonymous functions. | | +| `loadModule` | [.opencensus.proto.trace.Module](trace.proto.sk.md#Module) | The binary module from where the code was loaded. | | +| `sourceVersion` | [.opencensus.proto.trace.TruncatableString](trace.proto.sk.md#TruncatableString) | The version of the deployed source code. | | + + + + +--- +### StackFrames + + +A collection of stack frames, which can be truncated. + +```yaml +"frame": []opencensus.proto.trace.StackTrace.StackFrame +"droppedFramesCount": int + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `frame` | [[]opencensus.proto.trace.StackTrace.StackFrame](trace.proto.sk.md#StackFrame) | Stack frames in this call stack. | | +| `droppedFramesCount` | `int` | The number of stack frames that were dropped because there were too many stack frames. If this value is 0, then no stack frames were dropped. | | + + + + +--- +### Module + + +A description of a binary module. + +```yaml +"module": .opencensus.proto.trace.TruncatableString +"buildId": .opencensus.proto.trace.TruncatableString + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `module` | [.opencensus.proto.trace.TruncatableString](trace.proto.sk.md#TruncatableString) | TODO: document the meaning of this field. For example: main binary, kernel modules, and dynamic libraries such as libc.so, sharedlib.so. | | +| `buildId` | [.opencensus.proto.trace.TruncatableString](trace.proto.sk.md#TruncatableString) | A unique identifier for the module, usually a hash of its contents. | | + + + + +--- +### TruncatableString + + +A string that might be shortened to a specified length. + +```yaml +"value": string +"truncatedByteCount": int + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `value` | `string` | The shortened string. For example, if the original string was 500 bytes long and the limit of the string was 128 bytes, then this value contains the first 128 bytes of the 500-byte string. Note that truncation always happens on a character boundary, to ensure that a truncated string is still valid UTF-8. Because it may contain multi-byte characters, the size of the truncated string may be less than the truncation limit. | | +| `truncatedByteCount` | `int` | The number of bytes removed from the original string. If this value is 0, then the string was not shortened. | | + + + + + + + + diff --git a/test/mocks/api/doc/github.com/solo-io/solo-kit/api/v1/metadata.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/api/v1/metadata.proto.sk.md similarity index 95% rename from test/mocks/api/doc/github.com/solo-io/solo-kit/api/v1/metadata.proto.sk.md rename to test/mocks/docs/github.com/solo-io/solo-kit/api/v1/metadata.proto.sk.md index bf8270335..547dba1ea 100644 --- a/test/mocks/api/doc/github.com/solo-io/solo-kit/api/v1/metadata.proto.sk.md +++ b/test/mocks/docs/github.com/solo-io/solo-kit/api/v1/metadata.proto.sk.md @@ -1,17 +1,10 @@ - ---- -title: "metadata.proto" -weight: 5 ---- - - ### Package: `core.solo.io` #### Types: -- [Metadata](#metadata) +- [Metadata](#Metadata) @@ -23,7 +16,7 @@ weight: 5 --- -### Metadata +### Metadata * diff --git a/test/mocks/docs/github.com/solo-io/solo-kit/api/v1/ref.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/api/v1/ref.proto.sk.md new file mode 100644 index 000000000..2324d2c15 --- /dev/null +++ b/test/mocks/docs/github.com/solo-io/solo-kit/api/v1/ref.proto.sk.md @@ -0,0 +1,42 @@ + + +### Package: `core.solo.io` +#### Types: + + +- [ResourceRef](#ResourceRef) + + + + +##### Source File: [github.com/solo-io/solo-kit/api/v1/ref.proto](https://github.com/solo-io/solo-kit/blob/master/api/v1/ref.proto) + + + + + +--- +### ResourceRef + + +A way to reference resources across namespaces +TODO(ilackarms): make upstreamname and secretref into ResourceRefs + +```yaml +"name": string +"namespace": string + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `name` | `string` | | | +| `namespace` | `string` | | | + + + + + + + + diff --git a/test/mocks/api/doc/github.com/solo-io/solo-kit/api/v1/solo-kit.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/api/v1/solo-kit.proto.sk.md similarity index 92% rename from test/mocks/api/doc/github.com/solo-io/solo-kit/api/v1/solo-kit.proto.sk.md rename to test/mocks/docs/github.com/solo-io/solo-kit/api/v1/solo-kit.proto.sk.md index 7e9901caa..942289de7 100644 --- a/test/mocks/api/doc/github.com/solo-io/solo-kit/api/v1/solo-kit.proto.sk.md +++ b/test/mocks/docs/github.com/solo-io/solo-kit/api/v1/solo-kit.proto.sk.md @@ -1,17 +1,10 @@ - ---- -title: "solo-kit.proto" -weight: 5 ---- - - ### Package: `core.solo.io` #### Types: -- [Resource](#resource) +- [Resource](#Resource) @@ -23,7 +16,7 @@ weight: 5 --- -### Resource +### Resource diff --git a/test/mocks/api/doc/github.com/solo-io/solo-kit/api/v1/status.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/api/v1/status.proto.sk.md similarity index 90% rename from test/mocks/api/doc/github.com/solo-io/solo-kit/api/v1/status.proto.sk.md rename to test/mocks/docs/github.com/solo-io/solo-kit/api/v1/status.proto.sk.md index c10e8b579..aaf41b2e5 100644 --- a/test/mocks/api/doc/github.com/solo-io/solo-kit/api/v1/status.proto.sk.md +++ b/test/mocks/docs/github.com/solo-io/solo-kit/api/v1/status.proto.sk.md @@ -1,18 +1,11 @@ - ---- -title: "status.proto" -weight: 5 ---- - - ### Package: `core.solo.io` #### Types: -- [Status](#status) -- [State](#state) +- [Status](#Status) +- [State](#State) @@ -24,7 +17,7 @@ weight: 5 --- -### Status +### Status * @@ -41,7 +34,7 @@ Statuses are meant to be read-only by users | Field | Type | Description | Default | | ----- | ---- | ----------- |----------- | -| `state` | [.core.solo.io.Status.State](../status.proto.sk#state) | State is the enum indicating the state of the resource | | +| `state` | [.core.solo.io.Status.State](status.proto.sk.md#State) | State is the enum indicating the state of the resource | | | `reason` | `string` | Reason is a description of the error for Rejected resources. If the resource is pending or accepted, this field will be empty | | | `reportedBy` | `string` | Reference to the reporter who wrote this status | | | `subresourceStatuses` | `map` | Reference to statuses (by resource-ref string: "Kind.Namespace.Name") of subresources of the parent resource | | @@ -50,7 +43,7 @@ Statuses are meant to be read-only by users --- -### State +### State diff --git a/test/mocks/docs/github.com/solo-io/solo-kit/pkg/api/v1/apiserver/api_server.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/pkg/api/v1/apiserver/api_server.proto.sk.md new file mode 100644 index 000000000..7cc8e2654 --- /dev/null +++ b/test/mocks/docs/github.com/solo-io/solo-kit/pkg/api/v1/apiserver/api_server.proto.sk.md @@ -0,0 +1,247 @@ + + +### Package: `apiserver.api.v1` +#### Types: + + +- [ReadRequest](#ReadRequest) +- [ReadResponse](#ReadResponse) +- [WriteRequest](#WriteRequest) +- [WriteResponse](#WriteResponse) +- [DeleteRequest](#DeleteRequest) +- [DeleteResponse](#DeleteResponse) +- [ListRequest](#ListRequest) +- [ListResponse](#ListResponse) +- [WatchRequest](#WatchRequest) +- [WatchResponse](#WatchResponse) +- [RegisterRequest](#RegisterRequest) +- [RegisterResponse](#RegisterResponse) + + + + +##### Source File: [github.com/solo-io/solo-kit/pkg/api/v1/apiserver/api_server.proto](https://github.com/solo-io/solo-kit/blob/master/pkg/api/v1/apiserver/api_server.proto) + + + + + +--- +### ReadRequest + + +GRPC stuff + +```yaml +"name": string +"namespace": string +"typeUrl": string + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `name` | `string` | | | +| `namespace` | `string` | | | +| `typeUrl` | `string` | | | + + + + +--- +### ReadResponse + + + +```yaml +"resource": .google.protobuf.Any + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `resource` | [.google.protobuf.Any](https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/any) | | | + + + + +--- +### WriteRequest + + + +```yaml +"resource": .google.protobuf.Any +"overwriteExisting": bool + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `resource` | [.google.protobuf.Any](https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/any) | | | +| `overwriteExisting` | `bool` | | | + + + + +--- +### WriteResponse + + + +```yaml +"resource": .google.protobuf.Any + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `resource` | [.google.protobuf.Any](https://developers.google.com/protocol-buffers/docs/reference/csharp/class/google/protobuf/well-known-types/any) | | | + + + + +--- +### DeleteRequest + + + +```yaml +"name": string +"namespace": string +"typeUrl": string +"ignoreNotExist": bool + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `name` | `string` | | | +| `namespace` | `string` | | | +| `typeUrl` | `string` | | | +| `ignoreNotExist` | `bool` | | | + + + + +--- +### DeleteResponse + + + +```yaml + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | + + + + +--- +### ListRequest + + + +```yaml +"namespace": string +"typeUrl": string + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `namespace` | `string` | | | +| `typeUrl` | `string` | | | + + + + +--- +### ListResponse + + + +```yaml +"resourceList": []google.protobuf.Any + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `resourceList` | [[]google.protobuf.Any](../../../../../../../google/protobuf/any.proto.sk.md#Any) | | | + + + + +--- +### WatchRequest + + + +```yaml +"namespace": string +"typeUrl": string + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `namespace` | `string` | | | +| `typeUrl` | `string` | | | + + + + +--- +### WatchResponse + + + +```yaml +"resourceList": []google.protobuf.Any + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `resourceList` | [[]google.protobuf.Any](../../../../../../../google/protobuf/any.proto.sk.md#Any) | | | + + + + +--- +### RegisterRequest + + + +```yaml + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | + + + + +--- +### RegisterResponse + + + +```yaml + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | + + + + + + + + diff --git a/test/mocks/docs/github.com/solo-io/solo-kit/test/mocks/api/v1/mock_resources.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/test/mocks/api/v1/mock_resources.proto.sk.md new file mode 100644 index 000000000..adf957d03 --- /dev/null +++ b/test/mocks/docs/github.com/solo-io/solo-kit/test/mocks/api/v1/mock_resources.proto.sk.md @@ -0,0 +1,95 @@ + + +### Package: `testing.solo.io` +Syntax Comments +Syntax Comments a + + + +#### Types: + + +- [MockResource](#MockResource) **Top-Level Resource** +- [FakeResource](#FakeResource) **Top-Level Resource** +- [MockXdsResourceConfig](#MockXdsResourceConfig) + + + + +##### Source File: [github.com/solo-io/solo-kit/test/mocks/api/v1/mock_resources.proto](https://github.com/solo-io/solo-kit/blob/master/test/mocks/api/v1/mock_resources.proto) + + + + + +--- +### MockResource + + +Mock resources for goofin off + +```yaml +"status": .core.solo.io.Status +"metadata": .core.solo.io.Metadata +"data": string +"someDumbField": string +"oneofOne": string +"oneofTwo": bool + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `status` | [.core.solo.io.Status](../../../../api/v1/status.proto.sk.md#Status) | | | +| `metadata` | [.core.solo.io.Metadata](../../../../api/v1/metadata.proto.sk.md#Metadata) | | | +| `data` | `string` | | | +| `someDumbField` | `string` | | | +| `oneofOne` | `string` | | | +| `oneofTwo` | `bool` | | | + + + + +--- +### FakeResource + + + +```yaml +"count": int +"metadata": .core.solo.io.Metadata +"status": .core.solo.io.Status + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `count` | `int` | | | +| `metadata` | [.core.solo.io.Metadata](../../../../api/v1/metadata.proto.sk.md#Metadata) | | | +| `status` | [.core.solo.io.Status](../../../../api/v1/status.proto.sk.md#Status) | | | + + + + +--- +### MockXdsResourceConfig + + + + +```yaml +"domain": string + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `domain` | `string` | | | + + + + + + + + diff --git a/test/mocks/docs/github.com/solo-io/solo-kit/test/mocks/api/v1/more_mock_resources.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/test/mocks/api/v1/more_mock_resources.proto.sk.md new file mode 100644 index 000000000..328c22284 --- /dev/null +++ b/test/mocks/docs/github.com/solo-io/solo-kit/test/mocks/api/v1/more_mock_resources.proto.sk.md @@ -0,0 +1,65 @@ + + +### Package: `testing.solo.io` +#### Types: + + +- [AnotherMockResource](#AnotherMockResource) **Top-Level Resource** +- [ClusterResource](#ClusterResource) **Top-Level Resource** + + + + +##### Source File: [github.com/solo-io/solo-kit/test/mocks/api/v1/more_mock_resources.proto](https://github.com/solo-io/solo-kit/blob/master/test/mocks/api/v1/more_mock_resources.proto) + + + + + +--- +### AnotherMockResource + + +Description of the AnotherMockResource + +```yaml +"metadata": .core.solo.io.Metadata +"status": .core.solo.io.Status +"basicField": string + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `metadata` | [.core.solo.io.Metadata](../../../../api/v1/metadata.proto.sk.md#Metadata) | | | +| `status` | [.core.solo.io.Status](../../../../api/v1/status.proto.sk.md#Status) | | | +| `basicField` | `string` | comments that go above the basic field in our docs | | + + + + +--- +### ClusterResource + + + +```yaml +"metadata": .core.solo.io.Metadata +"status": .core.solo.io.Status +"basicField": string + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `metadata` | [.core.solo.io.Metadata](../../../../api/v1/metadata.proto.sk.md#Metadata) | | | +| `status` | [.core.solo.io.Status](../../../../api/v1/status.proto.sk.md#Status) | | | +| `basicField` | `string` | comments that go above the basic field in our docs | | + + + + + + + + diff --git a/test/mocks/docs/github.com/solo-io/solo-kit/test/mocks/api/v1alpha1/mock_resources.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/test/mocks/api/v1alpha1/mock_resources.proto.sk.md new file mode 100644 index 000000000..f984b0dd8 --- /dev/null +++ b/test/mocks/docs/github.com/solo-io/solo-kit/test/mocks/api/v1alpha1/mock_resources.proto.sk.md @@ -0,0 +1,74 @@ + + +### Package: `testing.solo.io` +Syntax Comments +Syntax Comments a + + + +#### Types: + + +- [MockResource](#MockResource) **Top-Level Resource** +- [FakeResource](#FakeResource) **Top-Level Resource** + + + + +##### Source File: [github.com/solo-io/solo-kit/test/mocks/api/v1alpha1/mock_resources.proto](https://github.com/solo-io/solo-kit/blob/master/test/mocks/api/v1alpha1/mock_resources.proto) + + + + + +--- +### MockResource + + +Mock resources for goofin off + +```yaml +"status": .core.solo.io.Status +"metadata": .core.solo.io.Metadata +"data": string +"someDumbField": string +"oneofOne": string +"oneofTwo": bool + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `status` | [.core.solo.io.Status](../../../../api/v1/status.proto.sk.md#Status) | | | +| `metadata` | [.core.solo.io.Metadata](../../../../api/v1/metadata.proto.sk.md#Metadata) | | | +| `data` | `string` | | | +| `someDumbField` | `string` | | | +| `oneofOne` | `string` | | | +| `oneofTwo` | `bool` | | | + + + + +--- +### FakeResource + + + +```yaml +"count": int +"metadata": .core.solo.io.Metadata + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `count` | `int` | | | +| `metadata` | [.core.solo.io.Metadata](../../../../api/v1/metadata.proto.sk.md#Metadata) | | | + + + + + + + + diff --git a/test/mocks/docs/github.com/solo-io/solo-kit/test/mocks/api/v2alpha1/mock_resources.proto.sk.md b/test/mocks/docs/github.com/solo-io/solo-kit/test/mocks/api/v2alpha1/mock_resources.proto.sk.md new file mode 100644 index 000000000..49c214ffd --- /dev/null +++ b/test/mocks/docs/github.com/solo-io/solo-kit/test/mocks/api/v2alpha1/mock_resources.proto.sk.md @@ -0,0 +1,49 @@ + + +### Package: `testing.solo.io` +#### Types: + + +- [MockResource](#MockResource) **Top-Level Resource** + + + + +##### Source File: [github.com/solo-io/solo-kit/test/mocks/api/v2alpha1/mock_resources.proto](https://github.com/solo-io/solo-kit/blob/master/test/mocks/api/v2alpha1/mock_resources.proto) + + + + + +--- +### MockResource + + +The best mock resource you ever done seen + +```yaml +"status": .core.solo.io.Status +"metadata": .core.solo.io.Metadata +"someDumbField": string +"data": string +"oneofOne": string +"oneofTwo": bool + +``` + +| Field | Type | Description | Default | +| ----- | ---- | ----------- |----------- | +| `status` | [.core.solo.io.Status](../../../../api/v1/status.proto.sk.md#Status) | | | +| `metadata` | [.core.solo.io.Metadata](../../../../api/v1/metadata.proto.sk.md#Metadata) | | | +| `someDumbField` | `string` | | | +| `data` | `string` | | | +| `oneofOne` | `string` | | | +| `oneofTwo` | `bool` | | | + + + + + + + + diff --git a/test/mocks/api/doc/google/protobuf/any.proto.sk.md b/test/mocks/docs/google/protobuf/any.proto.sk.md similarity index 98% rename from test/mocks/api/doc/google/protobuf/any.proto.sk.md rename to test/mocks/docs/google/protobuf/any.proto.sk.md index 58d95c111..03c64f4fb 100644 --- a/test/mocks/api/doc/google/protobuf/any.proto.sk.md +++ b/test/mocks/docs/google/protobuf/any.proto.sk.md @@ -1,12 +1,5 @@ - ---- -title: "any.proto" -weight: 5 ---- - - ### Package: `google.protobuf` Protocol Buffers - Google's data interchange format Copyright 2008 Google Inc. All rights reserved. @@ -43,7 +36,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #### Types: -- [Any](#any) +- [Any](#Any) @@ -55,7 +48,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --- -### Any +### Any `Any` contains an arbitrary serialized protocol buffer message along with a diff --git a/test/mocks/docs/testing.solo.io.project.sk.md b/test/mocks/docs/testing.solo.io.project.sk.md new file mode 100644 index 000000000..30b98c42c --- /dev/null +++ b/test/mocks/docs/testing.solo.io.project.sk.md @@ -0,0 +1,21 @@ + + + +### API Reference for Solo-Kit Testing + +API Version: `testing.solo.io.v1` + +mock solo-kit project + +### API Resources: +- [MockResource](./github.com/solo-io/solo-kit/test/mocks/api/v1/mock_resources.proto.sk.md#MockResource) +- [FakeResource](./github.com/solo-io/solo-kit/test/mocks/api/v1/mock_resources.proto.sk.md#FakeResource) +- [AnotherMockResource](./github.com/solo-io/solo-kit/test/mocks/api/v1/more_mock_resources.proto.sk.md#AnotherMockResource) +- [ClusterResource](./github.com/solo-io/solo-kit/test/mocks/api/v1/more_mock_resources.proto.sk.md#ClusterResource) +- [MockResource](./github.com/solo-io/solo-kit/test/mocks/api/v1alpha1/mock_resources.proto.sk.md#MockResource) +- [FakeResource](./github.com/solo-io/solo-kit/test/mocks/api/v1alpha1/mock_resources.proto.sk.md#FakeResource) +- [MockResource](./github.com/solo-io/solo-kit/test/mocks/api/v2alpha1/mock_resources.proto.sk.md#MockResource) + + + + diff --git a/test/mocks/group/group_suite_test.go b/test/mocks/group/group_suite_test.go new file mode 100644 index 000000000..8d2ddf537 --- /dev/null +++ b/test/mocks/group/group_suite_test.go @@ -0,0 +1,15 @@ +// Code generated by solo-kit. DO NOT EDIT. + +package group + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +func TestGroup(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Group Suite") +} diff --git a/test/mocks/v1/testing_event_loop.sk.go b/test/mocks/group/testing_event_loop.sk.go similarity index 93% rename from test/mocks/v1/testing_event_loop.sk.go rename to test/mocks/group/testing_event_loop.sk.go index d13a38077..68de46e85 100644 --- a/test/mocks/v1/testing_event_loop.sk.go +++ b/test/mocks/group/testing_event_loop.sk.go @@ -1,6 +1,6 @@ // Code generated by solo-kit. DO NOT EDIT. -package v1 +package group import ( "context" @@ -46,7 +46,7 @@ func NewTestingEventLoop(emitter TestingEmitter, syncer TestingSyncer) eventloop func (el *testingEventLoop) Run(namespaces []string, opts clients.WatchOpts) (<-chan error, error) { opts = opts.WithDefaults() - opts.Ctx = contextutils.WithLogger(opts.Ctx, "v1.event_loop") + opts.Ctx = contextutils.WithLogger(opts.Ctx, "group.event_loop") logger := contextutils.LoggerFrom(opts.Ctx) logger.Infof("event loop started") @@ -56,7 +56,7 @@ func (el *testingEventLoop) Run(namespaces []string, opts clients.WatchOpts) (<- if err != nil { return nil, errors.Wrapf(err, "starting snapshot watch") } - go errutils.AggregateErrs(opts.Ctx, errs, emitterErrs, "v1.emitter errors") + go errutils.AggregateErrs(opts.Ctx, errs, emitterErrs, "group.emitter errors") go func() { // create a new context for each loop, cancel it before each loop var cancel context.CancelFunc = func() {} diff --git a/test/mocks/v1/testing_event_loop_test.go b/test/mocks/group/testing_event_loop_test.go similarity index 66% rename from test/mocks/v1/testing_event_loop_test.go rename to test/mocks/group/testing_event_loop_test.go index 64e9372c6..a6e98ce3c 100644 --- a/test/mocks/v1/testing_event_loop_test.go +++ b/test/mocks/group/testing_event_loop_test.go @@ -2,7 +2,7 @@ // +build solokit -package v1 +package group import ( "context" @@ -10,6 +10,8 @@ import ( "time" github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes "github.com/solo-io/solo-kit/pkg/api/v1/resources/common/kubernetes" + github_com_solo_io_solo_kit_test_mocks_v1 "github.com/solo-io/solo-kit/test/mocks/v1" + testing_solo_io_kubernetes "github.com/solo-io/solo-kit/test/mocks/v1" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -30,31 +32,31 @@ var _ = Describe("TestingEventLoop", func() { mockResourceClientFactory := &factory.MemoryResourceClientFactory{ Cache: memory.NewInMemoryResourceCache(), } - mockResourceClient, err := NewMockResourceClient(mockResourceClientFactory) + mockResourceClient, err := testing_solo_io_kubernetes.NewMockResourceClient(mockResourceClientFactory) Expect(err).NotTo(HaveOccurred()) fakeResourceClientFactory := &factory.MemoryResourceClientFactory{ Cache: memory.NewInMemoryResourceCache(), } - fakeResourceClient, err := NewFakeResourceClient(fakeResourceClientFactory) + fakeResourceClient, err := testing_solo_io_kubernetes.NewFakeResourceClient(fakeResourceClientFactory) Expect(err).NotTo(HaveOccurred()) anotherMockResourceClientFactory := &factory.MemoryResourceClientFactory{ Cache: memory.NewInMemoryResourceCache(), } - anotherMockResourceClient, err := NewAnotherMockResourceClient(anotherMockResourceClientFactory) + anotherMockResourceClient, err := testing_solo_io_kubernetes.NewAnotherMockResourceClient(anotherMockResourceClientFactory) Expect(err).NotTo(HaveOccurred()) clusterResourceClientFactory := &factory.MemoryResourceClientFactory{ Cache: memory.NewInMemoryResourceCache(), } - clusterResourceClient, err := NewClusterResourceClient(clusterResourceClientFactory) + clusterResourceClient, err := testing_solo_io_kubernetes.NewClusterResourceClient(clusterResourceClientFactory) Expect(err).NotTo(HaveOccurred()) mockCustomTypeClientFactory := &factory.MemoryResourceClientFactory{ Cache: memory.NewInMemoryResourceCache(), } - mockCustomTypeClient, err := NewMockCustomTypeClient(mockCustomTypeClientFactory) + mockCustomTypeClient, err := github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomTypeClient(mockCustomTypeClientFactory) Expect(err).NotTo(HaveOccurred()) podClientFactory := &factory.MemoryResourceClientFactory{ @@ -66,15 +68,15 @@ var _ = Describe("TestingEventLoop", func() { emitter = NewTestingEmitter(mockResourceClient, fakeResourceClient, anotherMockResourceClient, clusterResourceClient, mockCustomTypeClient, podClient) }) It("runs sync function on a new snapshot", func() { - _, err = emitter.MockResource().Write(NewMockResource(namespace, "jerry"), clients.WriteOpts{}) + _, err = emitter.MockResource().Write(testing_solo_io_kubernetes.NewMockResource(namespace, "jerry"), clients.WriteOpts{}) Expect(err).NotTo(HaveOccurred()) - _, err = emitter.FakeResource().Write(NewFakeResource(namespace, "jerry"), clients.WriteOpts{}) + _, err = emitter.FakeResource().Write(testing_solo_io_kubernetes.NewFakeResource(namespace, "jerry"), clients.WriteOpts{}) Expect(err).NotTo(HaveOccurred()) - _, err = emitter.AnotherMockResource().Write(NewAnotherMockResource(namespace, "jerry"), clients.WriteOpts{}) + _, err = emitter.AnotherMockResource().Write(testing_solo_io_kubernetes.NewAnotherMockResource(namespace, "jerry"), clients.WriteOpts{}) Expect(err).NotTo(HaveOccurred()) - _, err = emitter.ClusterResource().Write(NewClusterResource(namespace, "jerry"), clients.WriteOpts{}) + _, err = emitter.ClusterResource().Write(testing_solo_io_kubernetes.NewClusterResource(namespace, "jerry"), clients.WriteOpts{}) Expect(err).NotTo(HaveOccurred()) - _, err = emitter.MockCustomType().Write(NewMockCustomType(namespace, "jerry"), clients.WriteOpts{}) + _, err = emitter.MockCustomType().Write(github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomType(namespace, "jerry"), clients.WriteOpts{}) Expect(err).NotTo(HaveOccurred()) _, err = emitter.Pod().Write(github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.NewPod(namespace, "jerry"), clients.WriteOpts{}) Expect(err).NotTo(HaveOccurred()) diff --git a/test/mocks/v1/testing_simple_event_loop.sk.go b/test/mocks/group/testing_simple_event_loop.sk.go similarity index 95% rename from test/mocks/v1/testing_simple_event_loop.sk.go rename to test/mocks/group/testing_simple_event_loop.sk.go index dde6efa3a..1109a3f6a 100644 --- a/test/mocks/v1/testing_simple_event_loop.sk.go +++ b/test/mocks/group/testing_simple_event_loop.sk.go @@ -1,6 +1,6 @@ // Code generated by solo-kit. DO NOT EDIT. -package v1 +package group import ( "context" @@ -43,7 +43,7 @@ func NewTestingSimpleEventLoop(emitter TestingSimpleEmitter, syncers ...TestingS } func (el *testingSimpleEventLoop) Run(ctx context.Context) (<-chan error, error) { - ctx = contextutils.WithLogger(ctx, "v1.event_loop") + ctx = contextutils.WithLogger(ctx, "group.event_loop") logger := contextutils.LoggerFrom(ctx) logger.Infof("event loop started") @@ -54,7 +54,7 @@ func (el *testingSimpleEventLoop) Run(ctx context.Context) (<-chan error, error) return nil, errors.Wrapf(err, "starting snapshot watch") } - go errutils.AggregateErrs(ctx, errs, emitterErrs, "v1.emitter errors") + go errutils.AggregateErrs(ctx, errs, emitterErrs, "group.emitter errors") go func() { // create a new context for each syncer for each loop, cancel each before each loop syncerCancels := make(map[TestingSyncer]context.CancelFunc) diff --git a/test/mocks/v1/testing_snapshot.sk.go b/test/mocks/group/testing_snapshot.sk.go similarity index 87% rename from test/mocks/v1/testing_snapshot.sk.go rename to test/mocks/group/testing_snapshot.sk.go index 198d23acd..cb18c62ae 100644 --- a/test/mocks/v1/testing_snapshot.sk.go +++ b/test/mocks/group/testing_snapshot.sk.go @@ -1,22 +1,24 @@ // Code generated by solo-kit. DO NOT EDIT. -package v1 +package group import ( "fmt" github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes "github.com/solo-io/solo-kit/pkg/api/v1/resources/common/kubernetes" + github_com_solo_io_solo_kit_test_mocks_v1 "github.com/solo-io/solo-kit/test/mocks/v1" + testing_solo_io_kubernetes "github.com/solo-io/solo-kit/test/mocks/v1" "github.com/solo-io/go-utils/hashutils" "go.uber.org/zap" ) type TestingSnapshot struct { - Mocks MockResourceList - Fakes FakeResourceList - Anothermockresources AnotherMockResourceList - Clusterresources ClusterResourceList - Mcts MockCustomTypeList + Mocks testing_solo_io_kubernetes.MockResourceList + Fakes testing_solo_io_kubernetes.FakeResourceList + Anothermockresources testing_solo_io_kubernetes.AnotherMockResourceList + Clusterresources testing_solo_io_kubernetes.ClusterResourceList + Mcts github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList Pods github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList } diff --git a/test/mocks/v1/testing_snapshot_emitter.sk.go b/test/mocks/group/testing_snapshot_emitter.sk.go similarity index 79% rename from test/mocks/v1/testing_snapshot_emitter.sk.go rename to test/mocks/group/testing_snapshot_emitter.sk.go index 1466eb7a8..8279593d9 100644 --- a/test/mocks/v1/testing_snapshot_emitter.sk.go +++ b/test/mocks/group/testing_snapshot_emitter.sk.go @@ -1,12 +1,14 @@ // Code generated by solo-kit. DO NOT EDIT. -package v1 +package group import ( "sync" "time" github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes "github.com/solo-io/solo-kit/pkg/api/v1/resources/common/kubernetes" + github_com_solo_io_solo_kit_test_mocks_v1 "github.com/solo-io/solo-kit/test/mocks/v1" + testing_solo_io_kubernetes "github.com/solo-io/solo-kit/test/mocks/v1" "go.opencensus.io/stats" "go.opencensus.io/stats/view" @@ -51,20 +53,20 @@ func init() { type TestingEmitter interface { Register() error - MockResource() MockResourceClient - FakeResource() FakeResourceClient - AnotherMockResource() AnotherMockResourceClient - ClusterResource() ClusterResourceClient - MockCustomType() MockCustomTypeClient + MockResource() testing_solo_io_kubernetes.MockResourceClient + FakeResource() testing_solo_io_kubernetes.FakeResourceClient + AnotherMockResource() testing_solo_io_kubernetes.AnotherMockResourceClient + ClusterResource() testing_solo_io_kubernetes.ClusterResourceClient + MockCustomType() github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeClient Pod() github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodClient Snapshots(watchNamespaces []string, opts clients.WatchOpts) (<-chan *TestingSnapshot, <-chan error, error) } -func NewTestingEmitter(mockResourceClient MockResourceClient, fakeResourceClient FakeResourceClient, anotherMockResourceClient AnotherMockResourceClient, clusterResourceClient ClusterResourceClient, mockCustomTypeClient MockCustomTypeClient, podClient github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodClient) TestingEmitter { +func NewTestingEmitter(mockResourceClient testing_solo_io_kubernetes.MockResourceClient, fakeResourceClient testing_solo_io_kubernetes.FakeResourceClient, anotherMockResourceClient testing_solo_io_kubernetes.AnotherMockResourceClient, clusterResourceClient testing_solo_io_kubernetes.ClusterResourceClient, mockCustomTypeClient github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeClient, podClient github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodClient) TestingEmitter { return NewTestingEmitterWithEmit(mockResourceClient, fakeResourceClient, anotherMockResourceClient, clusterResourceClient, mockCustomTypeClient, podClient, make(chan struct{})) } -func NewTestingEmitterWithEmit(mockResourceClient MockResourceClient, fakeResourceClient FakeResourceClient, anotherMockResourceClient AnotherMockResourceClient, clusterResourceClient ClusterResourceClient, mockCustomTypeClient MockCustomTypeClient, podClient github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodClient, emit <-chan struct{}) TestingEmitter { +func NewTestingEmitterWithEmit(mockResourceClient testing_solo_io_kubernetes.MockResourceClient, fakeResourceClient testing_solo_io_kubernetes.FakeResourceClient, anotherMockResourceClient testing_solo_io_kubernetes.AnotherMockResourceClient, clusterResourceClient testing_solo_io_kubernetes.ClusterResourceClient, mockCustomTypeClient github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeClient, podClient github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodClient, emit <-chan struct{}) TestingEmitter { return &testingEmitter{ mockResource: mockResourceClient, fakeResource: fakeResourceClient, @@ -78,11 +80,11 @@ func NewTestingEmitterWithEmit(mockResourceClient MockResourceClient, fakeResour type testingEmitter struct { forceEmit <-chan struct{} - mockResource MockResourceClient - fakeResource FakeResourceClient - anotherMockResource AnotherMockResourceClient - clusterResource ClusterResourceClient - mockCustomType MockCustomTypeClient + mockResource testing_solo_io_kubernetes.MockResourceClient + fakeResource testing_solo_io_kubernetes.FakeResourceClient + anotherMockResource testing_solo_io_kubernetes.AnotherMockResourceClient + clusterResource testing_solo_io_kubernetes.ClusterResourceClient + mockCustomType github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeClient pod github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodClient } @@ -108,23 +110,23 @@ func (c *testingEmitter) Register() error { return nil } -func (c *testingEmitter) MockResource() MockResourceClient { +func (c *testingEmitter) MockResource() testing_solo_io_kubernetes.MockResourceClient { return c.mockResource } -func (c *testingEmitter) FakeResource() FakeResourceClient { +func (c *testingEmitter) FakeResource() testing_solo_io_kubernetes.FakeResourceClient { return c.fakeResource } -func (c *testingEmitter) AnotherMockResource() AnotherMockResourceClient { +func (c *testingEmitter) AnotherMockResource() testing_solo_io_kubernetes.AnotherMockResourceClient { return c.anotherMockResource } -func (c *testingEmitter) ClusterResource() ClusterResourceClient { +func (c *testingEmitter) ClusterResource() testing_solo_io_kubernetes.ClusterResourceClient { return c.clusterResource } -func (c *testingEmitter) MockCustomType() MockCustomTypeClient { +func (c *testingEmitter) MockCustomType() github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeClient { return c.mockCustomType } @@ -150,37 +152,37 @@ func (c *testingEmitter) Snapshots(watchNamespaces []string, opts clients.WatchO ctx := opts.Ctx /* Create channel for MockResource */ type mockResourceListWithNamespace struct { - list MockResourceList + list testing_solo_io_kubernetes.MockResourceList namespace string } mockResourceChan := make(chan mockResourceListWithNamespace) - var initialMockResourceList MockResourceList + var initialMockResourceList testing_solo_io_kubernetes.MockResourceList /* Create channel for FakeResource */ type fakeResourceListWithNamespace struct { - list FakeResourceList + list testing_solo_io_kubernetes.FakeResourceList namespace string } fakeResourceChan := make(chan fakeResourceListWithNamespace) - var initialFakeResourceList FakeResourceList + var initialFakeResourceList testing_solo_io_kubernetes.FakeResourceList /* Create channel for AnotherMockResource */ type anotherMockResourceListWithNamespace struct { - list AnotherMockResourceList + list testing_solo_io_kubernetes.AnotherMockResourceList namespace string } anotherMockResourceChan := make(chan anotherMockResourceListWithNamespace) - var initialAnotherMockResourceList AnotherMockResourceList + var initialAnotherMockResourceList testing_solo_io_kubernetes.AnotherMockResourceList /* Create channel for ClusterResource */ /* Create channel for MockCustomType */ type mockCustomTypeListWithNamespace struct { - list MockCustomTypeList + list github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList namespace string } mockCustomTypeChan := make(chan mockCustomTypeListWithNamespace) - var initialMockCustomTypeList MockCustomTypeList + var initialMockCustomTypeList github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList /* Create channel for Pod */ type podListWithNamespace struct { list github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList @@ -373,10 +375,10 @@ func (c *testingEmitter) Snapshots(watchNamespaces []string, opts clients.WatchO stats.Record(ctx, mTestingSnapshotMissed.M(1)) } } - mocksByNamespace := make(map[string]MockResourceList) - fakesByNamespace := make(map[string]FakeResourceList) - anothermockresourcesByNamespace := make(map[string]AnotherMockResourceList) - mctsByNamespace := make(map[string]MockCustomTypeList) + mocksByNamespace := make(map[string]testing_solo_io_kubernetes.MockResourceList) + fakesByNamespace := make(map[string]testing_solo_io_kubernetes.FakeResourceList) + anothermockresourcesByNamespace := make(map[string]testing_solo_io_kubernetes.AnotherMockResourceList) + mctsByNamespace := make(map[string]github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList) podsByNamespace := make(map[string]github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList) for { @@ -400,7 +402,7 @@ func (c *testingEmitter) Snapshots(watchNamespaces []string, opts clients.WatchO // merge lists by namespace mocksByNamespace[namespace] = mockResourceNamespacedList.list - var mockResourceList MockResourceList + var mockResourceList testing_solo_io_kubernetes.MockResourceList for _, mocks := range mocksByNamespace { mockResourceList = append(mockResourceList, mocks...) } @@ -412,7 +414,7 @@ func (c *testingEmitter) Snapshots(watchNamespaces []string, opts clients.WatchO // merge lists by namespace fakesByNamespace[namespace] = fakeResourceNamespacedList.list - var fakeResourceList FakeResourceList + var fakeResourceList testing_solo_io_kubernetes.FakeResourceList for _, fakes := range fakesByNamespace { fakeResourceList = append(fakeResourceList, fakes...) } @@ -424,7 +426,7 @@ func (c *testingEmitter) Snapshots(watchNamespaces []string, opts clients.WatchO // merge lists by namespace anothermockresourcesByNamespace[namespace] = anotherMockResourceNamespacedList.list - var anotherMockResourceList AnotherMockResourceList + var anotherMockResourceList testing_solo_io_kubernetes.AnotherMockResourceList for _, anothermockresources := range anothermockresourcesByNamespace { anotherMockResourceList = append(anotherMockResourceList, anothermockresources...) } @@ -439,7 +441,7 @@ func (c *testingEmitter) Snapshots(watchNamespaces []string, opts clients.WatchO // merge lists by namespace mctsByNamespace[namespace] = mockCustomTypeNamespacedList.list - var mockCustomTypeList MockCustomTypeList + var mockCustomTypeList github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList for _, mcts := range mctsByNamespace { mockCustomTypeList = append(mockCustomTypeList, mcts...) } diff --git a/test/mocks/v1/testing_snapshot_emitter_test.go b/test/mocks/group/testing_snapshot_emitter_test.go similarity index 65% rename from test/mocks/v1/testing_snapshot_emitter_test.go rename to test/mocks/group/testing_snapshot_emitter_test.go index e4485c0a8..671be4850 100644 --- a/test/mocks/v1/testing_snapshot_emitter_test.go +++ b/test/mocks/group/testing_snapshot_emitter_test.go @@ -2,7 +2,7 @@ // +build solokit -package v1 +package group import ( "context" @@ -10,6 +10,8 @@ import ( "time" github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes "github.com/solo-io/solo-kit/pkg/api/v1/resources/common/kubernetes" + github_com_solo_io_solo_kit_test_mocks_v1 "github.com/solo-io/solo-kit/test/mocks/v1" + testing_solo_io_kubernetes "github.com/solo-io/solo-kit/test/mocks/v1" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" @@ -30,7 +32,7 @@ import ( _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" ) -var _ = Describe("V1Emitter", func() { +var _ = Describe("GroupEmitter", func() { if os.Getenv("RUN_KUBE_TESTS") != "1" { log.Printf("This test creates kubernetes resources and is disabled by default. To enable, set RUN_KUBE_TESTS=1 in your env.") return @@ -42,11 +44,11 @@ var _ = Describe("V1Emitter", func() { cfg *rest.Config kube kubernetes.Interface emitter TestingEmitter - mockResourceClient MockResourceClient - fakeResourceClient FakeResourceClient - anotherMockResourceClient AnotherMockResourceClient - clusterResourceClient ClusterResourceClient - mockCustomTypeClient MockCustomTypeClient + mockResourceClient testing_solo_io_kubernetes.MockResourceClient + fakeResourceClient testing_solo_io_kubernetes.FakeResourceClient + anotherMockResourceClient testing_solo_io_kubernetes.AnotherMockResourceClient + clusterResourceClient testing_solo_io_kubernetes.ClusterResourceClient + mockCustomTypeClient github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeClient podClient github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodClient ) @@ -60,44 +62,46 @@ var _ = Describe("V1Emitter", func() { Expect(err).NotTo(HaveOccurred()) // MockResource Constructor mockResourceClientFactory := &factory.KubeResourceClientFactory{ - Crd: MockResourceCrd, + Crd: testing_solo_io_kubernetes.MockResourceCrd, Cfg: cfg, SharedCache: kuberc.NewKubeCache(context.TODO()), } - mockResourceClient, err = NewMockResourceClient(mockResourceClientFactory) + mockResourceClient, err = testing_solo_io_kubernetes.NewMockResourceClient(mockResourceClientFactory) Expect(err).NotTo(HaveOccurred()) // FakeResource Constructor - fakeResourceClientFactory := &factory.MemoryResourceClientFactory{ - Cache: memory.NewInMemoryResourceCache(), + fakeResourceClientFactory := &factory.KubeResourceClientFactory{ + Crd: testing_solo_io_kubernetes.FakeResourceCrd, + Cfg: cfg, + SharedCache: kuberc.NewKubeCache(context.TODO()), } - fakeResourceClient, err = NewFakeResourceClient(fakeResourceClientFactory) + fakeResourceClient, err = testing_solo_io_kubernetes.NewFakeResourceClient(fakeResourceClientFactory) Expect(err).NotTo(HaveOccurred()) // AnotherMockResource Constructor anotherMockResourceClientFactory := &factory.KubeResourceClientFactory{ - Crd: AnotherMockResourceCrd, + Crd: testing_solo_io_kubernetes.AnotherMockResourceCrd, Cfg: cfg, SharedCache: kuberc.NewKubeCache(context.TODO()), } - anotherMockResourceClient, err = NewAnotherMockResourceClient(anotherMockResourceClientFactory) + anotherMockResourceClient, err = testing_solo_io_kubernetes.NewAnotherMockResourceClient(anotherMockResourceClientFactory) Expect(err).NotTo(HaveOccurred()) // ClusterResource Constructor clusterResourceClientFactory := &factory.KubeResourceClientFactory{ - Crd: ClusterResourceCrd, + Crd: testing_solo_io_kubernetes.ClusterResourceCrd, Cfg: cfg, SharedCache: kuberc.NewKubeCache(context.TODO()), } - clusterResourceClient, err = NewClusterResourceClient(clusterResourceClientFactory) + clusterResourceClient, err = testing_solo_io_kubernetes.NewClusterResourceClient(clusterResourceClientFactory) Expect(err).NotTo(HaveOccurred()) // MockCustomType Constructor mockCustomTypeClientFactory := &factory.MemoryResourceClientFactory{ Cache: memory.NewInMemoryResourceCache(), } - mockCustomTypeClient, err = NewMockCustomTypeClient(mockCustomTypeClientFactory) + mockCustomTypeClient, err = github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomTypeClient(mockCustomTypeClientFactory) Expect(err).NotTo(HaveOccurred()) // Pod Constructor podClientFactory := &factory.MemoryResourceClientFactory{ @@ -131,7 +135,7 @@ var _ = Describe("V1Emitter", func() { MockResource */ - assertSnapshotMocks := func(expectMocks MockResourceList, unexpectMocks MockResourceList) { + assertSnapshotMocks := func(expectMocks testing_solo_io_kubernetes.MockResourceList, unexpectMocks testing_solo_io_kubernetes.MockResourceList) { drain: for { select { @@ -157,38 +161,38 @@ var _ = Describe("V1Emitter", func() { } } } - mockResource1a, err := mockResourceClient.Write(NewMockResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + mockResource1a, err := mockResourceClient.Write(testing_solo_io_kubernetes.NewMockResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - mockResource1b, err := mockResourceClient.Write(NewMockResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) + mockResource1b, err := mockResourceClient.Write(testing_solo_io_kubernetes.NewMockResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotMocks(MockResourceList{mockResource1a, mockResource1b}, nil) - mockResource2a, err := mockResourceClient.Write(NewMockResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + assertSnapshotMocks(testing_solo_io_kubernetes.MockResourceList{mockResource1a, mockResource1b}, nil) + mockResource2a, err := mockResourceClient.Write(testing_solo_io_kubernetes.NewMockResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - mockResource2b, err := mockResourceClient.Write(NewMockResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) + mockResource2b, err := mockResourceClient.Write(testing_solo_io_kubernetes.NewMockResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotMocks(MockResourceList{mockResource1a, mockResource1b, mockResource2a, mockResource2b}, nil) + assertSnapshotMocks(testing_solo_io_kubernetes.MockResourceList{mockResource1a, mockResource1b, mockResource2a, mockResource2b}, nil) err = mockResourceClient.Delete(mockResource2a.GetMetadata().Namespace, mockResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) err = mockResourceClient.Delete(mockResource2b.GetMetadata().Namespace, mockResource2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotMocks(MockResourceList{mockResource1a, mockResource1b}, MockResourceList{mockResource2a, mockResource2b}) + assertSnapshotMocks(testing_solo_io_kubernetes.MockResourceList{mockResource1a, mockResource1b}, testing_solo_io_kubernetes.MockResourceList{mockResource2a, mockResource2b}) err = mockResourceClient.Delete(mockResource1a.GetMetadata().Namespace, mockResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) err = mockResourceClient.Delete(mockResource1b.GetMetadata().Namespace, mockResource1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotMocks(nil, MockResourceList{mockResource1a, mockResource1b, mockResource2a, mockResource2b}) + assertSnapshotMocks(nil, testing_solo_io_kubernetes.MockResourceList{mockResource1a, mockResource1b, mockResource2a, mockResource2b}) /* FakeResource */ - assertSnapshotFakes := func(expectFakes FakeResourceList, unexpectFakes FakeResourceList) { + assertSnapshotFakes := func(expectFakes testing_solo_io_kubernetes.FakeResourceList, unexpectFakes testing_solo_io_kubernetes.FakeResourceList) { drain: for { select { @@ -214,38 +218,38 @@ var _ = Describe("V1Emitter", func() { } } } - fakeResource1a, err := fakeResourceClient.Write(NewFakeResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + fakeResource1a, err := fakeResourceClient.Write(testing_solo_io_kubernetes.NewFakeResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - fakeResource1b, err := fakeResourceClient.Write(NewFakeResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) + fakeResource1b, err := fakeResourceClient.Write(testing_solo_io_kubernetes.NewFakeResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotFakes(FakeResourceList{fakeResource1a, fakeResource1b}, nil) - fakeResource2a, err := fakeResourceClient.Write(NewFakeResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + assertSnapshotFakes(testing_solo_io_kubernetes.FakeResourceList{fakeResource1a, fakeResource1b}, nil) + fakeResource2a, err := fakeResourceClient.Write(testing_solo_io_kubernetes.NewFakeResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - fakeResource2b, err := fakeResourceClient.Write(NewFakeResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) + fakeResource2b, err := fakeResourceClient.Write(testing_solo_io_kubernetes.NewFakeResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotFakes(FakeResourceList{fakeResource1a, fakeResource1b, fakeResource2a, fakeResource2b}, nil) + assertSnapshotFakes(testing_solo_io_kubernetes.FakeResourceList{fakeResource1a, fakeResource1b, fakeResource2a, fakeResource2b}, nil) err = fakeResourceClient.Delete(fakeResource2a.GetMetadata().Namespace, fakeResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) err = fakeResourceClient.Delete(fakeResource2b.GetMetadata().Namespace, fakeResource2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotFakes(FakeResourceList{fakeResource1a, fakeResource1b}, FakeResourceList{fakeResource2a, fakeResource2b}) + assertSnapshotFakes(testing_solo_io_kubernetes.FakeResourceList{fakeResource1a, fakeResource1b}, testing_solo_io_kubernetes.FakeResourceList{fakeResource2a, fakeResource2b}) err = fakeResourceClient.Delete(fakeResource1a.GetMetadata().Namespace, fakeResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) err = fakeResourceClient.Delete(fakeResource1b.GetMetadata().Namespace, fakeResource1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotFakes(nil, FakeResourceList{fakeResource1a, fakeResource1b, fakeResource2a, fakeResource2b}) + assertSnapshotFakes(nil, testing_solo_io_kubernetes.FakeResourceList{fakeResource1a, fakeResource1b, fakeResource2a, fakeResource2b}) /* AnotherMockResource */ - assertSnapshotAnothermockresources := func(expectAnothermockresources AnotherMockResourceList, unexpectAnothermockresources AnotherMockResourceList) { + assertSnapshotAnothermockresources := func(expectAnothermockresources testing_solo_io_kubernetes.AnotherMockResourceList, unexpectAnothermockresources testing_solo_io_kubernetes.AnotherMockResourceList) { drain: for { select { @@ -271,38 +275,38 @@ var _ = Describe("V1Emitter", func() { } } } - anotherMockResource1a, err := anotherMockResourceClient.Write(NewAnotherMockResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + anotherMockResource1a, err := anotherMockResourceClient.Write(testing_solo_io_kubernetes.NewAnotherMockResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - anotherMockResource1b, err := anotherMockResourceClient.Write(NewAnotherMockResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) + anotherMockResource1b, err := anotherMockResourceClient.Write(testing_solo_io_kubernetes.NewAnotherMockResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotAnothermockresources(AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b}, nil) - anotherMockResource2a, err := anotherMockResourceClient.Write(NewAnotherMockResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + assertSnapshotAnothermockresources(testing_solo_io_kubernetes.AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b}, nil) + anotherMockResource2a, err := anotherMockResourceClient.Write(testing_solo_io_kubernetes.NewAnotherMockResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - anotherMockResource2b, err := anotherMockResourceClient.Write(NewAnotherMockResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) + anotherMockResource2b, err := anotherMockResourceClient.Write(testing_solo_io_kubernetes.NewAnotherMockResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotAnothermockresources(AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b, anotherMockResource2a, anotherMockResource2b}, nil) + assertSnapshotAnothermockresources(testing_solo_io_kubernetes.AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b, anotherMockResource2a, anotherMockResource2b}, nil) err = anotherMockResourceClient.Delete(anotherMockResource2a.GetMetadata().Namespace, anotherMockResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) err = anotherMockResourceClient.Delete(anotherMockResource2b.GetMetadata().Namespace, anotherMockResource2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotAnothermockresources(AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b}, AnotherMockResourceList{anotherMockResource2a, anotherMockResource2b}) + assertSnapshotAnothermockresources(testing_solo_io_kubernetes.AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b}, testing_solo_io_kubernetes.AnotherMockResourceList{anotherMockResource2a, anotherMockResource2b}) err = anotherMockResourceClient.Delete(anotherMockResource1a.GetMetadata().Namespace, anotherMockResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) err = anotherMockResourceClient.Delete(anotherMockResource1b.GetMetadata().Namespace, anotherMockResource1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotAnothermockresources(nil, AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b, anotherMockResource2a, anotherMockResource2b}) + assertSnapshotAnothermockresources(nil, testing_solo_io_kubernetes.AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b, anotherMockResource2a, anotherMockResource2b}) /* ClusterResource */ - assertSnapshotClusterresources := func(expectClusterresources ClusterResourceList, unexpectClusterresources ClusterResourceList) { + assertSnapshotClusterresources := func(expectClusterresources testing_solo_io_kubernetes.ClusterResourceList, unexpectClusterresources testing_solo_io_kubernetes.ClusterResourceList) { drain: for { select { @@ -326,30 +330,30 @@ var _ = Describe("V1Emitter", func() { } } } - clusterResource1a, err := clusterResourceClient.Write(NewClusterResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + clusterResource1a, err := clusterResourceClient.Write(testing_solo_io_kubernetes.NewClusterResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotClusterresources(ClusterResourceList{clusterResource1a}, nil) - clusterResource2a, err := clusterResourceClient.Write(NewClusterResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + assertSnapshotClusterresources(testing_solo_io_kubernetes.ClusterResourceList{clusterResource1a}, nil) + clusterResource2a, err := clusterResourceClient.Write(testing_solo_io_kubernetes.NewClusterResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotClusterresources(ClusterResourceList{clusterResource1a, clusterResource2a}, nil) + assertSnapshotClusterresources(testing_solo_io_kubernetes.ClusterResourceList{clusterResource1a, clusterResource2a}, nil) err = clusterResourceClient.Delete(clusterResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotClusterresources(ClusterResourceList{clusterResource1a}, ClusterResourceList{clusterResource2a}) + assertSnapshotClusterresources(testing_solo_io_kubernetes.ClusterResourceList{clusterResource1a}, testing_solo_io_kubernetes.ClusterResourceList{clusterResource2a}) err = clusterResourceClient.Delete(clusterResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotClusterresources(nil, ClusterResourceList{clusterResource1a, clusterResource2a}) + assertSnapshotClusterresources(nil, testing_solo_io_kubernetes.ClusterResourceList{clusterResource1a, clusterResource2a}) /* MockCustomType */ - assertSnapshotmcts := func(expectmcts MockCustomTypeList, unexpectmcts MockCustomTypeList) { + assertSnapshotmcts := func(expectmcts github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList, unexpectmcts github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList) { drain: for { select { @@ -375,32 +379,32 @@ var _ = Describe("V1Emitter", func() { } } } - mockCustomType1a, err := mockCustomTypeClient.Write(NewMockCustomType(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + mockCustomType1a, err := mockCustomTypeClient.Write(github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomType(namespace1, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - mockCustomType1b, err := mockCustomTypeClient.Write(NewMockCustomType(namespace2, name1), clients.WriteOpts{Ctx: ctx}) + mockCustomType1b, err := mockCustomTypeClient.Write(github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomType(namespace2, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotmcts(MockCustomTypeList{mockCustomType1a, mockCustomType1b}, nil) - mockCustomType2a, err := mockCustomTypeClient.Write(NewMockCustomType(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + assertSnapshotmcts(github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList{mockCustomType1a, mockCustomType1b}, nil) + mockCustomType2a, err := mockCustomTypeClient.Write(github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomType(namespace1, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - mockCustomType2b, err := mockCustomTypeClient.Write(NewMockCustomType(namespace2, name2), clients.WriteOpts{Ctx: ctx}) + mockCustomType2b, err := mockCustomTypeClient.Write(github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomType(namespace2, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotmcts(MockCustomTypeList{mockCustomType1a, mockCustomType1b, mockCustomType2a, mockCustomType2b}, nil) + assertSnapshotmcts(github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList{mockCustomType1a, mockCustomType1b, mockCustomType2a, mockCustomType2b}, nil) err = mockCustomTypeClient.Delete(mockCustomType2a.GetMetadata().Namespace, mockCustomType2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) err = mockCustomTypeClient.Delete(mockCustomType2b.GetMetadata().Namespace, mockCustomType2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotmcts(MockCustomTypeList{mockCustomType1a, mockCustomType1b}, MockCustomTypeList{mockCustomType2a, mockCustomType2b}) + assertSnapshotmcts(github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList{mockCustomType1a, mockCustomType1b}, github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList{mockCustomType2a, mockCustomType2b}) err = mockCustomTypeClient.Delete(mockCustomType1a.GetMetadata().Namespace, mockCustomType1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) err = mockCustomTypeClient.Delete(mockCustomType1b.GetMetadata().Namespace, mockCustomType1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotmcts(nil, MockCustomTypeList{mockCustomType1a, mockCustomType1b, mockCustomType2a, mockCustomType2b}) + assertSnapshotmcts(nil, github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList{mockCustomType1a, mockCustomType1b, mockCustomType2a, mockCustomType2b}) /* Pod @@ -476,7 +480,7 @@ var _ = Describe("V1Emitter", func() { MockResource */ - assertSnapshotMocks := func(expectMocks MockResourceList, unexpectMocks MockResourceList) { + assertSnapshotMocks := func(expectMocks testing_solo_io_kubernetes.MockResourceList, unexpectMocks testing_solo_io_kubernetes.MockResourceList) { drain: for { select { @@ -502,38 +506,38 @@ var _ = Describe("V1Emitter", func() { } } } - mockResource1a, err := mockResourceClient.Write(NewMockResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + mockResource1a, err := mockResourceClient.Write(testing_solo_io_kubernetes.NewMockResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - mockResource1b, err := mockResourceClient.Write(NewMockResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) + mockResource1b, err := mockResourceClient.Write(testing_solo_io_kubernetes.NewMockResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotMocks(MockResourceList{mockResource1a, mockResource1b}, nil) - mockResource2a, err := mockResourceClient.Write(NewMockResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + assertSnapshotMocks(testing_solo_io_kubernetes.MockResourceList{mockResource1a, mockResource1b}, nil) + mockResource2a, err := mockResourceClient.Write(testing_solo_io_kubernetes.NewMockResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - mockResource2b, err := mockResourceClient.Write(NewMockResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) + mockResource2b, err := mockResourceClient.Write(testing_solo_io_kubernetes.NewMockResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotMocks(MockResourceList{mockResource1a, mockResource1b, mockResource2a, mockResource2b}, nil) + assertSnapshotMocks(testing_solo_io_kubernetes.MockResourceList{mockResource1a, mockResource1b, mockResource2a, mockResource2b}, nil) err = mockResourceClient.Delete(mockResource2a.GetMetadata().Namespace, mockResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) err = mockResourceClient.Delete(mockResource2b.GetMetadata().Namespace, mockResource2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotMocks(MockResourceList{mockResource1a, mockResource1b}, MockResourceList{mockResource2a, mockResource2b}) + assertSnapshotMocks(testing_solo_io_kubernetes.MockResourceList{mockResource1a, mockResource1b}, testing_solo_io_kubernetes.MockResourceList{mockResource2a, mockResource2b}) err = mockResourceClient.Delete(mockResource1a.GetMetadata().Namespace, mockResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) err = mockResourceClient.Delete(mockResource1b.GetMetadata().Namespace, mockResource1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotMocks(nil, MockResourceList{mockResource1a, mockResource1b, mockResource2a, mockResource2b}) + assertSnapshotMocks(nil, testing_solo_io_kubernetes.MockResourceList{mockResource1a, mockResource1b, mockResource2a, mockResource2b}) /* FakeResource */ - assertSnapshotFakes := func(expectFakes FakeResourceList, unexpectFakes FakeResourceList) { + assertSnapshotFakes := func(expectFakes testing_solo_io_kubernetes.FakeResourceList, unexpectFakes testing_solo_io_kubernetes.FakeResourceList) { drain: for { select { @@ -559,38 +563,38 @@ var _ = Describe("V1Emitter", func() { } } } - fakeResource1a, err := fakeResourceClient.Write(NewFakeResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + fakeResource1a, err := fakeResourceClient.Write(testing_solo_io_kubernetes.NewFakeResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - fakeResource1b, err := fakeResourceClient.Write(NewFakeResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) + fakeResource1b, err := fakeResourceClient.Write(testing_solo_io_kubernetes.NewFakeResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotFakes(FakeResourceList{fakeResource1a, fakeResource1b}, nil) - fakeResource2a, err := fakeResourceClient.Write(NewFakeResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + assertSnapshotFakes(testing_solo_io_kubernetes.FakeResourceList{fakeResource1a, fakeResource1b}, nil) + fakeResource2a, err := fakeResourceClient.Write(testing_solo_io_kubernetes.NewFakeResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - fakeResource2b, err := fakeResourceClient.Write(NewFakeResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) + fakeResource2b, err := fakeResourceClient.Write(testing_solo_io_kubernetes.NewFakeResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotFakes(FakeResourceList{fakeResource1a, fakeResource1b, fakeResource2a, fakeResource2b}, nil) + assertSnapshotFakes(testing_solo_io_kubernetes.FakeResourceList{fakeResource1a, fakeResource1b, fakeResource2a, fakeResource2b}, nil) err = fakeResourceClient.Delete(fakeResource2a.GetMetadata().Namespace, fakeResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) err = fakeResourceClient.Delete(fakeResource2b.GetMetadata().Namespace, fakeResource2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotFakes(FakeResourceList{fakeResource1a, fakeResource1b}, FakeResourceList{fakeResource2a, fakeResource2b}) + assertSnapshotFakes(testing_solo_io_kubernetes.FakeResourceList{fakeResource1a, fakeResource1b}, testing_solo_io_kubernetes.FakeResourceList{fakeResource2a, fakeResource2b}) err = fakeResourceClient.Delete(fakeResource1a.GetMetadata().Namespace, fakeResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) err = fakeResourceClient.Delete(fakeResource1b.GetMetadata().Namespace, fakeResource1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotFakes(nil, FakeResourceList{fakeResource1a, fakeResource1b, fakeResource2a, fakeResource2b}) + assertSnapshotFakes(nil, testing_solo_io_kubernetes.FakeResourceList{fakeResource1a, fakeResource1b, fakeResource2a, fakeResource2b}) /* AnotherMockResource */ - assertSnapshotAnothermockresources := func(expectAnothermockresources AnotherMockResourceList, unexpectAnothermockresources AnotherMockResourceList) { + assertSnapshotAnothermockresources := func(expectAnothermockresources testing_solo_io_kubernetes.AnotherMockResourceList, unexpectAnothermockresources testing_solo_io_kubernetes.AnotherMockResourceList) { drain: for { select { @@ -616,38 +620,38 @@ var _ = Describe("V1Emitter", func() { } } } - anotherMockResource1a, err := anotherMockResourceClient.Write(NewAnotherMockResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + anotherMockResource1a, err := anotherMockResourceClient.Write(testing_solo_io_kubernetes.NewAnotherMockResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - anotherMockResource1b, err := anotherMockResourceClient.Write(NewAnotherMockResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) + anotherMockResource1b, err := anotherMockResourceClient.Write(testing_solo_io_kubernetes.NewAnotherMockResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotAnothermockresources(AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b}, nil) - anotherMockResource2a, err := anotherMockResourceClient.Write(NewAnotherMockResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + assertSnapshotAnothermockresources(testing_solo_io_kubernetes.AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b}, nil) + anotherMockResource2a, err := anotherMockResourceClient.Write(testing_solo_io_kubernetes.NewAnotherMockResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - anotherMockResource2b, err := anotherMockResourceClient.Write(NewAnotherMockResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) + anotherMockResource2b, err := anotherMockResourceClient.Write(testing_solo_io_kubernetes.NewAnotherMockResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotAnothermockresources(AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b, anotherMockResource2a, anotherMockResource2b}, nil) + assertSnapshotAnothermockresources(testing_solo_io_kubernetes.AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b, anotherMockResource2a, anotherMockResource2b}, nil) err = anotherMockResourceClient.Delete(anotherMockResource2a.GetMetadata().Namespace, anotherMockResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) err = anotherMockResourceClient.Delete(anotherMockResource2b.GetMetadata().Namespace, anotherMockResource2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotAnothermockresources(AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b}, AnotherMockResourceList{anotherMockResource2a, anotherMockResource2b}) + assertSnapshotAnothermockresources(testing_solo_io_kubernetes.AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b}, testing_solo_io_kubernetes.AnotherMockResourceList{anotherMockResource2a, anotherMockResource2b}) err = anotherMockResourceClient.Delete(anotherMockResource1a.GetMetadata().Namespace, anotherMockResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) err = anotherMockResourceClient.Delete(anotherMockResource1b.GetMetadata().Namespace, anotherMockResource1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotAnothermockresources(nil, AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b, anotherMockResource2a, anotherMockResource2b}) + assertSnapshotAnothermockresources(nil, testing_solo_io_kubernetes.AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b, anotherMockResource2a, anotherMockResource2b}) /* ClusterResource */ - assertSnapshotClusterresources := func(expectClusterresources ClusterResourceList, unexpectClusterresources ClusterResourceList) { + assertSnapshotClusterresources := func(expectClusterresources testing_solo_io_kubernetes.ClusterResourceList, unexpectClusterresources testing_solo_io_kubernetes.ClusterResourceList) { drain: for { select { @@ -671,30 +675,30 @@ var _ = Describe("V1Emitter", func() { } } } - clusterResource1a, err := clusterResourceClient.Write(NewClusterResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + clusterResource1a, err := clusterResourceClient.Write(testing_solo_io_kubernetes.NewClusterResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotClusterresources(ClusterResourceList{clusterResource1a}, nil) - clusterResource2a, err := clusterResourceClient.Write(NewClusterResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + assertSnapshotClusterresources(testing_solo_io_kubernetes.ClusterResourceList{clusterResource1a}, nil) + clusterResource2a, err := clusterResourceClient.Write(testing_solo_io_kubernetes.NewClusterResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotClusterresources(ClusterResourceList{clusterResource1a, clusterResource2a}, nil) + assertSnapshotClusterresources(testing_solo_io_kubernetes.ClusterResourceList{clusterResource1a, clusterResource2a}, nil) err = clusterResourceClient.Delete(clusterResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotClusterresources(ClusterResourceList{clusterResource1a}, ClusterResourceList{clusterResource2a}) + assertSnapshotClusterresources(testing_solo_io_kubernetes.ClusterResourceList{clusterResource1a}, testing_solo_io_kubernetes.ClusterResourceList{clusterResource2a}) err = clusterResourceClient.Delete(clusterResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotClusterresources(nil, ClusterResourceList{clusterResource1a, clusterResource2a}) + assertSnapshotClusterresources(nil, testing_solo_io_kubernetes.ClusterResourceList{clusterResource1a, clusterResource2a}) /* MockCustomType */ - assertSnapshotmcts := func(expectmcts MockCustomTypeList, unexpectmcts MockCustomTypeList) { + assertSnapshotmcts := func(expectmcts github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList, unexpectmcts github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList) { drain: for { select { @@ -720,32 +724,32 @@ var _ = Describe("V1Emitter", func() { } } } - mockCustomType1a, err := mockCustomTypeClient.Write(NewMockCustomType(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + mockCustomType1a, err := mockCustomTypeClient.Write(github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomType(namespace1, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - mockCustomType1b, err := mockCustomTypeClient.Write(NewMockCustomType(namespace2, name1), clients.WriteOpts{Ctx: ctx}) + mockCustomType1b, err := mockCustomTypeClient.Write(github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomType(namespace2, name1), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotmcts(MockCustomTypeList{mockCustomType1a, mockCustomType1b}, nil) - mockCustomType2a, err := mockCustomTypeClient.Write(NewMockCustomType(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + assertSnapshotmcts(github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList{mockCustomType1a, mockCustomType1b}, nil) + mockCustomType2a, err := mockCustomTypeClient.Write(github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomType(namespace1, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - mockCustomType2b, err := mockCustomTypeClient.Write(NewMockCustomType(namespace2, name2), clients.WriteOpts{Ctx: ctx}) + mockCustomType2b, err := mockCustomTypeClient.Write(github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomType(namespace2, name2), clients.WriteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotmcts(MockCustomTypeList{mockCustomType1a, mockCustomType1b, mockCustomType2a, mockCustomType2b}, nil) + assertSnapshotmcts(github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList{mockCustomType1a, mockCustomType1b, mockCustomType2a, mockCustomType2b}, nil) err = mockCustomTypeClient.Delete(mockCustomType2a.GetMetadata().Namespace, mockCustomType2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) err = mockCustomTypeClient.Delete(mockCustomType2b.GetMetadata().Namespace, mockCustomType2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotmcts(MockCustomTypeList{mockCustomType1a, mockCustomType1b}, MockCustomTypeList{mockCustomType2a, mockCustomType2b}) + assertSnapshotmcts(github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList{mockCustomType1a, mockCustomType1b}, github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList{mockCustomType2a, mockCustomType2b}) err = mockCustomTypeClient.Delete(mockCustomType1a.GetMetadata().Namespace, mockCustomType1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) err = mockCustomTypeClient.Delete(mockCustomType1b.GetMetadata().Namespace, mockCustomType1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) Expect(err).NotTo(HaveOccurred()) - assertSnapshotmcts(nil, MockCustomTypeList{mockCustomType1a, mockCustomType1b, mockCustomType2a, mockCustomType2b}) + assertSnapshotmcts(nil, github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList{mockCustomType1a, mockCustomType1b, mockCustomType2a, mockCustomType2b}) /* Pod diff --git a/test/mocks/v1/testing_snapshot_simple_emitter.sk.go b/test/mocks/group/testing_snapshot_simple_emitter.sk.go similarity index 86% rename from test/mocks/v1/testing_snapshot_simple_emitter.sk.go rename to test/mocks/group/testing_snapshot_simple_emitter.sk.go index 859b91511..802d27bc2 100644 --- a/test/mocks/v1/testing_snapshot_simple_emitter.sk.go +++ b/test/mocks/group/testing_snapshot_simple_emitter.sk.go @@ -1,13 +1,15 @@ // Code generated by solo-kit. DO NOT EDIT. -package v1 +package group import ( "context" - fmt "fmt" + "fmt" "time" github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes "github.com/solo-io/solo-kit/pkg/api/v1/resources/common/kubernetes" + github_com_solo_io_solo_kit_test_mocks_v1 "github.com/solo-io/solo-kit/test/mocks/v1" + testing_solo_io_kubernetes "github.com/solo-io/solo-kit/test/mocks/v1" "go.opencensus.io/stats" @@ -83,15 +85,15 @@ func (c *testingSimpleEmitter) Snapshots(ctx context.Context) (<-chan *TestingSn currentSnapshot = TestingSnapshot{} for _, res := range untypedList { switch typed := res.(type) { - case *MockResource: + case *testing_solo_io_kubernetes.MockResource: currentSnapshot.Mocks = append(currentSnapshot.Mocks, typed) - case *FakeResource: + case *testing_solo_io_kubernetes.FakeResource: currentSnapshot.Fakes = append(currentSnapshot.Fakes, typed) - case *AnotherMockResource: + case *testing_solo_io_kubernetes.AnotherMockResource: currentSnapshot.Anothermockresources = append(currentSnapshot.Anothermockresources, typed) - case *ClusterResource: + case *testing_solo_io_kubernetes.ClusterResource: currentSnapshot.Clusterresources = append(currentSnapshot.Clusterresources, typed) - case *MockCustomType: + case *github_com_solo_io_solo_kit_test_mocks_v1.MockCustomType: currentSnapshot.Mcts = append(currentSnapshot.Mcts, typed) case *github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.Pod: currentSnapshot.Pods = append(currentSnapshot.Pods, typed) diff --git a/test/mocks/v1/fake_resource.sk.go b/test/mocks/v1/fake_resource.sk.go index 0c1c63a9b..c5a0d6c91 100644 --- a/test/mocks/v1/fake_resource.sk.go +++ b/test/mocks/v1/fake_resource.sk.go @@ -28,6 +28,10 @@ func (r *FakeResource) SetMetadata(meta core.Metadata) { r.Metadata = meta } +func (r *FakeResource) SetStatus(status core.Status) { + r.Status = status +} + func (r *FakeResource) Hash() uint64 { metaCopy := r.GetMetadata() metaCopy.ResourceVersion = "" @@ -63,6 +67,14 @@ func (list FakeResourceList) AsResources() resources.ResourceList { return ress } +func (list FakeResourceList) AsInputResources() resources.InputResourceList { + var ress resources.InputResourceList + for _, fakeResource := range list { + ress = append(ress, fakeResource) + } + return ress +} + func (list FakeResourceList) Names() []string { var names []string for _, fakeResource := range list { diff --git a/test/mocks/v1/fake_resource_client_test.go b/test/mocks/v1/fake_resource_client_test.go index 9bce0f00d..6d4af21ae 100644 --- a/test/mocks/v1/fake_resource_client_test.go +++ b/test/mocks/v1/fake_resource_client_test.go @@ -73,6 +73,7 @@ func FakeResourceClientTest(namespace string, client FakeResourceClient, name1, Expect(r1.GetMetadata().ResourceVersion).NotTo(Equal(input.GetMetadata().ResourceVersion)) Expect(r1.GetMetadata().Ref()).To(Equal(input.GetMetadata().Ref())) Expect(r1.Count).To(Equal(input.Count)) + Expect(r1.Status).To(Equal(input.Status)) _, err = client.Write(input, clients.WriteOpts{ OverwriteExisting: true, diff --git a/test/mocks/v1/mock_resources.pb.go b/test/mocks/v1/mock_resources.pb.go index 4c2f00c4a..b2ac8cf7e 100644 --- a/test/mocks/v1/mock_resources.pb.go +++ b/test/mocks/v1/mock_resources.pb.go @@ -210,6 +210,7 @@ func _MockResource_OneofSizer(msg proto.Message) (n int) { type FakeResource struct { Count uint32 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` Metadata core.Metadata `protobuf:"bytes,7,opt,name=metadata,proto3" json:"metadata"` + Status core.Status `protobuf:"bytes,6,opt,name=status,proto3" json:"status"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -253,6 +254,13 @@ func (m *FakeResource) GetMetadata() core.Metadata { return core.Metadata{} } +func (m *FakeResource) GetStatus() core.Status { + if m != nil { + return m.Status + } + return core.Status{} +} + // //@solo-kit:xds-service=MockXdsResourceDiscoveryService //@solo-kit:resource.no_references @@ -306,44 +314,44 @@ func init() { } var fileDescriptor_5de7a91ad5dc71ff = []byte{ - // 577 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0x31, 0x6f, 0xd3, 0x40, - 0x14, 0xc7, 0xeb, 0xd4, 0x4d, 0xdb, 0xa3, 0x55, 0x85, 0x1b, 0xaa, 0xc8, 0x94, 0x26, 0x4a, 0x11, - 0x0a, 0x08, 0x6c, 0x12, 0x16, 0x94, 0x31, 0x44, 0x11, 0x4b, 0x85, 0xe4, 0x30, 0x20, 0x96, 0xe8, - 0x62, 0xbf, 0xb8, 0x87, 0xe3, 0x7b, 0xc1, 0x77, 0x76, 0xe9, 0x86, 0x32, 0xb0, 0x31, 0xf1, 0x25, - 0xf8, 0x0c, 0x7c, 0x02, 0x76, 0xf6, 0x0e, 0x88, 0x89, 0x2d, 0xdf, 0x00, 0xf9, 0x6c, 0xa7, 0x4a, - 0x29, 0x55, 0x41, 0x62, 0xf2, 0xbd, 0xfb, 0xbf, 0xdf, 0x7b, 0xef, 0x9e, 0xdf, 0x1d, 0xe9, 0xfa, - 0x4c, 0x1e, 0xc7, 0x23, 0xcb, 0xc5, 0xd0, 0x16, 0x38, 0xc1, 0x47, 0x0c, 0xb3, 0x6f, 0xc0, 0xa4, - 0x2d, 0x41, 0x48, 0x3b, 0x44, 0x37, 0x10, 0x36, 0x9d, 0x32, 0x3b, 0x69, 0x29, 0x63, 0x18, 0x81, - 0xc0, 0x38, 0x72, 0x41, 0x58, 0xd3, 0x08, 0x25, 0x1a, 0x3b, 0xa9, 0x1f, 0xe3, 0xbe, 0x95, 0x82, - 0x16, 0x43, 0x73, 0x1f, 0x78, 0x82, 0xa7, 0x19, 0xd3, 0xb6, 0x3d, 0x26, 0x5c, 0x4c, 0x20, 0x3a, - 0xcd, 0xdc, 0xcd, 0x7d, 0x1f, 0xd1, 0x9f, 0x80, 0x92, 0x29, 0xe7, 0x28, 0xa9, 0x64, 0xc8, 0xf3, - 0x60, 0x66, 0xc5, 0x47, 0x1f, 0xd5, 0xd2, 0x4e, 0x57, 0xf9, 0x6e, 0xeb, 0xaa, 0x32, 0x8b, 0xda, - 0x40, 0x52, 0x8f, 0x4a, 0x9a, 0x23, 0xf6, 0x35, 0x10, 0x21, 0xa9, 0x8c, 0xc5, 0x5f, 0xe4, 0x28, - 0xec, 0x0c, 0x69, 0x7c, 0x29, 0x91, 0xad, 0x23, 0x74, 0x03, 0x27, 0xef, 0x88, 0xd1, 0x26, 0xe5, - 0x2c, 0x66, 0xb5, 0x5c, 0xd7, 0x9a, 0x37, 0xda, 0x15, 0xcb, 0xc5, 0x08, 0x8a, 0xc6, 0x58, 0x03, - 0xa5, 0x75, 0xf5, 0xaf, 0x67, 0xb5, 0x15, 0x27, 0xf7, 0x34, 0x9e, 0x92, 0x8d, 0xa2, 0xf4, 0xea, - 0xba, 0xa2, 0xf6, 0x96, 0xa9, 0xa3, 0x5c, 0xcd, 0xb9, 0x85, 0xb7, 0x71, 0x8f, 0xe8, 0x8a, 0xd2, - 0xea, 0x5a, 0x73, 0xb3, 0xbb, 0xfd, 0xf3, 0xac, 0xb6, 0xa9, 0x1a, 0xf0, 0x46, 0x20, 0x77, 0xce, - 0x97, 0xc6, 0x43, 0xb2, 0x23, 0x30, 0x84, 0xa1, 0x17, 0x87, 0xa3, 0xe1, 0x98, 0xc1, 0xc4, 0xab, - 0x7a, 0x0a, 0xd1, 0xdf, 0xcf, 0x75, 0xcd, 0xd9, 0x4e, 0xc5, 0x5e, 0x1c, 0x8e, 0xfa, 0xa9, 0x64, - 0xdc, 0x21, 0x9b, 0xc8, 0x01, 0xc7, 0x43, 0xe4, 0x50, 0x5d, 0x4d, 0xfd, 0x9e, 0xaf, 0x38, 0x1b, - 0x6a, 0xeb, 0x05, 0x87, 0x73, 0x59, 0x9e, 0x60, 0xb5, 0x54, 0xd7, 0x9a, 0x1b, 0x0b, 0xf9, 0xe5, - 0x09, 0x76, 0x76, 0x67, 0x73, 0x5d, 0x27, 0xa5, 0x30, 0x98, 0xcd, 0xf5, 0x75, 0x63, 0x4d, 0x4d, - 0x4f, 0x77, 0x97, 0xdc, 0x4c, 0x67, 0x64, 0x98, 0x81, 0xaa, 0x02, 0xd1, 0x10, 0x64, 0xab, 0x4f, - 0x03, 0x58, 0xf4, 0xae, 0x42, 0xd6, 0x5c, 0x8c, 0xb9, 0x54, 0xc7, 0xd9, 0x76, 0x32, 0xe3, 0xdf, - 0xbb, 0x53, 0x54, 0x32, 0xce, 0x2b, 0x19, 0xd3, 0x00, 0x44, 0xc3, 0x26, 0xb7, 0xd2, 0x1f, 0xf6, - 0xca, 0x13, 0x45, 0xde, 0x67, 0xc8, 0xc7, 0xcc, 0x37, 0xf6, 0x48, 0xd9, 0xc3, 0x90, 0x32, 0x9e, - 0x75, 0xd3, 0xc9, 0xad, 0xf6, 0x87, 0x55, 0x52, 0xbb, 0x40, 0xf4, 0x8a, 0x81, 0x1e, 0x40, 0x94, - 0x30, 0x17, 0x0c, 0x8f, 0xdc, 0x1e, 0xc8, 0x08, 0x68, 0x78, 0x79, 0xe8, 0x03, 0x4b, 0xdd, 0x07, - 0x8b, 0x4e, 0x99, 0x95, 0xb4, 0xad, 0x05, 0xee, 0xc0, 0xdb, 0x18, 0x84, 0x34, 0x6b, 0x7f, 0xd4, - 0xc5, 0x14, 0xb9, 0x80, 0xc6, 0x4a, 0x53, 0x7b, 0xac, 0x19, 0x21, 0x31, 0x7b, 0x30, 0x91, 0xf4, - 0xf2, 0x24, 0x87, 0x17, 0x82, 0xa4, 0x9e, 0xbf, 0x65, 0xba, 0x7b, 0xb5, 0xd3, 0x52, 0xba, 0x8f, - 0x1a, 0x31, 0xfb, 0x20, 0xdd, 0xe3, 0xff, 0x74, 0x28, 0x6b, 0xf6, 0xed, 0xc7, 0xa7, 0x52, 0xb3, - 0x71, 0xb8, 0xf4, 0x46, 0x74, 0xd2, 0x81, 0x79, 0xe7, 0x89, 0xe2, 0x8d, 0x71, 0x55, 0xb6, 0x8e, - 0xf6, 0xa0, 0x6b, 0x7f, 0xfe, 0x7e, 0xa0, 0xbd, 0xbe, 0x7f, 0xcd, 0xf7, 0x2a, 0x69, 0x8d, 0xca, - 0xea, 0x8e, 0x3e, 0xf9, 0x15, 0x00, 0x00, 0xff, 0xff, 0xc3, 0x3d, 0x67, 0xce, 0xe3, 0x04, 0x00, - 0x00, + // 582 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x54, 0x31, 0x6f, 0xd3, 0x40, + 0x14, 0xae, 0x53, 0x37, 0x6d, 0x8f, 0x56, 0x15, 0x6e, 0xa9, 0x22, 0x53, 0x9a, 0x28, 0x45, 0x28, + 0x20, 0xb0, 0x49, 0x58, 0x50, 0xc6, 0x10, 0x45, 0x2c, 0x15, 0x92, 0xc3, 0x80, 0x58, 0xa2, 0x8b, + 0xfd, 0xe2, 0x1e, 0x8e, 0xef, 0x05, 0xdf, 0xd9, 0xa5, 0x1b, 0xca, 0xc0, 0xc6, 0xc4, 0x8f, 0x80, + 0xdf, 0xc0, 0x2f, 0x60, 0x67, 0xef, 0x80, 0x98, 0xd8, 0xf2, 0x0f, 0x90, 0xcf, 0x76, 0xaa, 0x94, + 0x52, 0x15, 0x10, 0x93, 0xef, 0xf9, 0xfb, 0xbe, 0xf7, 0xbe, 0x7b, 0x77, 0xf7, 0x48, 0xc7, 0x67, + 0xf2, 0x28, 0x1e, 0x5a, 0x2e, 0x86, 0xb6, 0xc0, 0x31, 0x3e, 0x60, 0x98, 0x7d, 0x03, 0x26, 0x6d, + 0x09, 0x42, 0xda, 0x21, 0xba, 0x81, 0xb0, 0xe9, 0x84, 0xd9, 0x49, 0x53, 0x05, 0x83, 0x08, 0x04, + 0xc6, 0x91, 0x0b, 0xc2, 0x9a, 0x44, 0x28, 0xd1, 0xd8, 0x4a, 0x79, 0x8c, 0xfb, 0x56, 0x2a, 0xb4, + 0x18, 0x9a, 0x7b, 0xc0, 0x13, 0x3c, 0xc9, 0x34, 0x2d, 0xdb, 0x63, 0xc2, 0xc5, 0x04, 0xa2, 0x93, + 0x8c, 0x6e, 0xee, 0xf9, 0x88, 0xfe, 0x18, 0x14, 0x4c, 0x39, 0x47, 0x49, 0x25, 0x43, 0x9e, 0x27, + 0x33, 0x77, 0x7c, 0xf4, 0x51, 0x2d, 0xed, 0x74, 0x95, 0xff, 0x6d, 0x5e, 0x66, 0xb3, 0xf0, 0x06, + 0x92, 0x7a, 0x54, 0xd2, 0x5c, 0x62, 0x5f, 0x41, 0x22, 0x24, 0x95, 0xb1, 0xf8, 0x83, 0x1a, 0x45, + 0x9c, 0x49, 0xea, 0x9f, 0x4b, 0x64, 0xe3, 0x10, 0xdd, 0xc0, 0xc9, 0x3b, 0x62, 0xb4, 0x48, 0x39, + 0xcb, 0x59, 0x29, 0xd7, 0xb4, 0xc6, 0xb5, 0xd6, 0x8e, 0xe5, 0x62, 0x04, 0x45, 0x63, 0xac, 0xbe, + 0xc2, 0x3a, 0xfa, 0x97, 0xd3, 0xea, 0x92, 0x93, 0x33, 0x8d, 0xc7, 0x64, 0xad, 0xb0, 0x5e, 0x59, + 0x55, 0xaa, 0xdd, 0x45, 0xd5, 0x61, 0x8e, 0xe6, 0xba, 0x39, 0xdb, 0xb8, 0x43, 0x74, 0xa5, 0xd2, + 0x6a, 0x5a, 0x63, 0xbd, 0xb3, 0xf9, 0xe3, 0xb4, 0xba, 0xae, 0x1a, 0xf0, 0x4a, 0x20, 0x77, 0xce, + 0x96, 0xc6, 0x7d, 0xb2, 0x25, 0x30, 0x84, 0x81, 0x17, 0x87, 0xc3, 0xc1, 0x88, 0xc1, 0xd8, 0xab, + 0x78, 0x4a, 0xa2, 0xbf, 0x9d, 0xe9, 0x9a, 0xb3, 0x99, 0x82, 0xdd, 0x38, 0x1c, 0xf6, 0x52, 0xc8, + 0xb8, 0x45, 0xd6, 0x91, 0x03, 0x8e, 0x06, 0xc8, 0xa1, 0xb2, 0x9c, 0xf2, 0x9e, 0x2e, 0x39, 0x6b, + 0xea, 0xd7, 0x33, 0x0e, 0x67, 0xb0, 0x3c, 0xc6, 0x4a, 0xa9, 0xa6, 0x35, 0xd6, 0xe6, 0xf0, 0xf3, + 0x63, 0x6c, 0x6f, 0x4f, 0x67, 0xba, 0x4e, 0x4a, 0x61, 0x30, 0x9d, 0xe9, 0xab, 0xc6, 0x8a, 0xba, + 0x3d, 0x9d, 0x6d, 0x72, 0x3d, 0xbd, 0x23, 0x83, 0x4c, 0xa8, 0x1c, 0x88, 0xfa, 0x47, 0x8d, 0x6c, + 0xf4, 0x68, 0x00, 0xf3, 0xe6, 0xed, 0x90, 0x15, 0x17, 0x63, 0x2e, 0xd5, 0x7e, 0x36, 0x9d, 0x2c, + 0xf8, 0x87, 0xf6, 0xfc, 0xc5, 0x61, 0x14, 0xf6, 0x47, 0xb9, 0xfd, 0x11, 0x0d, 0x40, 0xd4, 0x6d, + 0x72, 0x23, 0x3d, 0xe5, 0x17, 0x9e, 0x28, 0xbc, 0x3e, 0x41, 0x3e, 0x62, 0xbe, 0xb1, 0x4b, 0xca, + 0x1e, 0x86, 0x94, 0xf1, 0xec, 0x08, 0x9c, 0x3c, 0x6a, 0xbd, 0x5b, 0x26, 0xd5, 0x73, 0x8a, 0x6e, + 0xf1, 0x0a, 0xfa, 0x10, 0x25, 0xcc, 0x05, 0xc3, 0x23, 0x37, 0xfb, 0x32, 0x02, 0x1a, 0x5e, 0x9c, + 0x7a, 0xdf, 0x52, 0x8f, 0xc8, 0xa2, 0x13, 0x66, 0x25, 0x2d, 0x6b, 0x2e, 0x77, 0xe0, 0x75, 0x0c, + 0x42, 0x9a, 0xd5, 0xdf, 0xe2, 0x62, 0x82, 0x5c, 0x40, 0x7d, 0xa9, 0xa1, 0x3d, 0xd4, 0x8c, 0x90, + 0x98, 0x5d, 0x18, 0x4b, 0x7a, 0x71, 0x91, 0x83, 0x73, 0x49, 0x52, 0xe6, 0x2f, 0x95, 0x6e, 0x5f, + 0x4e, 0x5a, 0x28, 0xf7, 0x5e, 0x23, 0x66, 0x0f, 0xa4, 0x7b, 0xf4, 0x9f, 0x36, 0x65, 0x4d, 0xbf, + 0x7e, 0xff, 0x50, 0x6a, 0xd4, 0x0f, 0x16, 0x06, 0x4b, 0x3b, 0xbd, 0x65, 0x6f, 0x3c, 0x51, 0x0c, + 0x26, 0x57, 0x55, 0x6b, 0x6b, 0xf7, 0x3a, 0xf6, 0xa7, 0x6f, 0xfb, 0xda, 0xcb, 0xbb, 0x57, 0x1c, + 0x72, 0x49, 0x73, 0x58, 0x56, 0x0f, 0xfb, 0xd1, 0xcf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x9a, 0xbf, + 0x07, 0x09, 0x18, 0x05, 0x00, 0x00, } func (this *MockResource) Equal(that interface{}) bool { @@ -464,6 +472,9 @@ func (this *FakeResource) Equal(that interface{}) bool { if !this.Metadata.Equal(&that1.Metadata) { return false } + if !this.Status.Equal(&that1.Status) { + return false + } if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) { return false } diff --git a/test/mocks/v1/testing.solo.io_suite_test.go b/test/mocks/v1/testing.solo.io_suite_test.go index 300f58bc0..c999c0c35 100644 --- a/test/mocks/v1/testing.solo.io_suite_test.go +++ b/test/mocks/v1/testing.solo.io_suite_test.go @@ -36,13 +36,13 @@ var ( Expect(err).NotTo(HaveOccurred()) clientset, err := apiexts.NewForConfig(cfg) Expect(err).NotTo(HaveOccurred()) - err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("anothermockresources.testing.solo.io", &metav1.DeleteOptions{}) - testutils.ErrorNotOccuredOrNotFound(err) - err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("clusterresources.testing.solo.io", &metav1.DeleteOptions{}) + err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("mocks.testing.solo.io", &metav1.DeleteOptions{}) testutils.ErrorNotOccuredOrNotFound(err) err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("fakes.testing.solo.io", &metav1.DeleteOptions{}) testutils.ErrorNotOccuredOrNotFound(err) - err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("mocks.testing.solo.io", &metav1.DeleteOptions{}) + err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("anothermockresources.testing.solo.io", &metav1.DeleteOptions{}) + testutils.ErrorNotOccuredOrNotFound(err) + err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("clusterresources.testing.solo.io", &metav1.DeleteOptions{}) testutils.ErrorNotOccuredOrNotFound(err) Expect(lock.ReleaseLock()).NotTo(HaveOccurred()) }) diff --git a/test/mocks/v1alpha1/fake_resource.sk.go b/test/mocks/v1alpha1/fake_resource.sk.go index 9d2ef7da6..afa37ef32 100644 --- a/test/mocks/v1alpha1/fake_resource.sk.go +++ b/test/mocks/v1alpha1/fake_resource.sk.go @@ -145,7 +145,7 @@ func init() { var ( FakeResourceGVK = schema.GroupVersionKind{ Version: "v1alpha1", - Group: "crds.testing.solo.io", + Group: "testing.solo.io", Kind: "FakeResource", } ) diff --git a/test/mocks/v1alpha1/mock_resource.sk.go b/test/mocks/v1alpha1/mock_resource.sk.go index b17533f0d..3b6bcd612 100644 --- a/test/mocks/v1alpha1/mock_resource.sk.go +++ b/test/mocks/v1alpha1/mock_resource.sk.go @@ -158,7 +158,7 @@ func init() { var ( MockResourceGVK = schema.GroupVersionKind{ Version: "v1alpha1", - Group: "crds.testing.solo.io", + Group: "testing.solo.io", Kind: "MockResource", } ) diff --git a/test/mocks/v1alpha1/more_mock_resources.pb.go b/test/mocks/v1alpha1/more_mock_resources.pb.go deleted file mode 100644 index 42465e30a..000000000 --- a/test/mocks/v1alpha1/more_mock_resources.pb.go +++ /dev/null @@ -1,238 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: github.com/solo-io/solo-kit/test/mocks/api/v1alpha1/more_mock_resources.proto - -package v1alpha1 - -import ( - bytes "bytes" - fmt "fmt" - math "math" - - _ "github.com/gogo/protobuf/gogoproto" - proto "github.com/gogo/protobuf/proto" - core "github.com/solo-io/solo-kit/pkg/api/v1/resources/core" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package - -// -//Description of the AnotherMockResource -type AnotherMockResource struct { - Metadata core.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata"` - Status core.Status `protobuf:"bytes,6,opt,name=status,proto3" json:"status"` - // comments that go above the basic field in our docs - BasicField string `protobuf:"bytes,2,opt,name=basic_field,json=basicField,proto3" json:"basic_field,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *AnotherMockResource) Reset() { *m = AnotherMockResource{} } -func (m *AnotherMockResource) String() string { return proto.CompactTextString(m) } -func (*AnotherMockResource) ProtoMessage() {} -func (*AnotherMockResource) Descriptor() ([]byte, []int) { - return fileDescriptor_adb5d88e228084e4, []int{0} -} -func (m *AnotherMockResource) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_AnotherMockResource.Unmarshal(m, b) -} -func (m *AnotherMockResource) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_AnotherMockResource.Marshal(b, m, deterministic) -} -func (m *AnotherMockResource) XXX_Merge(src proto.Message) { - xxx_messageInfo_AnotherMockResource.Merge(m, src) -} -func (m *AnotherMockResource) XXX_Size() int { - return xxx_messageInfo_AnotherMockResource.Size(m) -} -func (m *AnotherMockResource) XXX_DiscardUnknown() { - xxx_messageInfo_AnotherMockResource.DiscardUnknown(m) -} - -var xxx_messageInfo_AnotherMockResource proto.InternalMessageInfo - -func (m *AnotherMockResource) GetMetadata() core.Metadata { - if m != nil { - return m.Metadata - } - return core.Metadata{} -} - -func (m *AnotherMockResource) GetStatus() core.Status { - if m != nil { - return m.Status - } - return core.Status{} -} - -func (m *AnotherMockResource) GetBasicField() string { - if m != nil { - return m.BasicField - } - return "" -} - -type ClusterResource struct { - Metadata core.Metadata `protobuf:"bytes,1,opt,name=metadata,proto3" json:"metadata"` - Status core.Status `protobuf:"bytes,6,opt,name=status,proto3" json:"status"` - // comments that go above the basic field in our docs - BasicField string `protobuf:"bytes,2,opt,name=basic_field,json=basicField,proto3" json:"basic_field,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *ClusterResource) Reset() { *m = ClusterResource{} } -func (m *ClusterResource) String() string { return proto.CompactTextString(m) } -func (*ClusterResource) ProtoMessage() {} -func (*ClusterResource) Descriptor() ([]byte, []int) { - return fileDescriptor_adb5d88e228084e4, []int{1} -} -func (m *ClusterResource) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ClusterResource.Unmarshal(m, b) -} -func (m *ClusterResource) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ClusterResource.Marshal(b, m, deterministic) -} -func (m *ClusterResource) XXX_Merge(src proto.Message) { - xxx_messageInfo_ClusterResource.Merge(m, src) -} -func (m *ClusterResource) XXX_Size() int { - return xxx_messageInfo_ClusterResource.Size(m) -} -func (m *ClusterResource) XXX_DiscardUnknown() { - xxx_messageInfo_ClusterResource.DiscardUnknown(m) -} - -var xxx_messageInfo_ClusterResource proto.InternalMessageInfo - -func (m *ClusterResource) GetMetadata() core.Metadata { - if m != nil { - return m.Metadata - } - return core.Metadata{} -} - -func (m *ClusterResource) GetStatus() core.Status { - if m != nil { - return m.Status - } - return core.Status{} -} - -func (m *ClusterResource) GetBasicField() string { - if m != nil { - return m.BasicField - } - return "" -} - -func init() { - proto.RegisterType((*AnotherMockResource)(nil), "testing.solo.io.AnotherMockResource") - proto.RegisterType((*ClusterResource)(nil), "testing.solo.io.ClusterResource") -} - -func init() { - proto.RegisterFile("github.com/solo-io/solo-kit/test/mocks/api/v1alpha1/more_mock_resources.proto", fileDescriptor_adb5d88e228084e4) -} - -var fileDescriptor_adb5d88e228084e4 = []byte{ - // 335 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xcc, 0x92, 0xc1, 0x4e, 0x32, 0x31, - 0x10, 0xc7, 0xbf, 0xf2, 0xad, 0x44, 0xcb, 0x01, 0x53, 0x09, 0xd9, 0x70, 0x10, 0x82, 0x31, 0xe1, - 0x62, 0x1b, 0x30, 0x26, 0xc6, 0x9b, 0x98, 0x78, 0xe3, 0x82, 0x37, 0x2f, 0xa4, 0x94, 0xba, 0x34, - 0xec, 0x32, 0xa4, 0xed, 0xfa, 0x00, 0xfb, 0x34, 0xbe, 0x89, 0xfa, 0x12, 0x1e, 0x7c, 0x83, 0x7d, - 0x03, 0xd3, 0xed, 0xee, 0x26, 0x5e, 0x0c, 0xde, 0x3c, 0xb5, 0x9d, 0x99, 0x5f, 0xe7, 0xff, 0xcf, - 0x0c, 0x9e, 0x45, 0xca, 0xae, 0xd3, 0x25, 0x15, 0x90, 0x30, 0x03, 0x31, 0x5c, 0x28, 0xf0, 0xe7, - 0x46, 0x59, 0x66, 0xa5, 0xb1, 0x2c, 0x01, 0xb1, 0x31, 0x8c, 0xef, 0x14, 0x7b, 0x1e, 0xf3, 0x78, - 0xb7, 0xe6, 0x63, 0x96, 0x80, 0x96, 0x0b, 0x17, 0x5f, 0x68, 0x69, 0x20, 0xd5, 0x42, 0x1a, 0xba, - 0xd3, 0x60, 0x81, 0xb4, 0x1d, 0xa2, 0xb6, 0x11, 0x75, 0x7f, 0x50, 0x05, 0xbd, 0x4e, 0x04, 0x11, - 0x14, 0x39, 0xe6, 0x6e, 0xbe, 0xac, 0x37, 0xfe, 0xa9, 0xab, 0x6f, 0xc5, 0x12, 0x69, 0xf9, 0x8a, - 0x5b, 0x5e, 0x22, 0x6c, 0x0f, 0xc4, 0x58, 0x6e, 0x53, 0xf3, 0x8b, 0x1e, 0xd5, 0xdb, 0x23, 0xc3, - 0x77, 0x84, 0x4f, 0x6e, 0xb7, 0x60, 0xd7, 0x52, 0xcf, 0x40, 0x6c, 0xe6, 0xa5, 0x39, 0x72, 0x8d, - 0x0f, 0x2b, 0x35, 0x21, 0x1a, 0xa0, 0x51, 0x6b, 0xd2, 0xa5, 0x02, 0xb4, 0xac, 0x5c, 0xd2, 0x59, - 0x99, 0x9d, 0x06, 0x6f, 0x1f, 0xfd, 0x7f, 0xf3, 0xba, 0x9a, 0x4c, 0x70, 0xd3, 0x8b, 0x0a, 0x9b, - 0x05, 0xd7, 0xf9, 0xce, 0x3d, 0x14, 0xb9, 0x92, 0x2a, 0x2b, 0x49, 0x1f, 0xb7, 0x96, 0xdc, 0x28, - 0xb1, 0x78, 0x52, 0x32, 0x5e, 0x85, 0x8d, 0x01, 0x1a, 0x1d, 0xcd, 0x71, 0x11, 0xba, 0x77, 0x91, - 0x9b, 0xb3, 0x2c, 0x0f, 0x0e, 0xf0, 0x7f, 0x9e, 0xe8, 0x2c, 0x0f, 0xba, 0xa4, 0xc3, 0xbd, 0x64, - 0x37, 0x90, 0x7a, 0x1e, 0xc3, 0x57, 0x84, 0xdb, 0x77, 0x71, 0x6a, 0xac, 0xd4, 0x7f, 0xd5, 0xc7, - 0xb9, 0xf7, 0x21, 0x62, 0xe7, 0x83, 0x90, 0x63, 0xe1, 0xe5, 0xd6, 0x1e, 0xb2, 0x3c, 0x68, 0x84, - 0x68, 0x7a, 0xf5, 0xf2, 0x79, 0x8a, 0x1e, 0xd9, 0x9e, 0x8b, 0x5a, 0x2d, 0xe9, 0xb2, 0x59, 0xcc, - 0xf4, 0xf2, 0x2b, 0x00, 0x00, 0xff, 0xff, 0x51, 0x9f, 0xd0, 0xc7, 0xe2, 0x02, 0x00, 0x00, -} - -func (this *AnotherMockResource) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*AnotherMockResource) - if !ok { - that2, ok := that.(AnotherMockResource) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if !this.Metadata.Equal(&that1.Metadata) { - return false - } - if !this.Status.Equal(&that1.Status) { - return false - } - if this.BasicField != that1.BasicField { - return false - } - if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) { - return false - } - return true -} -func (this *ClusterResource) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*ClusterResource) - if !ok { - that2, ok := that.(ClusterResource) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if !this.Metadata.Equal(&that1.Metadata) { - return false - } - if !this.Status.Equal(&that1.Status) { - return false - } - if this.BasicField != that1.BasicField { - return false - } - if !bytes.Equal(this.XXX_unrecognized, that1.XXX_unrecognized) { - return false - } - return true -} diff --git a/test/mocks/v1alpha1/testing.solo.io_suite_test.go b/test/mocks/v1alpha1/testing.solo.io_suite_test.go index 57ce95c5a..4272f0dde 100644 --- a/test/mocks/v1alpha1/testing.solo.io_suite_test.go +++ b/test/mocks/v1alpha1/testing.solo.io_suite_test.go @@ -36,13 +36,13 @@ var ( Expect(err).NotTo(HaveOccurred()) clientset, err := apiexts.NewForConfig(cfg) Expect(err).NotTo(HaveOccurred()) - err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("anothermockresources.testing.solo.io", &metav1.DeleteOptions{}) - testutils.ErrorNotOccuredOrNotFound(err) - err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("clusterresources.testing.solo.io", &metav1.DeleteOptions{}) + err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("mocks.testing.solo.io", &metav1.DeleteOptions{}) testutils.ErrorNotOccuredOrNotFound(err) err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("fakes.testing.solo.io", &metav1.DeleteOptions{}) testutils.ErrorNotOccuredOrNotFound(err) - err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("mocks.testing.solo.io", &metav1.DeleteOptions{}) + err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("anothermockresources.testing.solo.io", &metav1.DeleteOptions{}) + testutils.ErrorNotOccuredOrNotFound(err) + err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("clusterresources.testing.solo.io", &metav1.DeleteOptions{}) testutils.ErrorNotOccuredOrNotFound(err) Expect(lock.ReleaseLock()).NotTo(HaveOccurred()) }) diff --git a/test/mocks/v1alpha1/testing_event_loop_test.go b/test/mocks/v1alpha1/testing_event_loop_test.go deleted file mode 100644 index 0950ce3d6..000000000 --- a/test/mocks/v1alpha1/testing_event_loop_test.go +++ /dev/null @@ -1,63 +0,0 @@ -// Code generated by solo-kit. DO NOT EDIT. - -// +build solokit - -package v1alpha1 - -import ( - "context" - "sync" - "time" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/solo-io/solo-kit/pkg/api/v1/clients" - "github.com/solo-io/solo-kit/pkg/api/v1/clients/factory" - "github.com/solo-io/solo-kit/pkg/api/v1/clients/memory" -) - -var _ = Describe("TestingEventLoop", func() { - var ( - namespace string - emitter TestingEmitter - err error - ) - - BeforeEach(func() { - - mockResourceClientFactory := &factory.MemoryResourceClientFactory{ - Cache: memory.NewInMemoryResourceCache(), - } - mockResourceClient, err := NewMockResourceClient(mockResourceClientFactory) - Expect(err).NotTo(HaveOccurred()) - - emitter = NewTestingEmitter(mockResourceClient) - }) - It("runs sync function on a new snapshot", func() { - _, err = emitter.MockResource().Write(NewMockResource(namespace, "jerry"), clients.WriteOpts{}) - Expect(err).NotTo(HaveOccurred()) - sync := &mockTestingSyncer{} - el := NewTestingEventLoop(emitter, sync) - _, err := el.Run([]string{namespace}, clients.WatchOpts{}) - Expect(err).NotTo(HaveOccurred()) - Eventually(sync.Synced, 5*time.Second).Should(BeTrue()) - }) -}) - -type mockTestingSyncer struct { - synced bool - mutex sync.Mutex -} - -func (s *mockTestingSyncer) Synced() bool { - s.mutex.Lock() - defer s.mutex.Unlock() - return s.synced -} - -func (s *mockTestingSyncer) Sync(ctx context.Context, snap *TestingSnapshot) error { - s.mutex.Lock() - s.synced = true - s.mutex.Unlock() - return nil -} diff --git a/test/mocks/v1alpha1/testing_simple_event_loop.sk.go b/test/mocks/v1alpha1/testing_simple_event_loop.sk.go deleted file mode 100644 index 05e3abea7..000000000 --- a/test/mocks/v1alpha1/testing_simple_event_loop.sk.go +++ /dev/null @@ -1,122 +0,0 @@ -// Code generated by solo-kit. DO NOT EDIT. - -package v1alpha1 - -import ( - "context" - "fmt" - - "go.opencensus.io/trace" - - "github.com/solo-io/go-utils/contextutils" - "github.com/solo-io/go-utils/errutils" - "github.com/solo-io/solo-kit/pkg/api/v1/eventloop" - "github.com/solo-io/solo-kit/pkg/errors" -) - -// SyncDeciders Syncer which implements this interface -// can make smarter decisions over whether -// it should be restarted (including having its context cancelled) -// based on a diff of the previous and current snapshot - -// Deprecated: use TestingSyncDeciderWithContext -type TestingSyncDecider interface { - TestingSyncer - ShouldSync(old, new *TestingSnapshot) bool -} - -type TestingSyncDeciderWithContext interface { - TestingSyncer - ShouldSync(ctx context.Context, old, new *TestingSnapshot) bool -} - -type testingSimpleEventLoop struct { - emitter TestingSimpleEmitter - syncers []TestingSyncer -} - -func NewTestingSimpleEventLoop(emitter TestingSimpleEmitter, syncers ...TestingSyncer) eventloop.SimpleEventLoop { - return &testingSimpleEventLoop{ - emitter: emitter, - syncers: syncers, - } -} - -func (el *testingSimpleEventLoop) Run(ctx context.Context) (<-chan error, error) { - ctx = contextutils.WithLogger(ctx, "v1alpha1.event_loop") - logger := contextutils.LoggerFrom(ctx) - logger.Infof("event loop started") - - errs := make(chan error) - - watch, emitterErrs, err := el.emitter.Snapshots(ctx) - if err != nil { - return nil, errors.Wrapf(err, "starting snapshot watch") - } - - go errutils.AggregateErrs(ctx, errs, emitterErrs, "v1alpha1.emitter errors") - go func() { - // create a new context for each syncer for each loop, cancel each before each loop - syncerCancels := make(map[TestingSyncer]context.CancelFunc) - - // use closure to allow cancel function to be updated as context changes - defer func() { - for _, cancel := range syncerCancels { - cancel() - } - }() - - // cache the previous snapshot for comparison - var previousSnapshot *TestingSnapshot - - for { - select { - case snapshot, ok := <-watch: - if !ok { - return - } - - // cancel any open watches from previous loop - for _, syncer := range el.syncers { - // allow the syncer to decide if we should sync it + cancel its previous context - if syncDecider, isDecider := syncer.(TestingSyncDecider); isDecider { - if shouldSync := syncDecider.ShouldSync(previousSnapshot, snapshot); !shouldSync { - continue // skip syncing this syncer - } - } else if syncDeciderWithContext, isDecider := syncer.(TestingSyncDeciderWithContext); isDecider { - if shouldSync := syncDeciderWithContext.ShouldSync(ctx, previousSnapshot, snapshot); !shouldSync { - continue // skip syncing this syncer - } - } - - // if this syncer had a previous context, cancel it - cancel, ok := syncerCancels[syncer] - if ok { - cancel() - } - - ctx, span := trace.StartSpan(ctx, fmt.Sprintf("testing.solo.io.SimpleEventLoopSync-%T", syncer)) - ctx, canc := context.WithCancel(ctx) - err := syncer.Sync(ctx, snapshot) - span.End() - - if err != nil { - select { - case errs <- err: - default: - logger.Errorf("write error channel is full! could not propagate err: %v", err) - } - } - - syncerCancels[syncer] = canc - } - - previousSnapshot = snapshot - - case <-ctx.Done(): - return - } - } - }() - return errs, nil -} diff --git a/test/mocks/v1alpha1/testing_snapshot.sk.go b/test/mocks/v1alpha1/testing_snapshot.sk.go deleted file mode 100644 index 42f788263..000000000 --- a/test/mocks/v1alpha1/testing_snapshot.sk.go +++ /dev/null @@ -1,60 +0,0 @@ -// Code generated by solo-kit. DO NOT EDIT. - -package v1alpha1 - -import ( - "fmt" - - "github.com/solo-io/go-utils/hashutils" - "go.uber.org/zap" -) - -type TestingSnapshot struct { - Mocks MockResourceList -} - -func (s TestingSnapshot) Clone() TestingSnapshot { - return TestingSnapshot{ - Mocks: s.Mocks.Clone(), - } -} - -func (s TestingSnapshot) Hash() uint64 { - return hashutils.HashAll( - s.hashMocks(), - ) -} - -func (s TestingSnapshot) hashMocks() uint64 { - return hashutils.HashAll(s.Mocks.AsInterfaces()...) -} - -func (s TestingSnapshot) HashFields() []zap.Field { - var fields []zap.Field - fields = append(fields, zap.Uint64("mocks", s.hashMocks())) - - return append(fields, zap.Uint64("snapshotHash", s.Hash())) -} - -type TestingSnapshotStringer struct { - Version uint64 - Mocks []string -} - -func (ss TestingSnapshotStringer) String() string { - s := fmt.Sprintf("TestingSnapshot %v\n", ss.Version) - - s += fmt.Sprintf(" Mocks %v\n", len(ss.Mocks)) - for _, name := range ss.Mocks { - s += fmt.Sprintf(" %v\n", name) - } - - return s -} - -func (s TestingSnapshot) Stringer() TestingSnapshotStringer { - return TestingSnapshotStringer{ - Version: s.Hash(), - Mocks: s.Mocks.NamespacesDotNames(), - } -} diff --git a/test/mocks/v1alpha1/testing_snapshot_emitter.sk.go b/test/mocks/v1alpha1/testing_snapshot_emitter.sk.go deleted file mode 100644 index 67ac556a2..000000000 --- a/test/mocks/v1alpha1/testing_snapshot_emitter.sk.go +++ /dev/null @@ -1,204 +0,0 @@ -// Code generated by solo-kit. DO NOT EDIT. - -package v1alpha1 - -import ( - "sync" - "time" - - "go.opencensus.io/stats" - "go.opencensus.io/stats/view" - "go.opencensus.io/tag" - - "github.com/solo-io/go-utils/errutils" - "github.com/solo-io/solo-kit/pkg/api/v1/clients" - "github.com/solo-io/solo-kit/pkg/errors" -) - -var ( - mTestingSnapshotIn = stats.Int64("testing.solo.io/snap_emitter/snap_in", "The number of snapshots in", "1") - mTestingSnapshotOut = stats.Int64("testing.solo.io/snap_emitter/snap_out", "The number of snapshots out", "1") - mTestingSnapshotMissed = stats.Int64("testing.solo.io/snap_emitter/snap_missed", "The number of snapshots missed", "1") - - testingsnapshotInView = &view.View{ - Name: "testing.solo.io_snap_emitter/snap_in", - Measure: mTestingSnapshotIn, - Description: "The number of snapshots updates coming in", - Aggregation: view.Count(), - TagKeys: []tag.Key{}, - } - testingsnapshotOutView = &view.View{ - Name: "testing.solo.io/snap_emitter/snap_out", - Measure: mTestingSnapshotOut, - Description: "The number of snapshots updates going out", - Aggregation: view.Count(), - TagKeys: []tag.Key{}, - } - testingsnapshotMissedView = &view.View{ - Name: "testing.solo.io/snap_emitter/snap_missed", - Measure: mTestingSnapshotMissed, - Description: "The number of snapshots updates going missed. this can happen in heavy load. missed snapshot will be re-tried after a second.", - Aggregation: view.Count(), - TagKeys: []tag.Key{}, - } -) - -func init() { - view.Register(testingsnapshotInView, testingsnapshotOutView, testingsnapshotMissedView) -} - -type TestingEmitter interface { - Register() error - MockResource() MockResourceClient - Snapshots(watchNamespaces []string, opts clients.WatchOpts) (<-chan *TestingSnapshot, <-chan error, error) -} - -func NewTestingEmitter(mockResourceClient MockResourceClient) TestingEmitter { - return NewTestingEmitterWithEmit(mockResourceClient, make(chan struct{})) -} - -func NewTestingEmitterWithEmit(mockResourceClient MockResourceClient, emit <-chan struct{}) TestingEmitter { - return &testingEmitter{ - mockResource: mockResourceClient, - forceEmit: emit, - } -} - -type testingEmitter struct { - forceEmit <-chan struct{} - mockResource MockResourceClient -} - -func (c *testingEmitter) Register() error { - if err := c.mockResource.Register(); err != nil { - return err - } - return nil -} - -func (c *testingEmitter) MockResource() MockResourceClient { - return c.mockResource -} - -func (c *testingEmitter) Snapshots(watchNamespaces []string, opts clients.WatchOpts) (<-chan *TestingSnapshot, <-chan error, error) { - - if len(watchNamespaces) == 0 { - watchNamespaces = []string{""} - } - - for _, ns := range watchNamespaces { - if ns == "" && len(watchNamespaces) > 1 { - return nil, nil, errors.Errorf("the \"\" namespace is used to watch all namespaces. Snapshots can either be tracked for " + - "specific namespaces or \"\" AllNamespaces, but not both.") - } - } - - errs := make(chan error) - var done sync.WaitGroup - ctx := opts.Ctx - /* Create channel for MockResource */ - type mockResourceListWithNamespace struct { - list MockResourceList - namespace string - } - mockResourceChan := make(chan mockResourceListWithNamespace) - - var initialMockResourceList MockResourceList - - currentSnapshot := TestingSnapshot{} - - for _, namespace := range watchNamespaces { - /* Setup namespaced watch for MockResource */ - { - mocks, err := c.mockResource.List(namespace, clients.ListOpts{Ctx: opts.Ctx, Selector: opts.Selector}) - if err != nil { - return nil, nil, errors.Wrapf(err, "initial MockResource list") - } - initialMockResourceList = append(initialMockResourceList, mocks...) - } - mockResourceNamespacesChan, mockResourceErrs, err := c.mockResource.Watch(namespace, opts) - if err != nil { - return nil, nil, errors.Wrapf(err, "starting MockResource watch") - } - - done.Add(1) - go func(namespace string) { - defer done.Done() - errutils.AggregateErrs(ctx, errs, mockResourceErrs, namespace+"-mocks") - }(namespace) - - /* Watch for changes and update snapshot */ - go func(namespace string) { - for { - select { - case <-ctx.Done(): - return - case mockResourceList := <-mockResourceNamespacesChan: - select { - case <-ctx.Done(): - return - case mockResourceChan <- mockResourceListWithNamespace{list: mockResourceList, namespace: namespace}: - } - } - } - }(namespace) - } - /* Initialize snapshot for Mocks */ - currentSnapshot.Mocks = initialMockResourceList.Sort() - - snapshots := make(chan *TestingSnapshot) - go func() { - // sent initial snapshot to kick off the watch - initialSnapshot := currentSnapshot.Clone() - snapshots <- &initialSnapshot - - originalSnapshot := TestingSnapshot{} - timer := time.NewTicker(time.Second * 1) - - sync := func() { - if originalSnapshot.Hash() == currentSnapshot.Hash() { - return - } - - sentSnapshot := currentSnapshot.Clone() - select { - case snapshots <- &sentSnapshot: - stats.Record(ctx, mTestingSnapshotOut.M(1)) - originalSnapshot = currentSnapshot.Clone() - default: - stats.Record(ctx, mTestingSnapshotMissed.M(1)) - } - } - mocksByNamespace := make(map[string]MockResourceList) - - for { - record := func() { stats.Record(ctx, mTestingSnapshotIn.M(1)) } - - select { - case <-timer.C: - sync() - case <-ctx.Done(): - close(snapshots) - done.Wait() - close(errs) - return - case <-c.forceEmit: - sentSnapshot := currentSnapshot.Clone() - snapshots <- &sentSnapshot - case mockResourceNamespacedList := <-mockResourceChan: - record() - - namespace := mockResourceNamespacedList.namespace - - // merge lists by namespace - mocksByNamespace[namespace] = mockResourceNamespacedList.list - var mockResourceList MockResourceList - for _, mocks := range mocksByNamespace { - mockResourceList = append(mockResourceList, mocks...) - } - currentSnapshot.Mocks = mockResourceList.Sort() - } - } - }() - return snapshots, errs, nil -} diff --git a/test/mocks/v1alpha1/testing_snapshot_emitter_test.go b/test/mocks/v1alpha1/testing_snapshot_emitter_test.go deleted file mode 100644 index 74a570606..000000000 --- a/test/mocks/v1alpha1/testing_snapshot_emitter_test.go +++ /dev/null @@ -1,208 +0,0 @@ -// Code generated by solo-kit. DO NOT EDIT. - -// +build solokit - -package v1alpha1 - -import ( - "context" - "os" - "time" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/solo-io/go-utils/kubeutils" - "github.com/solo-io/go-utils/log" - "github.com/solo-io/solo-kit/pkg/api/v1/clients" - "github.com/solo-io/solo-kit/pkg/api/v1/clients/factory" - kuberc "github.com/solo-io/solo-kit/pkg/api/v1/clients/kube" - "github.com/solo-io/solo-kit/test/helpers" - "k8s.io/client-go/kubernetes" - "k8s.io/client-go/rest" - - // Needed to run tests in GKE - _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" - - // From https://github.com/kubernetes/client-go/blob/53c7adfd0294caa142d961e1f780f74081d5b15f/examples/out-of-cluster-client-configuration/main.go#L31 - _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" -) - -var _ = Describe("V1Alpha1Emitter", func() { - if os.Getenv("RUN_KUBE_TESTS") != "1" { - log.Printf("This test creates kubernetes resources and is disabled by default. To enable, set RUN_KUBE_TESTS=1 in your env.") - return - } - var ( - namespace1 string - namespace2 string - name1, name2 = "angela" + helpers.RandString(3), "bob" + helpers.RandString(3) - cfg *rest.Config - kube kubernetes.Interface - emitter TestingEmitter - mockResourceClient MockResourceClient - ) - - BeforeEach(func() { - namespace1 = helpers.RandString(8) - namespace2 = helpers.RandString(8) - kube = helpers.MustKubeClient() - err := kubeutils.CreateNamespacesInParallel(kube, namespace1, namespace2) - Expect(err).NotTo(HaveOccurred()) - cfg, err = kubeutils.GetConfig("", "") - Expect(err).NotTo(HaveOccurred()) - // MockResource Constructor - mockResourceClientFactory := &factory.KubeResourceClientFactory{ - Crd: MockResourceCrd, - Cfg: cfg, - SharedCache: kuberc.NewKubeCache(context.TODO()), - } - - mockResourceClient, err = NewMockResourceClient(mockResourceClientFactory) - Expect(err).NotTo(HaveOccurred()) - emitter = NewTestingEmitter(mockResourceClient) - }) - AfterEach(func() { - err := kubeutils.DeleteNamespacesInParallelBlocking(kube, namespace1, namespace2) - Expect(err).NotTo(HaveOccurred()) - }) - It("tracks snapshots on changes to any resource", func() { - ctx := context.Background() - err := emitter.Register() - Expect(err).NotTo(HaveOccurred()) - - snapshots, errs, err := emitter.Snapshots([]string{namespace1, namespace2}, clients.WatchOpts{ - Ctx: ctx, - RefreshRate: time.Second, - }) - Expect(err).NotTo(HaveOccurred()) - - var snap *TestingSnapshot - - /* - MockResource - */ - - assertSnapshotMocks := func(expectMocks MockResourceList, unexpectMocks MockResourceList) { - drain: - for { - select { - case snap = <-snapshots: - for _, expected := range expectMocks { - if _, err := snap.Mocks.Find(expected.GetMetadata().Ref().Strings()); err != nil { - continue drain - } - } - for _, unexpected := range unexpectMocks { - if _, err := snap.Mocks.Find(unexpected.GetMetadata().Ref().Strings()); err == nil { - continue drain - } - } - break drain - case err := <-errs: - Expect(err).NotTo(HaveOccurred()) - case <-time.After(time.Second * 10): - nsList1, _ := mockResourceClient.List(namespace1, clients.ListOpts{}) - nsList2, _ := mockResourceClient.List(namespace2, clients.ListOpts{}) - combined := append(nsList1, nsList2...) - Fail("expected final snapshot before 10 seconds. expected " + log.Sprintf("%v", combined)) - } - } - } - mockResource1a, err := mockResourceClient.Write(NewMockResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - mockResource1b, err := mockResourceClient.Write(NewMockResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotMocks(MockResourceList{mockResource1a, mockResource1b}, nil) - mockResource2a, err := mockResourceClient.Write(NewMockResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - mockResource2b, err := mockResourceClient.Write(NewMockResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotMocks(MockResourceList{mockResource1a, mockResource1b, mockResource2a, mockResource2b}, nil) - - err = mockResourceClient.Delete(mockResource2a.GetMetadata().Namespace, mockResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - err = mockResourceClient.Delete(mockResource2b.GetMetadata().Namespace, mockResource2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotMocks(MockResourceList{mockResource1a, mockResource1b}, MockResourceList{mockResource2a, mockResource2b}) - - err = mockResourceClient.Delete(mockResource1a.GetMetadata().Namespace, mockResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - err = mockResourceClient.Delete(mockResource1b.GetMetadata().Namespace, mockResource1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotMocks(nil, MockResourceList{mockResource1a, mockResource1b, mockResource2a, mockResource2b}) - }) - It("tracks snapshots on changes to any resource using AllNamespace", func() { - ctx := context.Background() - err := emitter.Register() - Expect(err).NotTo(HaveOccurred()) - - snapshots, errs, err := emitter.Snapshots([]string{""}, clients.WatchOpts{ - Ctx: ctx, - RefreshRate: time.Second, - }) - Expect(err).NotTo(HaveOccurred()) - - var snap *TestingSnapshot - - /* - MockResource - */ - - assertSnapshotMocks := func(expectMocks MockResourceList, unexpectMocks MockResourceList) { - drain: - for { - select { - case snap = <-snapshots: - for _, expected := range expectMocks { - if _, err := snap.Mocks.Find(expected.GetMetadata().Ref().Strings()); err != nil { - continue drain - } - } - for _, unexpected := range unexpectMocks { - if _, err := snap.Mocks.Find(unexpected.GetMetadata().Ref().Strings()); err == nil { - continue drain - } - } - break drain - case err := <-errs: - Expect(err).NotTo(HaveOccurred()) - case <-time.After(time.Second * 10): - nsList1, _ := mockResourceClient.List(namespace1, clients.ListOpts{}) - nsList2, _ := mockResourceClient.List(namespace2, clients.ListOpts{}) - combined := append(nsList1, nsList2...) - Fail("expected final snapshot before 10 seconds. expected " + log.Sprintf("%v", combined)) - } - } - } - mockResource1a, err := mockResourceClient.Write(NewMockResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - mockResource1b, err := mockResourceClient.Write(NewMockResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotMocks(MockResourceList{mockResource1a, mockResource1b}, nil) - mockResource2a, err := mockResourceClient.Write(NewMockResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - mockResource2b, err := mockResourceClient.Write(NewMockResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotMocks(MockResourceList{mockResource1a, mockResource1b, mockResource2a, mockResource2b}, nil) - - err = mockResourceClient.Delete(mockResource2a.GetMetadata().Namespace, mockResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - err = mockResourceClient.Delete(mockResource2b.GetMetadata().Namespace, mockResource2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotMocks(MockResourceList{mockResource1a, mockResource1b}, MockResourceList{mockResource2a, mockResource2b}) - - err = mockResourceClient.Delete(mockResource1a.GetMetadata().Namespace, mockResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - err = mockResourceClient.Delete(mockResource1b.GetMetadata().Namespace, mockResource1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotMocks(nil, MockResourceList{mockResource1a, mockResource1b, mockResource2a, mockResource2b}) - }) -}) diff --git a/test/mocks/v1alpha1/testing_snapshot_simple_emitter.sk.go b/test/mocks/v1alpha1/testing_snapshot_simple_emitter.sk.go deleted file mode 100644 index 52fc11597..000000000 --- a/test/mocks/v1alpha1/testing_snapshot_simple_emitter.sk.go +++ /dev/null @@ -1,100 +0,0 @@ -// Code generated by solo-kit. DO NOT EDIT. - -package v1alpha1 - -import ( - "context" - fmt "fmt" - "time" - - "go.opencensus.io/stats" - - "github.com/solo-io/go-utils/errutils" - "github.com/solo-io/solo-kit/pkg/api/v1/clients" -) - -type TestingSimpleEmitter interface { - Snapshots(ctx context.Context) (<-chan *TestingSnapshot, <-chan error, error) -} - -func NewTestingSimpleEmitter(aggregatedWatch clients.ResourceWatch) TestingSimpleEmitter { - return NewTestingSimpleEmitterWithEmit(aggregatedWatch, make(chan struct{})) -} - -func NewTestingSimpleEmitterWithEmit(aggregatedWatch clients.ResourceWatch, emit <-chan struct{}) TestingSimpleEmitter { - return &testingSimpleEmitter{ - aggregatedWatch: aggregatedWatch, - forceEmit: emit, - } -} - -type testingSimpleEmitter struct { - forceEmit <-chan struct{} - aggregatedWatch clients.ResourceWatch -} - -func (c *testingSimpleEmitter) Snapshots(ctx context.Context) (<-chan *TestingSnapshot, <-chan error, error) { - snapshots := make(chan *TestingSnapshot) - errs := make(chan error) - - untyped, watchErrs, err := c.aggregatedWatch(ctx) - if err != nil { - return nil, nil, err - } - - go errutils.AggregateErrs(ctx, errs, watchErrs, "testing-emitter") - - go func() { - originalSnapshot := TestingSnapshot{} - currentSnapshot := originalSnapshot.Clone() - timer := time.NewTicker(time.Second * 1) - sync := func() { - if originalSnapshot.Hash() == currentSnapshot.Hash() { - return - } - - stats.Record(ctx, mTestingSnapshotOut.M(1)) - originalSnapshot = currentSnapshot.Clone() - sentSnapshot := currentSnapshot.Clone() - snapshots <- &sentSnapshot - } - - defer func() { - close(snapshots) - close(errs) - }() - - for { - record := func() { stats.Record(ctx, mTestingSnapshotIn.M(1)) } - - select { - case <-timer.C: - sync() - case <-ctx.Done(): - return - case <-c.forceEmit: - sentSnapshot := currentSnapshot.Clone() - snapshots <- &sentSnapshot - case untypedList := <-untyped: - record() - - currentSnapshot = TestingSnapshot{} - for _, res := range untypedList { - switch typed := res.(type) { - case *MockResource: - currentSnapshot.Mocks = append(currentSnapshot.Mocks, typed) - default: - select { - case errs <- fmt.Errorf("TestingSnapshotEmitter "+ - "cannot process resource %v of type %T", res.GetMetadata().Ref(), res): - case <-ctx.Done(): - return - } - } - } - - } - } - }() - return snapshots, errs, nil -} diff --git a/test/mocks/v2alpha1/testing.solo.io_suite_test.go b/test/mocks/v2alpha1/testing.solo.io_suite_test.go index 358919f9b..2d6a94828 100644 --- a/test/mocks/v2alpha1/testing.solo.io_suite_test.go +++ b/test/mocks/v2alpha1/testing.solo.io_suite_test.go @@ -36,13 +36,13 @@ var ( Expect(err).NotTo(HaveOccurred()) clientset, err := apiexts.NewForConfig(cfg) Expect(err).NotTo(HaveOccurred()) - err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("anothermockresources.testing.solo.io", &metav1.DeleteOptions{}) - testutils.ErrorNotOccuredOrNotFound(err) - err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("clusterresources.testing.solo.io", &metav1.DeleteOptions{}) + err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("mocks.testing.solo.io", &metav1.DeleteOptions{}) testutils.ErrorNotOccuredOrNotFound(err) err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("fakes.testing.solo.io", &metav1.DeleteOptions{}) testutils.ErrorNotOccuredOrNotFound(err) - err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("mocks.testing.solo.io", &metav1.DeleteOptions{}) + err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("anothermockresources.testing.solo.io", &metav1.DeleteOptions{}) + testutils.ErrorNotOccuredOrNotFound(err) + err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Delete("clusterresources.testing.solo.io", &metav1.DeleteOptions{}) testutils.ErrorNotOccuredOrNotFound(err) Expect(lock.ReleaseLock()).NotTo(HaveOccurred()) }) diff --git a/test/mocks/v2alpha1/testing_event_loop.sk.go b/test/mocks/v2alpha1/testing_event_loop.sk.go deleted file mode 100644 index 4d76c8e71..000000000 --- a/test/mocks/v2alpha1/testing_event_loop.sk.go +++ /dev/null @@ -1,93 +0,0 @@ -// Code generated by solo-kit. DO NOT EDIT. - -package v2alpha1 - -import ( - "context" - - "go.opencensus.io/trace" - - "github.com/hashicorp/go-multierror" - - "github.com/solo-io/go-utils/contextutils" - "github.com/solo-io/go-utils/errutils" - "github.com/solo-io/solo-kit/pkg/api/v1/clients" - "github.com/solo-io/solo-kit/pkg/api/v1/eventloop" - "github.com/solo-io/solo-kit/pkg/errors" -) - -type TestingSyncer interface { - Sync(context.Context, *TestingSnapshot) error -} - -type TestingSyncers []TestingSyncer - -func (s TestingSyncers) Sync(ctx context.Context, snapshot *TestingSnapshot) error { - var multiErr *multierror.Error - for _, syncer := range s { - if err := syncer.Sync(ctx, snapshot); err != nil { - multiErr = multierror.Append(multiErr, err) - } - } - return multiErr.ErrorOrNil() -} - -type testingEventLoop struct { - emitter TestingEmitter - syncer TestingSyncer -} - -func NewTestingEventLoop(emitter TestingEmitter, syncer TestingSyncer) eventloop.EventLoop { - return &testingEventLoop{ - emitter: emitter, - syncer: syncer, - } -} - -func (el *testingEventLoop) Run(namespaces []string, opts clients.WatchOpts) (<-chan error, error) { - opts = opts.WithDefaults() - opts.Ctx = contextutils.WithLogger(opts.Ctx, "v2alpha1.event_loop") - logger := contextutils.LoggerFrom(opts.Ctx) - logger.Infof("event loop started") - - errs := make(chan error) - - watch, emitterErrs, err := el.emitter.Snapshots(namespaces, opts) - if err != nil { - return nil, errors.Wrapf(err, "starting snapshot watch") - } - go errutils.AggregateErrs(opts.Ctx, errs, emitterErrs, "v2alpha1.emitter errors") - go func() { - // create a new context for each loop, cancel it before each loop - var cancel context.CancelFunc = func() {} - // use closure to allow cancel function to be updated as context changes - defer func() { cancel() }() - for { - select { - case snapshot, ok := <-watch: - if !ok { - return - } - // cancel any open watches from previous loop - cancel() - - ctx, span := trace.StartSpan(opts.Ctx, "testing.solo.io.EventLoopSync") - ctx, canc := context.WithCancel(ctx) - cancel = canc - err := el.syncer.Sync(ctx, snapshot) - span.End() - - if err != nil { - select { - case errs <- err: - default: - logger.Errorf("write error channel is full! could not propagate err: %v", err) - } - } - case <-opts.Ctx.Done(): - return - } - } - }() - return errs, nil -} diff --git a/test/mocks/v2alpha1/testing_event_loop_test.go b/test/mocks/v2alpha1/testing_event_loop_test.go deleted file mode 100644 index e5bee236e..000000000 --- a/test/mocks/v2alpha1/testing_event_loop_test.go +++ /dev/null @@ -1,73 +0,0 @@ -// Code generated by solo-kit. DO NOT EDIT. - -// +build solokit - -package v2alpha1 - -import ( - "context" - "sync" - "time" - - testing_solo_io "github.com/solo-io/solo-kit/test/mocks/v1" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/solo-io/solo-kit/pkg/api/v1/clients" - "github.com/solo-io/solo-kit/pkg/api/v1/clients/factory" - "github.com/solo-io/solo-kit/pkg/api/v1/clients/memory" -) - -var _ = Describe("TestingEventLoop", func() { - var ( - namespace string - emitter TestingEmitter - err error - ) - - BeforeEach(func() { - - mockResourceClientFactory := &factory.MemoryResourceClientFactory{ - Cache: memory.NewInMemoryResourceCache(), - } - mockResourceClient, err := NewMockResourceClient(mockResourceClientFactory) - Expect(err).NotTo(HaveOccurred()) - - fakeResourceClientFactory := &factory.MemoryResourceClientFactory{ - Cache: memory.NewInMemoryResourceCache(), - } - fakeResourceClient, err := testing_solo_io.NewFakeResourceClient(fakeResourceClientFactory) - Expect(err).NotTo(HaveOccurred()) - - emitter = NewTestingEmitter(mockResourceClient, fakeResourceClient) - }) - It("runs sync function on a new snapshot", func() { - _, err = emitter.MockResource().Write(NewMockResource(namespace, "jerry"), clients.WriteOpts{}) - Expect(err).NotTo(HaveOccurred()) - _, err = emitter.FakeResource().Write(testing_solo_io.NewFakeResource(namespace, "jerry"), clients.WriteOpts{}) - Expect(err).NotTo(HaveOccurred()) - sync := &mockTestingSyncer{} - el := NewTestingEventLoop(emitter, sync) - _, err := el.Run([]string{namespace}, clients.WatchOpts{}) - Expect(err).NotTo(HaveOccurred()) - Eventually(sync.Synced, 5*time.Second).Should(BeTrue()) - }) -}) - -type mockTestingSyncer struct { - synced bool - mutex sync.Mutex -} - -func (s *mockTestingSyncer) Synced() bool { - s.mutex.Lock() - defer s.mutex.Unlock() - return s.synced -} - -func (s *mockTestingSyncer) Sync(ctx context.Context, snap *TestingSnapshot) error { - s.mutex.Lock() - s.synced = true - s.mutex.Unlock() - return nil -} diff --git a/test/mocks/v2alpha1/testing_snapshot.sk.go b/test/mocks/v2alpha1/testing_snapshot.sk.go deleted file mode 100644 index 7c4113b46..000000000 --- a/test/mocks/v2alpha1/testing_snapshot.sk.go +++ /dev/null @@ -1,77 +0,0 @@ -// Code generated by solo-kit. DO NOT EDIT. - -package v2alpha1 - -import ( - "fmt" - - testing_solo_io "github.com/solo-io/solo-kit/test/mocks/v1" - - "github.com/solo-io/go-utils/hashutils" - "go.uber.org/zap" -) - -type TestingSnapshot struct { - Mocks MockResourceList - Fakes testing_solo_io.FakeResourceList -} - -func (s TestingSnapshot) Clone() TestingSnapshot { - return TestingSnapshot{ - Mocks: s.Mocks.Clone(), - Fakes: s.Fakes.Clone(), - } -} - -func (s TestingSnapshot) Hash() uint64 { - return hashutils.HashAll( - s.hashMocks(), - s.hashFakes(), - ) -} - -func (s TestingSnapshot) hashMocks() uint64 { - return hashutils.HashAll(s.Mocks.AsInterfaces()...) -} - -func (s TestingSnapshot) hashFakes() uint64 { - return hashutils.HashAll(s.Fakes.AsInterfaces()...) -} - -func (s TestingSnapshot) HashFields() []zap.Field { - var fields []zap.Field - fields = append(fields, zap.Uint64("mocks", s.hashMocks())) - fields = append(fields, zap.Uint64("fakes", s.hashFakes())) - - return append(fields, zap.Uint64("snapshotHash", s.Hash())) -} - -type TestingSnapshotStringer struct { - Version uint64 - Mocks []string - Fakes []string -} - -func (ss TestingSnapshotStringer) String() string { - s := fmt.Sprintf("TestingSnapshot %v\n", ss.Version) - - s += fmt.Sprintf(" Mocks %v\n", len(ss.Mocks)) - for _, name := range ss.Mocks { - s += fmt.Sprintf(" %v\n", name) - } - - s += fmt.Sprintf(" Fakes %v\n", len(ss.Fakes)) - for _, name := range ss.Fakes { - s += fmt.Sprintf(" %v\n", name) - } - - return s -} - -func (s TestingSnapshot) Stringer() TestingSnapshotStringer { - return TestingSnapshotStringer{ - Version: s.Hash(), - Mocks: s.Mocks.NamespacesDotNames(), - Fakes: s.Fakes.NamespacesDotNames(), - } -} diff --git a/test/mocks/v2alpha1/testing_snapshot_emitter.sk.go b/test/mocks/v2alpha1/testing_snapshot_emitter.sk.go deleted file mode 100644 index 9c64b7157..000000000 --- a/test/mocks/v2alpha1/testing_snapshot_emitter.sk.go +++ /dev/null @@ -1,263 +0,0 @@ -// Code generated by solo-kit. DO NOT EDIT. - -package v2alpha1 - -import ( - "sync" - "time" - - testing_solo_io "github.com/solo-io/solo-kit/test/mocks/v1" - - "go.opencensus.io/stats" - "go.opencensus.io/stats/view" - "go.opencensus.io/tag" - - "github.com/solo-io/go-utils/errutils" - "github.com/solo-io/solo-kit/pkg/api/v1/clients" - "github.com/solo-io/solo-kit/pkg/errors" -) - -var ( - mTestingSnapshotIn = stats.Int64("testing.solo.io/snap_emitter/snap_in", "The number of snapshots in", "1") - mTestingSnapshotOut = stats.Int64("testing.solo.io/snap_emitter/snap_out", "The number of snapshots out", "1") - mTestingSnapshotMissed = stats.Int64("testing.solo.io/snap_emitter/snap_missed", "The number of snapshots missed", "1") - - testingsnapshotInView = &view.View{ - Name: "testing.solo.io_snap_emitter/snap_in", - Measure: mTestingSnapshotIn, - Description: "The number of snapshots updates coming in", - Aggregation: view.Count(), - TagKeys: []tag.Key{}, - } - testingsnapshotOutView = &view.View{ - Name: "testing.solo.io/snap_emitter/snap_out", - Measure: mTestingSnapshotOut, - Description: "The number of snapshots updates going out", - Aggregation: view.Count(), - TagKeys: []tag.Key{}, - } - testingsnapshotMissedView = &view.View{ - Name: "testing.solo.io/snap_emitter/snap_missed", - Measure: mTestingSnapshotMissed, - Description: "The number of snapshots updates going missed. this can happen in heavy load. missed snapshot will be re-tried after a second.", - Aggregation: view.Count(), - TagKeys: []tag.Key{}, - } -) - -func init() { - view.Register(testingsnapshotInView, testingsnapshotOutView, testingsnapshotMissedView) -} - -type TestingEmitter interface { - Register() error - MockResource() MockResourceClient - FakeResource() testing_solo_io.FakeResourceClient - Snapshots(watchNamespaces []string, opts clients.WatchOpts) (<-chan *TestingSnapshot, <-chan error, error) -} - -func NewTestingEmitter(mockResourceClient MockResourceClient, fakeResourceClient testing_solo_io.FakeResourceClient) TestingEmitter { - return NewTestingEmitterWithEmit(mockResourceClient, fakeResourceClient, make(chan struct{})) -} - -func NewTestingEmitterWithEmit(mockResourceClient MockResourceClient, fakeResourceClient testing_solo_io.FakeResourceClient, emit <-chan struct{}) TestingEmitter { - return &testingEmitter{ - mockResource: mockResourceClient, - fakeResource: fakeResourceClient, - forceEmit: emit, - } -} - -type testingEmitter struct { - forceEmit <-chan struct{} - mockResource MockResourceClient - fakeResource testing_solo_io.FakeResourceClient -} - -func (c *testingEmitter) Register() error { - if err := c.mockResource.Register(); err != nil { - return err - } - if err := c.fakeResource.Register(); err != nil { - return err - } - return nil -} - -func (c *testingEmitter) MockResource() MockResourceClient { - return c.mockResource -} - -func (c *testingEmitter) FakeResource() testing_solo_io.FakeResourceClient { - return c.fakeResource -} - -func (c *testingEmitter) Snapshots(watchNamespaces []string, opts clients.WatchOpts) (<-chan *TestingSnapshot, <-chan error, error) { - - if len(watchNamespaces) == 0 { - watchNamespaces = []string{""} - } - - for _, ns := range watchNamespaces { - if ns == "" && len(watchNamespaces) > 1 { - return nil, nil, errors.Errorf("the \"\" namespace is used to watch all namespaces. Snapshots can either be tracked for " + - "specific namespaces or \"\" AllNamespaces, but not both.") - } - } - - errs := make(chan error) - var done sync.WaitGroup - ctx := opts.Ctx - /* Create channel for MockResource */ - type mockResourceListWithNamespace struct { - list MockResourceList - namespace string - } - mockResourceChan := make(chan mockResourceListWithNamespace) - - var initialMockResourceList MockResourceList - /* Create channel for FakeResource */ - type fakeResourceListWithNamespace struct { - list testing_solo_io.FakeResourceList - namespace string - } - fakeResourceChan := make(chan fakeResourceListWithNamespace) - - var initialFakeResourceList testing_solo_io.FakeResourceList - - currentSnapshot := TestingSnapshot{} - - for _, namespace := range watchNamespaces { - /* Setup namespaced watch for MockResource */ - { - mocks, err := c.mockResource.List(namespace, clients.ListOpts{Ctx: opts.Ctx, Selector: opts.Selector}) - if err != nil { - return nil, nil, errors.Wrapf(err, "initial MockResource list") - } - initialMockResourceList = append(initialMockResourceList, mocks...) - } - mockResourceNamespacesChan, mockResourceErrs, err := c.mockResource.Watch(namespace, opts) - if err != nil { - return nil, nil, errors.Wrapf(err, "starting MockResource watch") - } - - done.Add(1) - go func(namespace string) { - defer done.Done() - errutils.AggregateErrs(ctx, errs, mockResourceErrs, namespace+"-mocks") - }(namespace) - /* Setup namespaced watch for FakeResource */ - { - fakes, err := c.fakeResource.List(namespace, clients.ListOpts{Ctx: opts.Ctx, Selector: opts.Selector}) - if err != nil { - return nil, nil, errors.Wrapf(err, "initial FakeResource list") - } - initialFakeResourceList = append(initialFakeResourceList, fakes...) - } - fakeResourceNamespacesChan, fakeResourceErrs, err := c.fakeResource.Watch(namespace, opts) - if err != nil { - return nil, nil, errors.Wrapf(err, "starting FakeResource watch") - } - - done.Add(1) - go func(namespace string) { - defer done.Done() - errutils.AggregateErrs(ctx, errs, fakeResourceErrs, namespace+"-fakes") - }(namespace) - - /* Watch for changes and update snapshot */ - go func(namespace string) { - for { - select { - case <-ctx.Done(): - return - case mockResourceList := <-mockResourceNamespacesChan: - select { - case <-ctx.Done(): - return - case mockResourceChan <- mockResourceListWithNamespace{list: mockResourceList, namespace: namespace}: - } - case fakeResourceList := <-fakeResourceNamespacesChan: - select { - case <-ctx.Done(): - return - case fakeResourceChan <- fakeResourceListWithNamespace{list: fakeResourceList, namespace: namespace}: - } - } - } - }(namespace) - } - /* Initialize snapshot for Mocks */ - currentSnapshot.Mocks = initialMockResourceList.Sort() - /* Initialize snapshot for Fakes */ - currentSnapshot.Fakes = initialFakeResourceList.Sort() - - snapshots := make(chan *TestingSnapshot) - go func() { - // sent initial snapshot to kick off the watch - initialSnapshot := currentSnapshot.Clone() - snapshots <- &initialSnapshot - - originalSnapshot := TestingSnapshot{} - timer := time.NewTicker(time.Second * 1) - - sync := func() { - if originalSnapshot.Hash() == currentSnapshot.Hash() { - return - } - - sentSnapshot := currentSnapshot.Clone() - select { - case snapshots <- &sentSnapshot: - stats.Record(ctx, mTestingSnapshotOut.M(1)) - originalSnapshot = currentSnapshot.Clone() - default: - stats.Record(ctx, mTestingSnapshotMissed.M(1)) - } - } - mocksByNamespace := make(map[string]MockResourceList) - fakesByNamespace := make(map[string]testing_solo_io.FakeResourceList) - - for { - record := func() { stats.Record(ctx, mTestingSnapshotIn.M(1)) } - - select { - case <-timer.C: - sync() - case <-ctx.Done(): - close(snapshots) - done.Wait() - close(errs) - return - case <-c.forceEmit: - sentSnapshot := currentSnapshot.Clone() - snapshots <- &sentSnapshot - case mockResourceNamespacedList := <-mockResourceChan: - record() - - namespace := mockResourceNamespacedList.namespace - - // merge lists by namespace - mocksByNamespace[namespace] = mockResourceNamespacedList.list - var mockResourceList MockResourceList - for _, mocks := range mocksByNamespace { - mockResourceList = append(mockResourceList, mocks...) - } - currentSnapshot.Mocks = mockResourceList.Sort() - case fakeResourceNamespacedList := <-fakeResourceChan: - record() - - namespace := fakeResourceNamespacedList.namespace - - // merge lists by namespace - fakesByNamespace[namespace] = fakeResourceNamespacedList.list - var fakeResourceList testing_solo_io.FakeResourceList - for _, fakes := range fakesByNamespace { - fakeResourceList = append(fakeResourceList, fakes...) - } - currentSnapshot.Fakes = fakeResourceList.Sort() - } - } - }() - return snapshots, errs, nil -} diff --git a/test/mocks/v2alpha1/testing_snapshot_emitter_test.go b/test/mocks/v2alpha1/testing_snapshot_emitter_test.go deleted file mode 100644 index 3e2975f24..000000000 --- a/test/mocks/v2alpha1/testing_snapshot_emitter_test.go +++ /dev/null @@ -1,333 +0,0 @@ -// Code generated by solo-kit. DO NOT EDIT. - -// +build solokit - -package v2alpha1 - -import ( - "context" - "os" - "time" - - testing_solo_io "github.com/solo-io/solo-kit/test/mocks/v1" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" - "github.com/solo-io/go-utils/kubeutils" - "github.com/solo-io/go-utils/log" - "github.com/solo-io/solo-kit/pkg/api/v1/clients" - "github.com/solo-io/solo-kit/pkg/api/v1/clients/factory" - kuberc "github.com/solo-io/solo-kit/pkg/api/v1/clients/kube" - "github.com/solo-io/solo-kit/pkg/api/v1/clients/memory" - "github.com/solo-io/solo-kit/test/helpers" - "k8s.io/client-go/kubernetes" - "k8s.io/client-go/rest" - - // Needed to run tests in GKE - _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" - - // From https://github.com/kubernetes/client-go/blob/53c7adfd0294caa142d961e1f780f74081d5b15f/examples/out-of-cluster-client-configuration/main.go#L31 - _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" -) - -var _ = Describe("V2Alpha1Emitter", func() { - if os.Getenv("RUN_KUBE_TESTS") != "1" { - log.Printf("This test creates kubernetes resources and is disabled by default. To enable, set RUN_KUBE_TESTS=1 in your env.") - return - } - var ( - namespace1 string - namespace2 string - name1, name2 = "angela" + helpers.RandString(3), "bob" + helpers.RandString(3) - cfg *rest.Config - kube kubernetes.Interface - emitter TestingEmitter - mockResourceClient MockResourceClient - fakeResourceClient testing_solo_io.FakeResourceClient - ) - - BeforeEach(func() { - namespace1 = helpers.RandString(8) - namespace2 = helpers.RandString(8) - kube = helpers.MustKubeClient() - err := kubeutils.CreateNamespacesInParallel(kube, namespace1, namespace2) - Expect(err).NotTo(HaveOccurred()) - cfg, err = kubeutils.GetConfig("", "") - Expect(err).NotTo(HaveOccurred()) - // MockResource Constructor - mockResourceClientFactory := &factory.KubeResourceClientFactory{ - Crd: MockResourceCrd, - Cfg: cfg, - SharedCache: kuberc.NewKubeCache(context.TODO()), - } - - mockResourceClient, err = NewMockResourceClient(mockResourceClientFactory) - Expect(err).NotTo(HaveOccurred()) - // FakeResource Constructor - fakeResourceClientFactory := &factory.MemoryResourceClientFactory{ - Cache: memory.NewInMemoryResourceCache(), - } - - fakeResourceClient, err = testing_solo_io.NewFakeResourceClient(fakeResourceClientFactory) - Expect(err).NotTo(HaveOccurred()) - emitter = NewTestingEmitter(mockResourceClient, fakeResourceClient) - }) - AfterEach(func() { - err := kubeutils.DeleteNamespacesInParallelBlocking(kube, namespace1, namespace2) - Expect(err).NotTo(HaveOccurred()) - }) - It("tracks snapshots on changes to any resource", func() { - ctx := context.Background() - err := emitter.Register() - Expect(err).NotTo(HaveOccurred()) - - snapshots, errs, err := emitter.Snapshots([]string{namespace1, namespace2}, clients.WatchOpts{ - Ctx: ctx, - RefreshRate: time.Second, - }) - Expect(err).NotTo(HaveOccurred()) - - var snap *TestingSnapshot - - /* - MockResource - */ - - assertSnapshotMocks := func(expectMocks MockResourceList, unexpectMocks MockResourceList) { - drain: - for { - select { - case snap = <-snapshots: - for _, expected := range expectMocks { - if _, err := snap.Mocks.Find(expected.GetMetadata().Ref().Strings()); err != nil { - continue drain - } - } - for _, unexpected := range unexpectMocks { - if _, err := snap.Mocks.Find(unexpected.GetMetadata().Ref().Strings()); err == nil { - continue drain - } - } - break drain - case err := <-errs: - Expect(err).NotTo(HaveOccurred()) - case <-time.After(time.Second * 10): - nsList1, _ := mockResourceClient.List(namespace1, clients.ListOpts{}) - nsList2, _ := mockResourceClient.List(namespace2, clients.ListOpts{}) - combined := append(nsList1, nsList2...) - Fail("expected final snapshot before 10 seconds. expected " + log.Sprintf("%v", combined)) - } - } - } - mockResource1a, err := mockResourceClient.Write(NewMockResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - mockResource1b, err := mockResourceClient.Write(NewMockResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotMocks(MockResourceList{mockResource1a, mockResource1b}, nil) - mockResource2a, err := mockResourceClient.Write(NewMockResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - mockResource2b, err := mockResourceClient.Write(NewMockResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotMocks(MockResourceList{mockResource1a, mockResource1b, mockResource2a, mockResource2b}, nil) - - err = mockResourceClient.Delete(mockResource2a.GetMetadata().Namespace, mockResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - err = mockResourceClient.Delete(mockResource2b.GetMetadata().Namespace, mockResource2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotMocks(MockResourceList{mockResource1a, mockResource1b}, MockResourceList{mockResource2a, mockResource2b}) - - err = mockResourceClient.Delete(mockResource1a.GetMetadata().Namespace, mockResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - err = mockResourceClient.Delete(mockResource1b.GetMetadata().Namespace, mockResource1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotMocks(nil, MockResourceList{mockResource1a, mockResource1b, mockResource2a, mockResource2b}) - - /* - FakeResource - */ - - assertSnapshotFakes := func(expectFakes testing_solo_io.FakeResourceList, unexpectFakes testing_solo_io.FakeResourceList) { - drain: - for { - select { - case snap = <-snapshots: - for _, expected := range expectFakes { - if _, err := snap.Fakes.Find(expected.GetMetadata().Ref().Strings()); err != nil { - continue drain - } - } - for _, unexpected := range unexpectFakes { - if _, err := snap.Fakes.Find(unexpected.GetMetadata().Ref().Strings()); err == nil { - continue drain - } - } - break drain - case err := <-errs: - Expect(err).NotTo(HaveOccurred()) - case <-time.After(time.Second * 10): - nsList1, _ := fakeResourceClient.List(namespace1, clients.ListOpts{}) - nsList2, _ := fakeResourceClient.List(namespace2, clients.ListOpts{}) - combined := append(nsList1, nsList2...) - Fail("expected final snapshot before 10 seconds. expected " + log.Sprintf("%v", combined)) - } - } - } - fakeResource1a, err := fakeResourceClient.Write(testing_solo_io.NewFakeResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - fakeResource1b, err := fakeResourceClient.Write(testing_solo_io.NewFakeResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotFakes(testing_solo_io.FakeResourceList{fakeResource1a, fakeResource1b}, nil) - fakeResource2a, err := fakeResourceClient.Write(testing_solo_io.NewFakeResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - fakeResource2b, err := fakeResourceClient.Write(testing_solo_io.NewFakeResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotFakes(testing_solo_io.FakeResourceList{fakeResource1a, fakeResource1b, fakeResource2a, fakeResource2b}, nil) - - err = fakeResourceClient.Delete(fakeResource2a.GetMetadata().Namespace, fakeResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - err = fakeResourceClient.Delete(fakeResource2b.GetMetadata().Namespace, fakeResource2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotFakes(testing_solo_io.FakeResourceList{fakeResource1a, fakeResource1b}, testing_solo_io.FakeResourceList{fakeResource2a, fakeResource2b}) - - err = fakeResourceClient.Delete(fakeResource1a.GetMetadata().Namespace, fakeResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - err = fakeResourceClient.Delete(fakeResource1b.GetMetadata().Namespace, fakeResource1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotFakes(nil, testing_solo_io.FakeResourceList{fakeResource1a, fakeResource1b, fakeResource2a, fakeResource2b}) - }) - It("tracks snapshots on changes to any resource using AllNamespace", func() { - ctx := context.Background() - err := emitter.Register() - Expect(err).NotTo(HaveOccurred()) - - snapshots, errs, err := emitter.Snapshots([]string{""}, clients.WatchOpts{ - Ctx: ctx, - RefreshRate: time.Second, - }) - Expect(err).NotTo(HaveOccurred()) - - var snap *TestingSnapshot - - /* - MockResource - */ - - assertSnapshotMocks := func(expectMocks MockResourceList, unexpectMocks MockResourceList) { - drain: - for { - select { - case snap = <-snapshots: - for _, expected := range expectMocks { - if _, err := snap.Mocks.Find(expected.GetMetadata().Ref().Strings()); err != nil { - continue drain - } - } - for _, unexpected := range unexpectMocks { - if _, err := snap.Mocks.Find(unexpected.GetMetadata().Ref().Strings()); err == nil { - continue drain - } - } - break drain - case err := <-errs: - Expect(err).NotTo(HaveOccurred()) - case <-time.After(time.Second * 10): - nsList1, _ := mockResourceClient.List(namespace1, clients.ListOpts{}) - nsList2, _ := mockResourceClient.List(namespace2, clients.ListOpts{}) - combined := append(nsList1, nsList2...) - Fail("expected final snapshot before 10 seconds. expected " + log.Sprintf("%v", combined)) - } - } - } - mockResource1a, err := mockResourceClient.Write(NewMockResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - mockResource1b, err := mockResourceClient.Write(NewMockResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotMocks(MockResourceList{mockResource1a, mockResource1b}, nil) - mockResource2a, err := mockResourceClient.Write(NewMockResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - mockResource2b, err := mockResourceClient.Write(NewMockResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotMocks(MockResourceList{mockResource1a, mockResource1b, mockResource2a, mockResource2b}, nil) - - err = mockResourceClient.Delete(mockResource2a.GetMetadata().Namespace, mockResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - err = mockResourceClient.Delete(mockResource2b.GetMetadata().Namespace, mockResource2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotMocks(MockResourceList{mockResource1a, mockResource1b}, MockResourceList{mockResource2a, mockResource2b}) - - err = mockResourceClient.Delete(mockResource1a.GetMetadata().Namespace, mockResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - err = mockResourceClient.Delete(mockResource1b.GetMetadata().Namespace, mockResource1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotMocks(nil, MockResourceList{mockResource1a, mockResource1b, mockResource2a, mockResource2b}) - - /* - FakeResource - */ - - assertSnapshotFakes := func(expectFakes testing_solo_io.FakeResourceList, unexpectFakes testing_solo_io.FakeResourceList) { - drain: - for { - select { - case snap = <-snapshots: - for _, expected := range expectFakes { - if _, err := snap.Fakes.Find(expected.GetMetadata().Ref().Strings()); err != nil { - continue drain - } - } - for _, unexpected := range unexpectFakes { - if _, err := snap.Fakes.Find(unexpected.GetMetadata().Ref().Strings()); err == nil { - continue drain - } - } - break drain - case err := <-errs: - Expect(err).NotTo(HaveOccurred()) - case <-time.After(time.Second * 10): - nsList1, _ := fakeResourceClient.List(namespace1, clients.ListOpts{}) - nsList2, _ := fakeResourceClient.List(namespace2, clients.ListOpts{}) - combined := append(nsList1, nsList2...) - Fail("expected final snapshot before 10 seconds. expected " + log.Sprintf("%v", combined)) - } - } - } - fakeResource1a, err := fakeResourceClient.Write(testing_solo_io.NewFakeResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - fakeResource1b, err := fakeResourceClient.Write(testing_solo_io.NewFakeResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotFakes(testing_solo_io.FakeResourceList{fakeResource1a, fakeResource1b}, nil) - fakeResource2a, err := fakeResourceClient.Write(testing_solo_io.NewFakeResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - fakeResource2b, err := fakeResourceClient.Write(testing_solo_io.NewFakeResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotFakes(testing_solo_io.FakeResourceList{fakeResource1a, fakeResource1b, fakeResource2a, fakeResource2b}, nil) - - err = fakeResourceClient.Delete(fakeResource2a.GetMetadata().Namespace, fakeResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - err = fakeResourceClient.Delete(fakeResource2b.GetMetadata().Namespace, fakeResource2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotFakes(testing_solo_io.FakeResourceList{fakeResource1a, fakeResource1b}, testing_solo_io.FakeResourceList{fakeResource2a, fakeResource2b}) - - err = fakeResourceClient.Delete(fakeResource1a.GetMetadata().Namespace, fakeResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - err = fakeResourceClient.Delete(fakeResource1b.GetMetadata().Namespace, fakeResource1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) - Expect(err).NotTo(HaveOccurred()) - - assertSnapshotFakes(nil, testing_solo_io.FakeResourceList{fakeResource1a, fakeResource1b, fakeResource2a, fakeResource2b}) - }) -}) diff --git a/test/mockstwo/api/solo-kit.json b/test/mockstwo/api/solo-kit.json new file mode 100644 index 000000000..0565e791c --- /dev/null +++ b/test/mockstwo/api/solo-kit.json @@ -0,0 +1,45 @@ +{ + "title": "Solo-Kit Testing Two", + "description": "mock solo-kit project", + "api_group": { + "name": "testingtwo.solo.io", + "docs_dir": "test/mockstwo/docs", + "resource_group_go_package": "github.com/solo-io/solo-kit/test/mockstwo/group", + "imports": [ + "github.com/solo-io/solo-kit/api/external/kubernetes", + "github.com/solo-io/solo-kit/test/mocks/api" + ], + "resource_groups": { + "testing.solo.io": [ + { + "name": "MockResource", + "package": "testing.solo.io", + "version": "v1" + }, + { + "name": "FakeResource", + "package": "testing.solo.io", + "version": "v1" + }, + { + "name": "AnotherMockResource", + "package": "testing.solo.io", + "version": "v1" + }, + { + "name": "ClusterResource", + "package": "testing.solo.io", + "version": "v1" + }, + { + "name": "MockCustomType", + "package": "github.com/solo-io/solo-kit/test/mocks/v1" + }, + { + "name": "Pod", + "package": "github.com/solo-io/solo-kit/pkg/api/v1/resources/common/kubernetes" + } + ] + } + } +} \ No newline at end of file diff --git a/test/mockstwo/group/group_suite_test.go b/test/mockstwo/group/group_suite_test.go new file mode 100644 index 000000000..8d2ddf537 --- /dev/null +++ b/test/mockstwo/group/group_suite_test.go @@ -0,0 +1,15 @@ +// Code generated by solo-kit. DO NOT EDIT. + +package group + +import ( + "testing" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" +) + +func TestGroup(t *testing.T) { + RegisterFailHandler(Fail) + RunSpecs(t, "Group Suite") +} diff --git a/test/mocks/v1alpha1/testing_event_loop.sk.go b/test/mockstwo/group/testing_event_loop.sk.go similarity index 92% rename from test/mocks/v1alpha1/testing_event_loop.sk.go rename to test/mockstwo/group/testing_event_loop.sk.go index 6c8a4c22e..68de46e85 100644 --- a/test/mocks/v1alpha1/testing_event_loop.sk.go +++ b/test/mockstwo/group/testing_event_loop.sk.go @@ -1,6 +1,6 @@ // Code generated by solo-kit. DO NOT EDIT. -package v1alpha1 +package group import ( "context" @@ -46,7 +46,7 @@ func NewTestingEventLoop(emitter TestingEmitter, syncer TestingSyncer) eventloop func (el *testingEventLoop) Run(namespaces []string, opts clients.WatchOpts) (<-chan error, error) { opts = opts.WithDefaults() - opts.Ctx = contextutils.WithLogger(opts.Ctx, "v1alpha1.event_loop") + opts.Ctx = contextutils.WithLogger(opts.Ctx, "group.event_loop") logger := contextutils.LoggerFrom(opts.Ctx) logger.Infof("event loop started") @@ -56,7 +56,7 @@ func (el *testingEventLoop) Run(namespaces []string, opts clients.WatchOpts) (<- if err != nil { return nil, errors.Wrapf(err, "starting snapshot watch") } - go errutils.AggregateErrs(opts.Ctx, errs, emitterErrs, "v1alpha1.emitter errors") + go errutils.AggregateErrs(opts.Ctx, errs, emitterErrs, "group.emitter errors") go func() { // create a new context for each loop, cancel it before each loop var cancel context.CancelFunc = func() {} diff --git a/test/mockstwo/group/testing_event_loop_test.go b/test/mockstwo/group/testing_event_loop_test.go new file mode 100644 index 000000000..a6e98ce3c --- /dev/null +++ b/test/mockstwo/group/testing_event_loop_test.go @@ -0,0 +1,107 @@ +// Code generated by solo-kit. DO NOT EDIT. + +// +build solokit + +package group + +import ( + "context" + "sync" + "time" + + github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes "github.com/solo-io/solo-kit/pkg/api/v1/resources/common/kubernetes" + github_com_solo_io_solo_kit_test_mocks_v1 "github.com/solo-io/solo-kit/test/mocks/v1" + testing_solo_io_kubernetes "github.com/solo-io/solo-kit/test/mocks/v1" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/solo-io/solo-kit/pkg/api/v1/clients" + "github.com/solo-io/solo-kit/pkg/api/v1/clients/factory" + "github.com/solo-io/solo-kit/pkg/api/v1/clients/memory" +) + +var _ = Describe("TestingEventLoop", func() { + var ( + namespace string + emitter TestingEmitter + err error + ) + + BeforeEach(func() { + + mockResourceClientFactory := &factory.MemoryResourceClientFactory{ + Cache: memory.NewInMemoryResourceCache(), + } + mockResourceClient, err := testing_solo_io_kubernetes.NewMockResourceClient(mockResourceClientFactory) + Expect(err).NotTo(HaveOccurred()) + + fakeResourceClientFactory := &factory.MemoryResourceClientFactory{ + Cache: memory.NewInMemoryResourceCache(), + } + fakeResourceClient, err := testing_solo_io_kubernetes.NewFakeResourceClient(fakeResourceClientFactory) + Expect(err).NotTo(HaveOccurred()) + + anotherMockResourceClientFactory := &factory.MemoryResourceClientFactory{ + Cache: memory.NewInMemoryResourceCache(), + } + anotherMockResourceClient, err := testing_solo_io_kubernetes.NewAnotherMockResourceClient(anotherMockResourceClientFactory) + Expect(err).NotTo(HaveOccurred()) + + clusterResourceClientFactory := &factory.MemoryResourceClientFactory{ + Cache: memory.NewInMemoryResourceCache(), + } + clusterResourceClient, err := testing_solo_io_kubernetes.NewClusterResourceClient(clusterResourceClientFactory) + Expect(err).NotTo(HaveOccurred()) + + mockCustomTypeClientFactory := &factory.MemoryResourceClientFactory{ + Cache: memory.NewInMemoryResourceCache(), + } + mockCustomTypeClient, err := github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomTypeClient(mockCustomTypeClientFactory) + Expect(err).NotTo(HaveOccurred()) + + podClientFactory := &factory.MemoryResourceClientFactory{ + Cache: memory.NewInMemoryResourceCache(), + } + podClient, err := github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.NewPodClient(podClientFactory) + Expect(err).NotTo(HaveOccurred()) + + emitter = NewTestingEmitter(mockResourceClient, fakeResourceClient, anotherMockResourceClient, clusterResourceClient, mockCustomTypeClient, podClient) + }) + It("runs sync function on a new snapshot", func() { + _, err = emitter.MockResource().Write(testing_solo_io_kubernetes.NewMockResource(namespace, "jerry"), clients.WriteOpts{}) + Expect(err).NotTo(HaveOccurred()) + _, err = emitter.FakeResource().Write(testing_solo_io_kubernetes.NewFakeResource(namespace, "jerry"), clients.WriteOpts{}) + Expect(err).NotTo(HaveOccurred()) + _, err = emitter.AnotherMockResource().Write(testing_solo_io_kubernetes.NewAnotherMockResource(namespace, "jerry"), clients.WriteOpts{}) + Expect(err).NotTo(HaveOccurred()) + _, err = emitter.ClusterResource().Write(testing_solo_io_kubernetes.NewClusterResource(namespace, "jerry"), clients.WriteOpts{}) + Expect(err).NotTo(HaveOccurred()) + _, err = emitter.MockCustomType().Write(github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomType(namespace, "jerry"), clients.WriteOpts{}) + Expect(err).NotTo(HaveOccurred()) + _, err = emitter.Pod().Write(github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.NewPod(namespace, "jerry"), clients.WriteOpts{}) + Expect(err).NotTo(HaveOccurred()) + sync := &mockTestingSyncer{} + el := NewTestingEventLoop(emitter, sync) + _, err := el.Run([]string{namespace}, clients.WatchOpts{}) + Expect(err).NotTo(HaveOccurred()) + Eventually(sync.Synced, 5*time.Second).Should(BeTrue()) + }) +}) + +type mockTestingSyncer struct { + synced bool + mutex sync.Mutex +} + +func (s *mockTestingSyncer) Synced() bool { + s.mutex.Lock() + defer s.mutex.Unlock() + return s.synced +} + +func (s *mockTestingSyncer) Sync(ctx context.Context, snap *TestingSnapshot) error { + s.mutex.Lock() + s.synced = true + s.mutex.Unlock() + return nil +} diff --git a/test/mocks/v2alpha1/testing_simple_event_loop.sk.go b/test/mockstwo/group/testing_simple_event_loop.sk.go similarity index 95% rename from test/mocks/v2alpha1/testing_simple_event_loop.sk.go rename to test/mockstwo/group/testing_simple_event_loop.sk.go index ba546366e..1109a3f6a 100644 --- a/test/mocks/v2alpha1/testing_simple_event_loop.sk.go +++ b/test/mockstwo/group/testing_simple_event_loop.sk.go @@ -1,6 +1,6 @@ // Code generated by solo-kit. DO NOT EDIT. -package v2alpha1 +package group import ( "context" @@ -43,7 +43,7 @@ func NewTestingSimpleEventLoop(emitter TestingSimpleEmitter, syncers ...TestingS } func (el *testingSimpleEventLoop) Run(ctx context.Context) (<-chan error, error) { - ctx = contextutils.WithLogger(ctx, "v2alpha1.event_loop") + ctx = contextutils.WithLogger(ctx, "group.event_loop") logger := contextutils.LoggerFrom(ctx) logger.Infof("event loop started") @@ -54,7 +54,7 @@ func (el *testingSimpleEventLoop) Run(ctx context.Context) (<-chan error, error) return nil, errors.Wrapf(err, "starting snapshot watch") } - go errutils.AggregateErrs(ctx, errs, emitterErrs, "v2alpha1.emitter errors") + go errutils.AggregateErrs(ctx, errs, emitterErrs, "group.emitter errors") go func() { // create a new context for each syncer for each loop, cancel each before each loop syncerCancels := make(map[TestingSyncer]context.CancelFunc) diff --git a/test/mockstwo/group/testing_snapshot.sk.go b/test/mockstwo/group/testing_snapshot.sk.go new file mode 100644 index 000000000..cb18c62ae --- /dev/null +++ b/test/mockstwo/group/testing_snapshot.sk.go @@ -0,0 +1,139 @@ +// Code generated by solo-kit. DO NOT EDIT. + +package group + +import ( + "fmt" + + github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes "github.com/solo-io/solo-kit/pkg/api/v1/resources/common/kubernetes" + github_com_solo_io_solo_kit_test_mocks_v1 "github.com/solo-io/solo-kit/test/mocks/v1" + testing_solo_io_kubernetes "github.com/solo-io/solo-kit/test/mocks/v1" + + "github.com/solo-io/go-utils/hashutils" + "go.uber.org/zap" +) + +type TestingSnapshot struct { + Mocks testing_solo_io_kubernetes.MockResourceList + Fakes testing_solo_io_kubernetes.FakeResourceList + Anothermockresources testing_solo_io_kubernetes.AnotherMockResourceList + Clusterresources testing_solo_io_kubernetes.ClusterResourceList + Mcts github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList + Pods github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList +} + +func (s TestingSnapshot) Clone() TestingSnapshot { + return TestingSnapshot{ + Mocks: s.Mocks.Clone(), + Fakes: s.Fakes.Clone(), + Anothermockresources: s.Anothermockresources.Clone(), + Clusterresources: s.Clusterresources.Clone(), + Mcts: s.Mcts.Clone(), + Pods: s.Pods.Clone(), + } +} + +func (s TestingSnapshot) Hash() uint64 { + return hashutils.HashAll( + s.hashMocks(), + s.hashFakes(), + s.hashAnothermockresources(), + s.hashClusterresources(), + s.hashMcts(), + s.hashPods(), + ) +} + +func (s TestingSnapshot) hashMocks() uint64 { + return hashutils.HashAll(s.Mocks.AsInterfaces()...) +} + +func (s TestingSnapshot) hashFakes() uint64 { + return hashutils.HashAll(s.Fakes.AsInterfaces()...) +} + +func (s TestingSnapshot) hashAnothermockresources() uint64 { + return hashutils.HashAll(s.Anothermockresources.AsInterfaces()...) +} + +func (s TestingSnapshot) hashClusterresources() uint64 { + return hashutils.HashAll(s.Clusterresources.AsInterfaces()...) +} + +func (s TestingSnapshot) hashMcts() uint64 { + return hashutils.HashAll(s.Mcts.AsInterfaces()...) +} + +func (s TestingSnapshot) hashPods() uint64 { + return hashutils.HashAll(s.Pods.AsInterfaces()...) +} + +func (s TestingSnapshot) HashFields() []zap.Field { + var fields []zap.Field + fields = append(fields, zap.Uint64("mocks", s.hashMocks())) + fields = append(fields, zap.Uint64("fakes", s.hashFakes())) + fields = append(fields, zap.Uint64("anothermockresources", s.hashAnothermockresources())) + fields = append(fields, zap.Uint64("clusterresources", s.hashClusterresources())) + fields = append(fields, zap.Uint64("mcts", s.hashMcts())) + fields = append(fields, zap.Uint64("pods", s.hashPods())) + + return append(fields, zap.Uint64("snapshotHash", s.Hash())) +} + +type TestingSnapshotStringer struct { + Version uint64 + Mocks []string + Fakes []string + Anothermockresources []string + Clusterresources []string + Mcts []string + Pods []string +} + +func (ss TestingSnapshotStringer) String() string { + s := fmt.Sprintf("TestingSnapshot %v\n", ss.Version) + + s += fmt.Sprintf(" Mocks %v\n", len(ss.Mocks)) + for _, name := range ss.Mocks { + s += fmt.Sprintf(" %v\n", name) + } + + s += fmt.Sprintf(" Fakes %v\n", len(ss.Fakes)) + for _, name := range ss.Fakes { + s += fmt.Sprintf(" %v\n", name) + } + + s += fmt.Sprintf(" Anothermockresources %v\n", len(ss.Anothermockresources)) + for _, name := range ss.Anothermockresources { + s += fmt.Sprintf(" %v\n", name) + } + + s += fmt.Sprintf(" Clusterresources %v\n", len(ss.Clusterresources)) + for _, name := range ss.Clusterresources { + s += fmt.Sprintf(" %v\n", name) + } + + s += fmt.Sprintf(" Mcts %v\n", len(ss.Mcts)) + for _, name := range ss.Mcts { + s += fmt.Sprintf(" %v\n", name) + } + + s += fmt.Sprintf(" Pods %v\n", len(ss.Pods)) + for _, name := range ss.Pods { + s += fmt.Sprintf(" %v\n", name) + } + + return s +} + +func (s TestingSnapshot) Stringer() TestingSnapshotStringer { + return TestingSnapshotStringer{ + Version: s.Hash(), + Mocks: s.Mocks.NamespacesDotNames(), + Fakes: s.Fakes.NamespacesDotNames(), + Anothermockresources: s.Anothermockresources.NamespacesDotNames(), + Clusterresources: s.Clusterresources.Names(), + Mcts: s.Mcts.NamespacesDotNames(), + Pods: s.Pods.NamespacesDotNames(), + } +} diff --git a/test/mockstwo/group/testing_snapshot_emitter.sk.go b/test/mockstwo/group/testing_snapshot_emitter.sk.go new file mode 100644 index 000000000..8279593d9 --- /dev/null +++ b/test/mockstwo/group/testing_snapshot_emitter.sk.go @@ -0,0 +1,465 @@ +// Code generated by solo-kit. DO NOT EDIT. + +package group + +import ( + "sync" + "time" + + github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes "github.com/solo-io/solo-kit/pkg/api/v1/resources/common/kubernetes" + github_com_solo_io_solo_kit_test_mocks_v1 "github.com/solo-io/solo-kit/test/mocks/v1" + testing_solo_io_kubernetes "github.com/solo-io/solo-kit/test/mocks/v1" + + "go.opencensus.io/stats" + "go.opencensus.io/stats/view" + "go.opencensus.io/tag" + + "github.com/solo-io/go-utils/errutils" + "github.com/solo-io/solo-kit/pkg/api/v1/clients" + "github.com/solo-io/solo-kit/pkg/errors" +) + +var ( + mTestingSnapshotIn = stats.Int64("testing.solo.io/snap_emitter/snap_in", "The number of snapshots in", "1") + mTestingSnapshotOut = stats.Int64("testing.solo.io/snap_emitter/snap_out", "The number of snapshots out", "1") + mTestingSnapshotMissed = stats.Int64("testing.solo.io/snap_emitter/snap_missed", "The number of snapshots missed", "1") + + testingsnapshotInView = &view.View{ + Name: "testing.solo.io_snap_emitter/snap_in", + Measure: mTestingSnapshotIn, + Description: "The number of snapshots updates coming in", + Aggregation: view.Count(), + TagKeys: []tag.Key{}, + } + testingsnapshotOutView = &view.View{ + Name: "testing.solo.io/snap_emitter/snap_out", + Measure: mTestingSnapshotOut, + Description: "The number of snapshots updates going out", + Aggregation: view.Count(), + TagKeys: []tag.Key{}, + } + testingsnapshotMissedView = &view.View{ + Name: "testing.solo.io/snap_emitter/snap_missed", + Measure: mTestingSnapshotMissed, + Description: "The number of snapshots updates going missed. this can happen in heavy load. missed snapshot will be re-tried after a second.", + Aggregation: view.Count(), + TagKeys: []tag.Key{}, + } +) + +func init() { + view.Register(testingsnapshotInView, testingsnapshotOutView, testingsnapshotMissedView) +} + +type TestingEmitter interface { + Register() error + MockResource() testing_solo_io_kubernetes.MockResourceClient + FakeResource() testing_solo_io_kubernetes.FakeResourceClient + AnotherMockResource() testing_solo_io_kubernetes.AnotherMockResourceClient + ClusterResource() testing_solo_io_kubernetes.ClusterResourceClient + MockCustomType() github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeClient + Pod() github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodClient + Snapshots(watchNamespaces []string, opts clients.WatchOpts) (<-chan *TestingSnapshot, <-chan error, error) +} + +func NewTestingEmitter(mockResourceClient testing_solo_io_kubernetes.MockResourceClient, fakeResourceClient testing_solo_io_kubernetes.FakeResourceClient, anotherMockResourceClient testing_solo_io_kubernetes.AnotherMockResourceClient, clusterResourceClient testing_solo_io_kubernetes.ClusterResourceClient, mockCustomTypeClient github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeClient, podClient github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodClient) TestingEmitter { + return NewTestingEmitterWithEmit(mockResourceClient, fakeResourceClient, anotherMockResourceClient, clusterResourceClient, mockCustomTypeClient, podClient, make(chan struct{})) +} + +func NewTestingEmitterWithEmit(mockResourceClient testing_solo_io_kubernetes.MockResourceClient, fakeResourceClient testing_solo_io_kubernetes.FakeResourceClient, anotherMockResourceClient testing_solo_io_kubernetes.AnotherMockResourceClient, clusterResourceClient testing_solo_io_kubernetes.ClusterResourceClient, mockCustomTypeClient github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeClient, podClient github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodClient, emit <-chan struct{}) TestingEmitter { + return &testingEmitter{ + mockResource: mockResourceClient, + fakeResource: fakeResourceClient, + anotherMockResource: anotherMockResourceClient, + clusterResource: clusterResourceClient, + mockCustomType: mockCustomTypeClient, + pod: podClient, + forceEmit: emit, + } +} + +type testingEmitter struct { + forceEmit <-chan struct{} + mockResource testing_solo_io_kubernetes.MockResourceClient + fakeResource testing_solo_io_kubernetes.FakeResourceClient + anotherMockResource testing_solo_io_kubernetes.AnotherMockResourceClient + clusterResource testing_solo_io_kubernetes.ClusterResourceClient + mockCustomType github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeClient + pod github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodClient +} + +func (c *testingEmitter) Register() error { + if err := c.mockResource.Register(); err != nil { + return err + } + if err := c.fakeResource.Register(); err != nil { + return err + } + if err := c.anotherMockResource.Register(); err != nil { + return err + } + if err := c.clusterResource.Register(); err != nil { + return err + } + if err := c.mockCustomType.Register(); err != nil { + return err + } + if err := c.pod.Register(); err != nil { + return err + } + return nil +} + +func (c *testingEmitter) MockResource() testing_solo_io_kubernetes.MockResourceClient { + return c.mockResource +} + +func (c *testingEmitter) FakeResource() testing_solo_io_kubernetes.FakeResourceClient { + return c.fakeResource +} + +func (c *testingEmitter) AnotherMockResource() testing_solo_io_kubernetes.AnotherMockResourceClient { + return c.anotherMockResource +} + +func (c *testingEmitter) ClusterResource() testing_solo_io_kubernetes.ClusterResourceClient { + return c.clusterResource +} + +func (c *testingEmitter) MockCustomType() github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeClient { + return c.mockCustomType +} + +func (c *testingEmitter) Pod() github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodClient { + return c.pod +} + +func (c *testingEmitter) Snapshots(watchNamespaces []string, opts clients.WatchOpts) (<-chan *TestingSnapshot, <-chan error, error) { + + if len(watchNamespaces) == 0 { + watchNamespaces = []string{""} + } + + for _, ns := range watchNamespaces { + if ns == "" && len(watchNamespaces) > 1 { + return nil, nil, errors.Errorf("the \"\" namespace is used to watch all namespaces. Snapshots can either be tracked for " + + "specific namespaces or \"\" AllNamespaces, but not both.") + } + } + + errs := make(chan error) + var done sync.WaitGroup + ctx := opts.Ctx + /* Create channel for MockResource */ + type mockResourceListWithNamespace struct { + list testing_solo_io_kubernetes.MockResourceList + namespace string + } + mockResourceChan := make(chan mockResourceListWithNamespace) + + var initialMockResourceList testing_solo_io_kubernetes.MockResourceList + /* Create channel for FakeResource */ + type fakeResourceListWithNamespace struct { + list testing_solo_io_kubernetes.FakeResourceList + namespace string + } + fakeResourceChan := make(chan fakeResourceListWithNamespace) + + var initialFakeResourceList testing_solo_io_kubernetes.FakeResourceList + /* Create channel for AnotherMockResource */ + type anotherMockResourceListWithNamespace struct { + list testing_solo_io_kubernetes.AnotherMockResourceList + namespace string + } + anotherMockResourceChan := make(chan anotherMockResourceListWithNamespace) + + var initialAnotherMockResourceList testing_solo_io_kubernetes.AnotherMockResourceList + /* Create channel for ClusterResource */ + /* Create channel for MockCustomType */ + type mockCustomTypeListWithNamespace struct { + list github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList + namespace string + } + mockCustomTypeChan := make(chan mockCustomTypeListWithNamespace) + + var initialMockCustomTypeList github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList + /* Create channel for Pod */ + type podListWithNamespace struct { + list github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList + namespace string + } + podChan := make(chan podListWithNamespace) + + var initialPodList github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList + + currentSnapshot := TestingSnapshot{} + + for _, namespace := range watchNamespaces { + /* Setup namespaced watch for MockResource */ + { + mocks, err := c.mockResource.List(namespace, clients.ListOpts{Ctx: opts.Ctx, Selector: opts.Selector}) + if err != nil { + return nil, nil, errors.Wrapf(err, "initial MockResource list") + } + initialMockResourceList = append(initialMockResourceList, mocks...) + } + mockResourceNamespacesChan, mockResourceErrs, err := c.mockResource.Watch(namespace, opts) + if err != nil { + return nil, nil, errors.Wrapf(err, "starting MockResource watch") + } + + done.Add(1) + go func(namespace string) { + defer done.Done() + errutils.AggregateErrs(ctx, errs, mockResourceErrs, namespace+"-mocks") + }(namespace) + /* Setup namespaced watch for FakeResource */ + { + fakes, err := c.fakeResource.List(namespace, clients.ListOpts{Ctx: opts.Ctx, Selector: opts.Selector}) + if err != nil { + return nil, nil, errors.Wrapf(err, "initial FakeResource list") + } + initialFakeResourceList = append(initialFakeResourceList, fakes...) + } + fakeResourceNamespacesChan, fakeResourceErrs, err := c.fakeResource.Watch(namespace, opts) + if err != nil { + return nil, nil, errors.Wrapf(err, "starting FakeResource watch") + } + + done.Add(1) + go func(namespace string) { + defer done.Done() + errutils.AggregateErrs(ctx, errs, fakeResourceErrs, namespace+"-fakes") + }(namespace) + /* Setup namespaced watch for AnotherMockResource */ + { + anothermockresources, err := c.anotherMockResource.List(namespace, clients.ListOpts{Ctx: opts.Ctx, Selector: opts.Selector}) + if err != nil { + return nil, nil, errors.Wrapf(err, "initial AnotherMockResource list") + } + initialAnotherMockResourceList = append(initialAnotherMockResourceList, anothermockresources...) + } + anotherMockResourceNamespacesChan, anotherMockResourceErrs, err := c.anotherMockResource.Watch(namespace, opts) + if err != nil { + return nil, nil, errors.Wrapf(err, "starting AnotherMockResource watch") + } + + done.Add(1) + go func(namespace string) { + defer done.Done() + errutils.AggregateErrs(ctx, errs, anotherMockResourceErrs, namespace+"-anothermockresources") + }(namespace) + /* Setup namespaced watch for MockCustomType */ + { + mcts, err := c.mockCustomType.List(namespace, clients.ListOpts{Ctx: opts.Ctx, Selector: opts.Selector}) + if err != nil { + return nil, nil, errors.Wrapf(err, "initial MockCustomType list") + } + initialMockCustomTypeList = append(initialMockCustomTypeList, mcts...) + } + mockCustomTypeNamespacesChan, mockCustomTypeErrs, err := c.mockCustomType.Watch(namespace, opts) + if err != nil { + return nil, nil, errors.Wrapf(err, "starting MockCustomType watch") + } + + done.Add(1) + go func(namespace string) { + defer done.Done() + errutils.AggregateErrs(ctx, errs, mockCustomTypeErrs, namespace+"-mcts") + }(namespace) + /* Setup namespaced watch for Pod */ + { + pods, err := c.pod.List(namespace, clients.ListOpts{Ctx: opts.Ctx, Selector: opts.Selector}) + if err != nil { + return nil, nil, errors.Wrapf(err, "initial Pod list") + } + initialPodList = append(initialPodList, pods...) + } + podNamespacesChan, podErrs, err := c.pod.Watch(namespace, opts) + if err != nil { + return nil, nil, errors.Wrapf(err, "starting Pod watch") + } + + done.Add(1) + go func(namespace string) { + defer done.Done() + errutils.AggregateErrs(ctx, errs, podErrs, namespace+"-pods") + }(namespace) + + /* Watch for changes and update snapshot */ + go func(namespace string) { + for { + select { + case <-ctx.Done(): + return + case mockResourceList := <-mockResourceNamespacesChan: + select { + case <-ctx.Done(): + return + case mockResourceChan <- mockResourceListWithNamespace{list: mockResourceList, namespace: namespace}: + } + case fakeResourceList := <-fakeResourceNamespacesChan: + select { + case <-ctx.Done(): + return + case fakeResourceChan <- fakeResourceListWithNamespace{list: fakeResourceList, namespace: namespace}: + } + case anotherMockResourceList := <-anotherMockResourceNamespacesChan: + select { + case <-ctx.Done(): + return + case anotherMockResourceChan <- anotherMockResourceListWithNamespace{list: anotherMockResourceList, namespace: namespace}: + } + case mockCustomTypeList := <-mockCustomTypeNamespacesChan: + select { + case <-ctx.Done(): + return + case mockCustomTypeChan <- mockCustomTypeListWithNamespace{list: mockCustomTypeList, namespace: namespace}: + } + case podList := <-podNamespacesChan: + select { + case <-ctx.Done(): + return + case podChan <- podListWithNamespace{list: podList, namespace: namespace}: + } + } + } + }(namespace) + } + /* Initialize snapshot for Mocks */ + currentSnapshot.Mocks = initialMockResourceList.Sort() + /* Initialize snapshot for Fakes */ + currentSnapshot.Fakes = initialFakeResourceList.Sort() + /* Initialize snapshot for Anothermockresources */ + currentSnapshot.Anothermockresources = initialAnotherMockResourceList.Sort() + /* Setup cluster-wide watch for ClusterResource */ + var err error + currentSnapshot.Clusterresources, err = c.clusterResource.List(clients.ListOpts{Ctx: opts.Ctx, Selector: opts.Selector}) + if err != nil { + return nil, nil, errors.Wrapf(err, "initial ClusterResource list") + } + clusterResourceChan, clusterResourceErrs, err := c.clusterResource.Watch(opts) + if err != nil { + return nil, nil, errors.Wrapf(err, "starting ClusterResource watch") + } + done.Add(1) + go func() { + defer done.Done() + errutils.AggregateErrs(ctx, errs, clusterResourceErrs, "clusterresources") + }() + /* Initialize snapshot for Mcts */ + currentSnapshot.Mcts = initialMockCustomTypeList.Sort() + /* Initialize snapshot for Pods */ + currentSnapshot.Pods = initialPodList.Sort() + + snapshots := make(chan *TestingSnapshot) + go func() { + // sent initial snapshot to kick off the watch + initialSnapshot := currentSnapshot.Clone() + snapshots <- &initialSnapshot + + originalSnapshot := TestingSnapshot{} + timer := time.NewTicker(time.Second * 1) + + sync := func() { + if originalSnapshot.Hash() == currentSnapshot.Hash() { + return + } + + sentSnapshot := currentSnapshot.Clone() + select { + case snapshots <- &sentSnapshot: + stats.Record(ctx, mTestingSnapshotOut.M(1)) + originalSnapshot = currentSnapshot.Clone() + default: + stats.Record(ctx, mTestingSnapshotMissed.M(1)) + } + } + mocksByNamespace := make(map[string]testing_solo_io_kubernetes.MockResourceList) + fakesByNamespace := make(map[string]testing_solo_io_kubernetes.FakeResourceList) + anothermockresourcesByNamespace := make(map[string]testing_solo_io_kubernetes.AnotherMockResourceList) + mctsByNamespace := make(map[string]github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList) + podsByNamespace := make(map[string]github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList) + + for { + record := func() { stats.Record(ctx, mTestingSnapshotIn.M(1)) } + + select { + case <-timer.C: + sync() + case <-ctx.Done(): + close(snapshots) + done.Wait() + close(errs) + return + case <-c.forceEmit: + sentSnapshot := currentSnapshot.Clone() + snapshots <- &sentSnapshot + case mockResourceNamespacedList := <-mockResourceChan: + record() + + namespace := mockResourceNamespacedList.namespace + + // merge lists by namespace + mocksByNamespace[namespace] = mockResourceNamespacedList.list + var mockResourceList testing_solo_io_kubernetes.MockResourceList + for _, mocks := range mocksByNamespace { + mockResourceList = append(mockResourceList, mocks...) + } + currentSnapshot.Mocks = mockResourceList.Sort() + case fakeResourceNamespacedList := <-fakeResourceChan: + record() + + namespace := fakeResourceNamespacedList.namespace + + // merge lists by namespace + fakesByNamespace[namespace] = fakeResourceNamespacedList.list + var fakeResourceList testing_solo_io_kubernetes.FakeResourceList + for _, fakes := range fakesByNamespace { + fakeResourceList = append(fakeResourceList, fakes...) + } + currentSnapshot.Fakes = fakeResourceList.Sort() + case anotherMockResourceNamespacedList := <-anotherMockResourceChan: + record() + + namespace := anotherMockResourceNamespacedList.namespace + + // merge lists by namespace + anothermockresourcesByNamespace[namespace] = anotherMockResourceNamespacedList.list + var anotherMockResourceList testing_solo_io_kubernetes.AnotherMockResourceList + for _, anothermockresources := range anothermockresourcesByNamespace { + anotherMockResourceList = append(anotherMockResourceList, anothermockresources...) + } + currentSnapshot.Anothermockresources = anotherMockResourceList.Sort() + case clusterResourceList := <-clusterResourceChan: + record() + currentSnapshot.Clusterresources = clusterResourceList + case mockCustomTypeNamespacedList := <-mockCustomTypeChan: + record() + + namespace := mockCustomTypeNamespacedList.namespace + + // merge lists by namespace + mctsByNamespace[namespace] = mockCustomTypeNamespacedList.list + var mockCustomTypeList github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList + for _, mcts := range mctsByNamespace { + mockCustomTypeList = append(mockCustomTypeList, mcts...) + } + currentSnapshot.Mcts = mockCustomTypeList.Sort() + case podNamespacedList := <-podChan: + record() + + namespace := podNamespacedList.namespace + + // merge lists by namespace + podsByNamespace[namespace] = podNamespacedList.list + var podList github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList + for _, pods := range podsByNamespace { + podList = append(podList, pods...) + } + currentSnapshot.Pods = podList.Sort() + } + } + }() + return snapshots, errs, nil +} diff --git a/test/mockstwo/group/testing_snapshot_emitter_test.go b/test/mockstwo/group/testing_snapshot_emitter_test.go new file mode 100644 index 000000000..671be4850 --- /dev/null +++ b/test/mockstwo/group/testing_snapshot_emitter_test.go @@ -0,0 +1,811 @@ +// Code generated by solo-kit. DO NOT EDIT. + +// +build solokit + +package group + +import ( + "context" + "os" + "time" + + github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes "github.com/solo-io/solo-kit/pkg/api/v1/resources/common/kubernetes" + github_com_solo_io_solo_kit_test_mocks_v1 "github.com/solo-io/solo-kit/test/mocks/v1" + testing_solo_io_kubernetes "github.com/solo-io/solo-kit/test/mocks/v1" + + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" + "github.com/solo-io/go-utils/kubeutils" + "github.com/solo-io/go-utils/log" + "github.com/solo-io/solo-kit/pkg/api/v1/clients" + "github.com/solo-io/solo-kit/pkg/api/v1/clients/factory" + kuberc "github.com/solo-io/solo-kit/pkg/api/v1/clients/kube" + "github.com/solo-io/solo-kit/pkg/api/v1/clients/memory" + "github.com/solo-io/solo-kit/test/helpers" + "k8s.io/client-go/kubernetes" + "k8s.io/client-go/rest" + + // Needed to run tests in GKE + _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" + + // From https://github.com/kubernetes/client-go/blob/53c7adfd0294caa142d961e1f780f74081d5b15f/examples/out-of-cluster-client-configuration/main.go#L31 + _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" +) + +var _ = Describe("GroupEmitter", func() { + if os.Getenv("RUN_KUBE_TESTS") != "1" { + log.Printf("This test creates kubernetes resources and is disabled by default. To enable, set RUN_KUBE_TESTS=1 in your env.") + return + } + var ( + namespace1 string + namespace2 string + name1, name2 = "angela" + helpers.RandString(3), "bob" + helpers.RandString(3) + cfg *rest.Config + kube kubernetes.Interface + emitter TestingEmitter + mockResourceClient testing_solo_io_kubernetes.MockResourceClient + fakeResourceClient testing_solo_io_kubernetes.FakeResourceClient + anotherMockResourceClient testing_solo_io_kubernetes.AnotherMockResourceClient + clusterResourceClient testing_solo_io_kubernetes.ClusterResourceClient + mockCustomTypeClient github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeClient + podClient github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodClient + ) + + BeforeEach(func() { + namespace1 = helpers.RandString(8) + namespace2 = helpers.RandString(8) + kube = helpers.MustKubeClient() + err := kubeutils.CreateNamespacesInParallel(kube, namespace1, namespace2) + Expect(err).NotTo(HaveOccurred()) + cfg, err = kubeutils.GetConfig("", "") + Expect(err).NotTo(HaveOccurred()) + // MockResource Constructor + mockResourceClientFactory := &factory.KubeResourceClientFactory{ + Crd: testing_solo_io_kubernetes.MockResourceCrd, + Cfg: cfg, + SharedCache: kuberc.NewKubeCache(context.TODO()), + } + + mockResourceClient, err = testing_solo_io_kubernetes.NewMockResourceClient(mockResourceClientFactory) + Expect(err).NotTo(HaveOccurred()) + // FakeResource Constructor + fakeResourceClientFactory := &factory.KubeResourceClientFactory{ + Crd: testing_solo_io_kubernetes.FakeResourceCrd, + Cfg: cfg, + SharedCache: kuberc.NewKubeCache(context.TODO()), + } + + fakeResourceClient, err = testing_solo_io_kubernetes.NewFakeResourceClient(fakeResourceClientFactory) + Expect(err).NotTo(HaveOccurred()) + // AnotherMockResource Constructor + anotherMockResourceClientFactory := &factory.KubeResourceClientFactory{ + Crd: testing_solo_io_kubernetes.AnotherMockResourceCrd, + Cfg: cfg, + SharedCache: kuberc.NewKubeCache(context.TODO()), + } + + anotherMockResourceClient, err = testing_solo_io_kubernetes.NewAnotherMockResourceClient(anotherMockResourceClientFactory) + Expect(err).NotTo(HaveOccurred()) + // ClusterResource Constructor + clusterResourceClientFactory := &factory.KubeResourceClientFactory{ + Crd: testing_solo_io_kubernetes.ClusterResourceCrd, + Cfg: cfg, + SharedCache: kuberc.NewKubeCache(context.TODO()), + } + + clusterResourceClient, err = testing_solo_io_kubernetes.NewClusterResourceClient(clusterResourceClientFactory) + Expect(err).NotTo(HaveOccurred()) + // MockCustomType Constructor + mockCustomTypeClientFactory := &factory.MemoryResourceClientFactory{ + Cache: memory.NewInMemoryResourceCache(), + } + + mockCustomTypeClient, err = github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomTypeClient(mockCustomTypeClientFactory) + Expect(err).NotTo(HaveOccurred()) + // Pod Constructor + podClientFactory := &factory.MemoryResourceClientFactory{ + Cache: memory.NewInMemoryResourceCache(), + } + + podClient, err = github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.NewPodClient(podClientFactory) + Expect(err).NotTo(HaveOccurred()) + emitter = NewTestingEmitter(mockResourceClient, fakeResourceClient, anotherMockResourceClient, clusterResourceClient, mockCustomTypeClient, podClient) + }) + AfterEach(func() { + err := kubeutils.DeleteNamespacesInParallelBlocking(kube, namespace1, namespace2) + Expect(err).NotTo(HaveOccurred()) + clusterResourceClient.Delete(name1, clients.DeleteOpts{}) + clusterResourceClient.Delete(name2, clients.DeleteOpts{}) + }) + It("tracks snapshots on changes to any resource", func() { + ctx := context.Background() + err := emitter.Register() + Expect(err).NotTo(HaveOccurred()) + + snapshots, errs, err := emitter.Snapshots([]string{namespace1, namespace2}, clients.WatchOpts{ + Ctx: ctx, + RefreshRate: time.Second, + }) + Expect(err).NotTo(HaveOccurred()) + + var snap *TestingSnapshot + + /* + MockResource + */ + + assertSnapshotMocks := func(expectMocks testing_solo_io_kubernetes.MockResourceList, unexpectMocks testing_solo_io_kubernetes.MockResourceList) { + drain: + for { + select { + case snap = <-snapshots: + for _, expected := range expectMocks { + if _, err := snap.Mocks.Find(expected.GetMetadata().Ref().Strings()); err != nil { + continue drain + } + } + for _, unexpected := range unexpectMocks { + if _, err := snap.Mocks.Find(unexpected.GetMetadata().Ref().Strings()); err == nil { + continue drain + } + } + break drain + case err := <-errs: + Expect(err).NotTo(HaveOccurred()) + case <-time.After(time.Second * 10): + nsList1, _ := mockResourceClient.List(namespace1, clients.ListOpts{}) + nsList2, _ := mockResourceClient.List(namespace2, clients.ListOpts{}) + combined := append(nsList1, nsList2...) + Fail("expected final snapshot before 10 seconds. expected " + log.Sprintf("%v", combined)) + } + } + } + mockResource1a, err := mockResourceClient.Write(testing_solo_io_kubernetes.NewMockResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + mockResource1b, err := mockResourceClient.Write(testing_solo_io_kubernetes.NewMockResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotMocks(testing_solo_io_kubernetes.MockResourceList{mockResource1a, mockResource1b}, nil) + mockResource2a, err := mockResourceClient.Write(testing_solo_io_kubernetes.NewMockResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + mockResource2b, err := mockResourceClient.Write(testing_solo_io_kubernetes.NewMockResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotMocks(testing_solo_io_kubernetes.MockResourceList{mockResource1a, mockResource1b, mockResource2a, mockResource2b}, nil) + + err = mockResourceClient.Delete(mockResource2a.GetMetadata().Namespace, mockResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + err = mockResourceClient.Delete(mockResource2b.GetMetadata().Namespace, mockResource2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotMocks(testing_solo_io_kubernetes.MockResourceList{mockResource1a, mockResource1b}, testing_solo_io_kubernetes.MockResourceList{mockResource2a, mockResource2b}) + + err = mockResourceClient.Delete(mockResource1a.GetMetadata().Namespace, mockResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + err = mockResourceClient.Delete(mockResource1b.GetMetadata().Namespace, mockResource1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotMocks(nil, testing_solo_io_kubernetes.MockResourceList{mockResource1a, mockResource1b, mockResource2a, mockResource2b}) + + /* + FakeResource + */ + + assertSnapshotFakes := func(expectFakes testing_solo_io_kubernetes.FakeResourceList, unexpectFakes testing_solo_io_kubernetes.FakeResourceList) { + drain: + for { + select { + case snap = <-snapshots: + for _, expected := range expectFakes { + if _, err := snap.Fakes.Find(expected.GetMetadata().Ref().Strings()); err != nil { + continue drain + } + } + for _, unexpected := range unexpectFakes { + if _, err := snap.Fakes.Find(unexpected.GetMetadata().Ref().Strings()); err == nil { + continue drain + } + } + break drain + case err := <-errs: + Expect(err).NotTo(HaveOccurred()) + case <-time.After(time.Second * 10): + nsList1, _ := fakeResourceClient.List(namespace1, clients.ListOpts{}) + nsList2, _ := fakeResourceClient.List(namespace2, clients.ListOpts{}) + combined := append(nsList1, nsList2...) + Fail("expected final snapshot before 10 seconds. expected " + log.Sprintf("%v", combined)) + } + } + } + fakeResource1a, err := fakeResourceClient.Write(testing_solo_io_kubernetes.NewFakeResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + fakeResource1b, err := fakeResourceClient.Write(testing_solo_io_kubernetes.NewFakeResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotFakes(testing_solo_io_kubernetes.FakeResourceList{fakeResource1a, fakeResource1b}, nil) + fakeResource2a, err := fakeResourceClient.Write(testing_solo_io_kubernetes.NewFakeResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + fakeResource2b, err := fakeResourceClient.Write(testing_solo_io_kubernetes.NewFakeResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotFakes(testing_solo_io_kubernetes.FakeResourceList{fakeResource1a, fakeResource1b, fakeResource2a, fakeResource2b}, nil) + + err = fakeResourceClient.Delete(fakeResource2a.GetMetadata().Namespace, fakeResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + err = fakeResourceClient.Delete(fakeResource2b.GetMetadata().Namespace, fakeResource2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotFakes(testing_solo_io_kubernetes.FakeResourceList{fakeResource1a, fakeResource1b}, testing_solo_io_kubernetes.FakeResourceList{fakeResource2a, fakeResource2b}) + + err = fakeResourceClient.Delete(fakeResource1a.GetMetadata().Namespace, fakeResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + err = fakeResourceClient.Delete(fakeResource1b.GetMetadata().Namespace, fakeResource1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotFakes(nil, testing_solo_io_kubernetes.FakeResourceList{fakeResource1a, fakeResource1b, fakeResource2a, fakeResource2b}) + + /* + AnotherMockResource + */ + + assertSnapshotAnothermockresources := func(expectAnothermockresources testing_solo_io_kubernetes.AnotherMockResourceList, unexpectAnothermockresources testing_solo_io_kubernetes.AnotherMockResourceList) { + drain: + for { + select { + case snap = <-snapshots: + for _, expected := range expectAnothermockresources { + if _, err := snap.Anothermockresources.Find(expected.GetMetadata().Ref().Strings()); err != nil { + continue drain + } + } + for _, unexpected := range unexpectAnothermockresources { + if _, err := snap.Anothermockresources.Find(unexpected.GetMetadata().Ref().Strings()); err == nil { + continue drain + } + } + break drain + case err := <-errs: + Expect(err).NotTo(HaveOccurred()) + case <-time.After(time.Second * 10): + nsList1, _ := anotherMockResourceClient.List(namespace1, clients.ListOpts{}) + nsList2, _ := anotherMockResourceClient.List(namespace2, clients.ListOpts{}) + combined := append(nsList1, nsList2...) + Fail("expected final snapshot before 10 seconds. expected " + log.Sprintf("%v", combined)) + } + } + } + anotherMockResource1a, err := anotherMockResourceClient.Write(testing_solo_io_kubernetes.NewAnotherMockResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + anotherMockResource1b, err := anotherMockResourceClient.Write(testing_solo_io_kubernetes.NewAnotherMockResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotAnothermockresources(testing_solo_io_kubernetes.AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b}, nil) + anotherMockResource2a, err := anotherMockResourceClient.Write(testing_solo_io_kubernetes.NewAnotherMockResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + anotherMockResource2b, err := anotherMockResourceClient.Write(testing_solo_io_kubernetes.NewAnotherMockResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotAnothermockresources(testing_solo_io_kubernetes.AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b, anotherMockResource2a, anotherMockResource2b}, nil) + + err = anotherMockResourceClient.Delete(anotherMockResource2a.GetMetadata().Namespace, anotherMockResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + err = anotherMockResourceClient.Delete(anotherMockResource2b.GetMetadata().Namespace, anotherMockResource2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotAnothermockresources(testing_solo_io_kubernetes.AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b}, testing_solo_io_kubernetes.AnotherMockResourceList{anotherMockResource2a, anotherMockResource2b}) + + err = anotherMockResourceClient.Delete(anotherMockResource1a.GetMetadata().Namespace, anotherMockResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + err = anotherMockResourceClient.Delete(anotherMockResource1b.GetMetadata().Namespace, anotherMockResource1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotAnothermockresources(nil, testing_solo_io_kubernetes.AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b, anotherMockResource2a, anotherMockResource2b}) + + /* + ClusterResource + */ + + assertSnapshotClusterresources := func(expectClusterresources testing_solo_io_kubernetes.ClusterResourceList, unexpectClusterresources testing_solo_io_kubernetes.ClusterResourceList) { + drain: + for { + select { + case snap = <-snapshots: + for _, expected := range expectClusterresources { + if _, err := snap.Clusterresources.Find(expected.GetMetadata().Ref().Strings()); err != nil { + continue drain + } + } + for _, unexpected := range unexpectClusterresources { + if _, err := snap.Clusterresources.Find(unexpected.GetMetadata().Ref().Strings()); err == nil { + continue drain + } + } + break drain + case err := <-errs: + Expect(err).NotTo(HaveOccurred()) + case <-time.After(time.Second * 10): + combined, _ := clusterResourceClient.List(clients.ListOpts{}) + Fail("expected final snapshot before 10 seconds. expected " + log.Sprintf("%v", combined)) + } + } + } + clusterResource1a, err := clusterResourceClient.Write(testing_solo_io_kubernetes.NewClusterResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotClusterresources(testing_solo_io_kubernetes.ClusterResourceList{clusterResource1a}, nil) + clusterResource2a, err := clusterResourceClient.Write(testing_solo_io_kubernetes.NewClusterResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotClusterresources(testing_solo_io_kubernetes.ClusterResourceList{clusterResource1a, clusterResource2a}, nil) + + err = clusterResourceClient.Delete(clusterResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotClusterresources(testing_solo_io_kubernetes.ClusterResourceList{clusterResource1a}, testing_solo_io_kubernetes.ClusterResourceList{clusterResource2a}) + + err = clusterResourceClient.Delete(clusterResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotClusterresources(nil, testing_solo_io_kubernetes.ClusterResourceList{clusterResource1a, clusterResource2a}) + + /* + MockCustomType + */ + + assertSnapshotmcts := func(expectmcts github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList, unexpectmcts github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList) { + drain: + for { + select { + case snap = <-snapshots: + for _, expected := range expectmcts { + if _, err := snap.Mcts.Find(expected.GetMetadata().Ref().Strings()); err != nil { + continue drain + } + } + for _, unexpected := range unexpectmcts { + if _, err := snap.Mcts.Find(unexpected.GetMetadata().Ref().Strings()); err == nil { + continue drain + } + } + break drain + case err := <-errs: + Expect(err).NotTo(HaveOccurred()) + case <-time.After(time.Second * 10): + nsList1, _ := mockCustomTypeClient.List(namespace1, clients.ListOpts{}) + nsList2, _ := mockCustomTypeClient.List(namespace2, clients.ListOpts{}) + combined := append(nsList1, nsList2...) + Fail("expected final snapshot before 10 seconds. expected " + log.Sprintf("%v", combined)) + } + } + } + mockCustomType1a, err := mockCustomTypeClient.Write(github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomType(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + mockCustomType1b, err := mockCustomTypeClient.Write(github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomType(namespace2, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotmcts(github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList{mockCustomType1a, mockCustomType1b}, nil) + mockCustomType2a, err := mockCustomTypeClient.Write(github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomType(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + mockCustomType2b, err := mockCustomTypeClient.Write(github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomType(namespace2, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotmcts(github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList{mockCustomType1a, mockCustomType1b, mockCustomType2a, mockCustomType2b}, nil) + + err = mockCustomTypeClient.Delete(mockCustomType2a.GetMetadata().Namespace, mockCustomType2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + err = mockCustomTypeClient.Delete(mockCustomType2b.GetMetadata().Namespace, mockCustomType2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotmcts(github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList{mockCustomType1a, mockCustomType1b}, github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList{mockCustomType2a, mockCustomType2b}) + + err = mockCustomTypeClient.Delete(mockCustomType1a.GetMetadata().Namespace, mockCustomType1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + err = mockCustomTypeClient.Delete(mockCustomType1b.GetMetadata().Namespace, mockCustomType1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotmcts(nil, github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList{mockCustomType1a, mockCustomType1b, mockCustomType2a, mockCustomType2b}) + + /* + Pod + */ + + assertSnapshotpods := func(expectpods github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList, unexpectpods github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList) { + drain: + for { + select { + case snap = <-snapshots: + for _, expected := range expectpods { + if _, err := snap.Pods.Find(expected.GetMetadata().Ref().Strings()); err != nil { + continue drain + } + } + for _, unexpected := range unexpectpods { + if _, err := snap.Pods.Find(unexpected.GetMetadata().Ref().Strings()); err == nil { + continue drain + } + } + break drain + case err := <-errs: + Expect(err).NotTo(HaveOccurred()) + case <-time.After(time.Second * 10): + nsList1, _ := podClient.List(namespace1, clients.ListOpts{}) + nsList2, _ := podClient.List(namespace2, clients.ListOpts{}) + combined := append(nsList1, nsList2...) + Fail("expected final snapshot before 10 seconds. expected " + log.Sprintf("%v", combined)) + } + } + } + pod1a, err := podClient.Write(github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.NewPod(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + pod1b, err := podClient.Write(github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.NewPod(namespace2, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotpods(github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList{pod1a, pod1b}, nil) + pod2a, err := podClient.Write(github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.NewPod(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + pod2b, err := podClient.Write(github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.NewPod(namespace2, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotpods(github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList{pod1a, pod1b, pod2a, pod2b}, nil) + + err = podClient.Delete(pod2a.GetMetadata().Namespace, pod2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + err = podClient.Delete(pod2b.GetMetadata().Namespace, pod2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotpods(github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList{pod1a, pod1b}, github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList{pod2a, pod2b}) + + err = podClient.Delete(pod1a.GetMetadata().Namespace, pod1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + err = podClient.Delete(pod1b.GetMetadata().Namespace, pod1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotpods(nil, github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList{pod1a, pod1b, pod2a, pod2b}) + }) + It("tracks snapshots on changes to any resource using AllNamespace", func() { + ctx := context.Background() + err := emitter.Register() + Expect(err).NotTo(HaveOccurred()) + + snapshots, errs, err := emitter.Snapshots([]string{""}, clients.WatchOpts{ + Ctx: ctx, + RefreshRate: time.Second, + }) + Expect(err).NotTo(HaveOccurred()) + + var snap *TestingSnapshot + + /* + MockResource + */ + + assertSnapshotMocks := func(expectMocks testing_solo_io_kubernetes.MockResourceList, unexpectMocks testing_solo_io_kubernetes.MockResourceList) { + drain: + for { + select { + case snap = <-snapshots: + for _, expected := range expectMocks { + if _, err := snap.Mocks.Find(expected.GetMetadata().Ref().Strings()); err != nil { + continue drain + } + } + for _, unexpected := range unexpectMocks { + if _, err := snap.Mocks.Find(unexpected.GetMetadata().Ref().Strings()); err == nil { + continue drain + } + } + break drain + case err := <-errs: + Expect(err).NotTo(HaveOccurred()) + case <-time.After(time.Second * 10): + nsList1, _ := mockResourceClient.List(namespace1, clients.ListOpts{}) + nsList2, _ := mockResourceClient.List(namespace2, clients.ListOpts{}) + combined := append(nsList1, nsList2...) + Fail("expected final snapshot before 10 seconds. expected " + log.Sprintf("%v", combined)) + } + } + } + mockResource1a, err := mockResourceClient.Write(testing_solo_io_kubernetes.NewMockResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + mockResource1b, err := mockResourceClient.Write(testing_solo_io_kubernetes.NewMockResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotMocks(testing_solo_io_kubernetes.MockResourceList{mockResource1a, mockResource1b}, nil) + mockResource2a, err := mockResourceClient.Write(testing_solo_io_kubernetes.NewMockResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + mockResource2b, err := mockResourceClient.Write(testing_solo_io_kubernetes.NewMockResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotMocks(testing_solo_io_kubernetes.MockResourceList{mockResource1a, mockResource1b, mockResource2a, mockResource2b}, nil) + + err = mockResourceClient.Delete(mockResource2a.GetMetadata().Namespace, mockResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + err = mockResourceClient.Delete(mockResource2b.GetMetadata().Namespace, mockResource2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotMocks(testing_solo_io_kubernetes.MockResourceList{mockResource1a, mockResource1b}, testing_solo_io_kubernetes.MockResourceList{mockResource2a, mockResource2b}) + + err = mockResourceClient.Delete(mockResource1a.GetMetadata().Namespace, mockResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + err = mockResourceClient.Delete(mockResource1b.GetMetadata().Namespace, mockResource1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotMocks(nil, testing_solo_io_kubernetes.MockResourceList{mockResource1a, mockResource1b, mockResource2a, mockResource2b}) + + /* + FakeResource + */ + + assertSnapshotFakes := func(expectFakes testing_solo_io_kubernetes.FakeResourceList, unexpectFakes testing_solo_io_kubernetes.FakeResourceList) { + drain: + for { + select { + case snap = <-snapshots: + for _, expected := range expectFakes { + if _, err := snap.Fakes.Find(expected.GetMetadata().Ref().Strings()); err != nil { + continue drain + } + } + for _, unexpected := range unexpectFakes { + if _, err := snap.Fakes.Find(unexpected.GetMetadata().Ref().Strings()); err == nil { + continue drain + } + } + break drain + case err := <-errs: + Expect(err).NotTo(HaveOccurred()) + case <-time.After(time.Second * 10): + nsList1, _ := fakeResourceClient.List(namespace1, clients.ListOpts{}) + nsList2, _ := fakeResourceClient.List(namespace2, clients.ListOpts{}) + combined := append(nsList1, nsList2...) + Fail("expected final snapshot before 10 seconds. expected " + log.Sprintf("%v", combined)) + } + } + } + fakeResource1a, err := fakeResourceClient.Write(testing_solo_io_kubernetes.NewFakeResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + fakeResource1b, err := fakeResourceClient.Write(testing_solo_io_kubernetes.NewFakeResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotFakes(testing_solo_io_kubernetes.FakeResourceList{fakeResource1a, fakeResource1b}, nil) + fakeResource2a, err := fakeResourceClient.Write(testing_solo_io_kubernetes.NewFakeResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + fakeResource2b, err := fakeResourceClient.Write(testing_solo_io_kubernetes.NewFakeResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotFakes(testing_solo_io_kubernetes.FakeResourceList{fakeResource1a, fakeResource1b, fakeResource2a, fakeResource2b}, nil) + + err = fakeResourceClient.Delete(fakeResource2a.GetMetadata().Namespace, fakeResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + err = fakeResourceClient.Delete(fakeResource2b.GetMetadata().Namespace, fakeResource2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotFakes(testing_solo_io_kubernetes.FakeResourceList{fakeResource1a, fakeResource1b}, testing_solo_io_kubernetes.FakeResourceList{fakeResource2a, fakeResource2b}) + + err = fakeResourceClient.Delete(fakeResource1a.GetMetadata().Namespace, fakeResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + err = fakeResourceClient.Delete(fakeResource1b.GetMetadata().Namespace, fakeResource1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotFakes(nil, testing_solo_io_kubernetes.FakeResourceList{fakeResource1a, fakeResource1b, fakeResource2a, fakeResource2b}) + + /* + AnotherMockResource + */ + + assertSnapshotAnothermockresources := func(expectAnothermockresources testing_solo_io_kubernetes.AnotherMockResourceList, unexpectAnothermockresources testing_solo_io_kubernetes.AnotherMockResourceList) { + drain: + for { + select { + case snap = <-snapshots: + for _, expected := range expectAnothermockresources { + if _, err := snap.Anothermockresources.Find(expected.GetMetadata().Ref().Strings()); err != nil { + continue drain + } + } + for _, unexpected := range unexpectAnothermockresources { + if _, err := snap.Anothermockresources.Find(unexpected.GetMetadata().Ref().Strings()); err == nil { + continue drain + } + } + break drain + case err := <-errs: + Expect(err).NotTo(HaveOccurred()) + case <-time.After(time.Second * 10): + nsList1, _ := anotherMockResourceClient.List(namespace1, clients.ListOpts{}) + nsList2, _ := anotherMockResourceClient.List(namespace2, clients.ListOpts{}) + combined := append(nsList1, nsList2...) + Fail("expected final snapshot before 10 seconds. expected " + log.Sprintf("%v", combined)) + } + } + } + anotherMockResource1a, err := anotherMockResourceClient.Write(testing_solo_io_kubernetes.NewAnotherMockResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + anotherMockResource1b, err := anotherMockResourceClient.Write(testing_solo_io_kubernetes.NewAnotherMockResource(namespace2, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotAnothermockresources(testing_solo_io_kubernetes.AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b}, nil) + anotherMockResource2a, err := anotherMockResourceClient.Write(testing_solo_io_kubernetes.NewAnotherMockResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + anotherMockResource2b, err := anotherMockResourceClient.Write(testing_solo_io_kubernetes.NewAnotherMockResource(namespace2, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotAnothermockresources(testing_solo_io_kubernetes.AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b, anotherMockResource2a, anotherMockResource2b}, nil) + + err = anotherMockResourceClient.Delete(anotherMockResource2a.GetMetadata().Namespace, anotherMockResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + err = anotherMockResourceClient.Delete(anotherMockResource2b.GetMetadata().Namespace, anotherMockResource2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotAnothermockresources(testing_solo_io_kubernetes.AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b}, testing_solo_io_kubernetes.AnotherMockResourceList{anotherMockResource2a, anotherMockResource2b}) + + err = anotherMockResourceClient.Delete(anotherMockResource1a.GetMetadata().Namespace, anotherMockResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + err = anotherMockResourceClient.Delete(anotherMockResource1b.GetMetadata().Namespace, anotherMockResource1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotAnothermockresources(nil, testing_solo_io_kubernetes.AnotherMockResourceList{anotherMockResource1a, anotherMockResource1b, anotherMockResource2a, anotherMockResource2b}) + + /* + ClusterResource + */ + + assertSnapshotClusterresources := func(expectClusterresources testing_solo_io_kubernetes.ClusterResourceList, unexpectClusterresources testing_solo_io_kubernetes.ClusterResourceList) { + drain: + for { + select { + case snap = <-snapshots: + for _, expected := range expectClusterresources { + if _, err := snap.Clusterresources.Find(expected.GetMetadata().Ref().Strings()); err != nil { + continue drain + } + } + for _, unexpected := range unexpectClusterresources { + if _, err := snap.Clusterresources.Find(unexpected.GetMetadata().Ref().Strings()); err == nil { + continue drain + } + } + break drain + case err := <-errs: + Expect(err).NotTo(HaveOccurred()) + case <-time.After(time.Second * 10): + combined, _ := clusterResourceClient.List(clients.ListOpts{}) + Fail("expected final snapshot before 10 seconds. expected " + log.Sprintf("%v", combined)) + } + } + } + clusterResource1a, err := clusterResourceClient.Write(testing_solo_io_kubernetes.NewClusterResource(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotClusterresources(testing_solo_io_kubernetes.ClusterResourceList{clusterResource1a}, nil) + clusterResource2a, err := clusterResourceClient.Write(testing_solo_io_kubernetes.NewClusterResource(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotClusterresources(testing_solo_io_kubernetes.ClusterResourceList{clusterResource1a, clusterResource2a}, nil) + + err = clusterResourceClient.Delete(clusterResource2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotClusterresources(testing_solo_io_kubernetes.ClusterResourceList{clusterResource1a}, testing_solo_io_kubernetes.ClusterResourceList{clusterResource2a}) + + err = clusterResourceClient.Delete(clusterResource1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotClusterresources(nil, testing_solo_io_kubernetes.ClusterResourceList{clusterResource1a, clusterResource2a}) + + /* + MockCustomType + */ + + assertSnapshotmcts := func(expectmcts github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList, unexpectmcts github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList) { + drain: + for { + select { + case snap = <-snapshots: + for _, expected := range expectmcts { + if _, err := snap.Mcts.Find(expected.GetMetadata().Ref().Strings()); err != nil { + continue drain + } + } + for _, unexpected := range unexpectmcts { + if _, err := snap.Mcts.Find(unexpected.GetMetadata().Ref().Strings()); err == nil { + continue drain + } + } + break drain + case err := <-errs: + Expect(err).NotTo(HaveOccurred()) + case <-time.After(time.Second * 10): + nsList1, _ := mockCustomTypeClient.List(namespace1, clients.ListOpts{}) + nsList2, _ := mockCustomTypeClient.List(namespace2, clients.ListOpts{}) + combined := append(nsList1, nsList2...) + Fail("expected final snapshot before 10 seconds. expected " + log.Sprintf("%v", combined)) + } + } + } + mockCustomType1a, err := mockCustomTypeClient.Write(github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomType(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + mockCustomType1b, err := mockCustomTypeClient.Write(github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomType(namespace2, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotmcts(github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList{mockCustomType1a, mockCustomType1b}, nil) + mockCustomType2a, err := mockCustomTypeClient.Write(github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomType(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + mockCustomType2b, err := mockCustomTypeClient.Write(github_com_solo_io_solo_kit_test_mocks_v1.NewMockCustomType(namespace2, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotmcts(github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList{mockCustomType1a, mockCustomType1b, mockCustomType2a, mockCustomType2b}, nil) + + err = mockCustomTypeClient.Delete(mockCustomType2a.GetMetadata().Namespace, mockCustomType2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + err = mockCustomTypeClient.Delete(mockCustomType2b.GetMetadata().Namespace, mockCustomType2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotmcts(github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList{mockCustomType1a, mockCustomType1b}, github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList{mockCustomType2a, mockCustomType2b}) + + err = mockCustomTypeClient.Delete(mockCustomType1a.GetMetadata().Namespace, mockCustomType1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + err = mockCustomTypeClient.Delete(mockCustomType1b.GetMetadata().Namespace, mockCustomType1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotmcts(nil, github_com_solo_io_solo_kit_test_mocks_v1.MockCustomTypeList{mockCustomType1a, mockCustomType1b, mockCustomType2a, mockCustomType2b}) + + /* + Pod + */ + + assertSnapshotpods := func(expectpods github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList, unexpectpods github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList) { + drain: + for { + select { + case snap = <-snapshots: + for _, expected := range expectpods { + if _, err := snap.Pods.Find(expected.GetMetadata().Ref().Strings()); err != nil { + continue drain + } + } + for _, unexpected := range unexpectpods { + if _, err := snap.Pods.Find(unexpected.GetMetadata().Ref().Strings()); err == nil { + continue drain + } + } + break drain + case err := <-errs: + Expect(err).NotTo(HaveOccurred()) + case <-time.After(time.Second * 10): + nsList1, _ := podClient.List(namespace1, clients.ListOpts{}) + nsList2, _ := podClient.List(namespace2, clients.ListOpts{}) + combined := append(nsList1, nsList2...) + Fail("expected final snapshot before 10 seconds. expected " + log.Sprintf("%v", combined)) + } + } + } + pod1a, err := podClient.Write(github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.NewPod(namespace1, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + pod1b, err := podClient.Write(github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.NewPod(namespace2, name1), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotpods(github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList{pod1a, pod1b}, nil) + pod2a, err := podClient.Write(github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.NewPod(namespace1, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + pod2b, err := podClient.Write(github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.NewPod(namespace2, name2), clients.WriteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotpods(github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList{pod1a, pod1b, pod2a, pod2b}, nil) + + err = podClient.Delete(pod2a.GetMetadata().Namespace, pod2a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + err = podClient.Delete(pod2b.GetMetadata().Namespace, pod2b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotpods(github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList{pod1a, pod1b}, github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList{pod2a, pod2b}) + + err = podClient.Delete(pod1a.GetMetadata().Namespace, pod1a.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + err = podClient.Delete(pod1b.GetMetadata().Namespace, pod1b.GetMetadata().Name, clients.DeleteOpts{Ctx: ctx}) + Expect(err).NotTo(HaveOccurred()) + + assertSnapshotpods(nil, github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.PodList{pod1a, pod1b, pod2a, pod2b}) + }) +}) diff --git a/test/mocks/v2alpha1/testing_snapshot_simple_emitter.sk.go b/test/mockstwo/group/testing_snapshot_simple_emitter.sk.go similarity index 70% rename from test/mocks/v2alpha1/testing_snapshot_simple_emitter.sk.go rename to test/mockstwo/group/testing_snapshot_simple_emitter.sk.go index 7c0b9e463..802d27bc2 100644 --- a/test/mocks/v2alpha1/testing_snapshot_simple_emitter.sk.go +++ b/test/mockstwo/group/testing_snapshot_simple_emitter.sk.go @@ -1,13 +1,15 @@ // Code generated by solo-kit. DO NOT EDIT. -package v2alpha1 +package group import ( "context" - fmt "fmt" + "fmt" "time" - testing_solo_io "github.com/solo-io/solo-kit/test/mocks/v1" + github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes "github.com/solo-io/solo-kit/pkg/api/v1/resources/common/kubernetes" + github_com_solo_io_solo_kit_test_mocks_v1 "github.com/solo-io/solo-kit/test/mocks/v1" + testing_solo_io_kubernetes "github.com/solo-io/solo-kit/test/mocks/v1" "go.opencensus.io/stats" @@ -83,10 +85,18 @@ func (c *testingSimpleEmitter) Snapshots(ctx context.Context) (<-chan *TestingSn currentSnapshot = TestingSnapshot{} for _, res := range untypedList { switch typed := res.(type) { - case *MockResource: + case *testing_solo_io_kubernetes.MockResource: currentSnapshot.Mocks = append(currentSnapshot.Mocks, typed) - case *testing_solo_io.FakeResource: + case *testing_solo_io_kubernetes.FakeResource: currentSnapshot.Fakes = append(currentSnapshot.Fakes, typed) + case *testing_solo_io_kubernetes.AnotherMockResource: + currentSnapshot.Anothermockresources = append(currentSnapshot.Anothermockresources, typed) + case *testing_solo_io_kubernetes.ClusterResource: + currentSnapshot.Clusterresources = append(currentSnapshot.Clusterresources, typed) + case *github_com_solo_io_solo_kit_test_mocks_v1.MockCustomType: + currentSnapshot.Mcts = append(currentSnapshot.Mcts, typed) + case *github_com_solo_io_solo_kit_pkg_api_v1_resources_common_kubernetes.Pod: + currentSnapshot.Pods = append(currentSnapshot.Pods, typed) default: select { case errs <- fmt.Errorf("TestingSnapshotEmitter "+