Skip to content

Commit

Permalink
multiple changes (#119)
Browse files Browse the repository at this point in the history
* set list filter func
* fix output snapshot
* remove incorrect warning
* regen, fix chart labels
* add marshaljson to snapshots
* allow nil sets
* snapshot sync only writes local resources
* Add test builder for input snapshot. (#109)

* Add test builder for input snapshot.
* Input snapshot test builder (#110)

* Add test builder for input snapshot.
* colocate builder with snapshot
* distinguish client from type import for k8s native resources
* Merge branch 'upgrades2' into input-snapshot-test-builder
* delete test builder template
* explicitly add type import
* gen code
* sync -> syncLocalCluster
* ref to objkey util
* sync status multicluster
* Merge branch 'master' into upgrades2
* Upgrades2 tweaks (#113)

* Enable mockgen directive for snapshots
* separate input snapshot test builder into separate template
* output snapshot builder
* rename to InputSnapshotManualBuilder
* fix input snapshot manual builder file path
* fix manual snapshot builder imports
* dont silence error
* variadic args
* debug logs in output builder
* add interface for builder
* allow adding nil obj
* multicluster writes are partitioned from local cluster writes
* use interval and rate limit the number of events pushed to input reconciler queue
* Merge branch 'master' into upgrades2
* support predicates on input reconciler
* prevent insertion of nil objects into set
* add output error handlers implementation
* explicitly define clusters in snapshot
* ch
  • Loading branch information
ilackarms authored Aug 20, 2020
1 parent 9690c32 commit b998dc4
Show file tree
Hide file tree
Showing 34 changed files with 1,606 additions and 240 deletions.
1 change: 1 addition & 0 deletions api/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func main() {
groups = append(groups, k8s.Groups()...)

skv2Cmd := codegen.Command{
AppName: "skv2",
Groups: groups,
AnyVendorConfig: skv2Imports,
RenderProtos: true,
Expand Down
37 changes: 37 additions & 0 deletions changelog/v0.9.0/upgrades-2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
changelog:
- type: NEW_FEATURE
description: Input Reconciler - Add the ability to rate-limit reconciliations.
issueLink: https://github.com/solo-io/skv2/issues/120
- type: NEW_FEATURE
description: Input Reconciler - Add the ability to supply `predicate.Predicate`s to the reconciler's watch function.
issueLink: https://github.com/solo-io/skv2/issues/121
- type: NEW_FEATURE
description: Input Snapshot - Add the ability to sync input resource statuses across multiple clusters.
issueLink: https://github.com/solo-io/skv2/issues/122
- type: NEW_FEATURE
description: Input & Output Snapshot - Add a MarshalJSON function for debugging.
issueLink: https://github.com/solo-io/skv2/issues/123
- type: NEW_FEATURE
description: Input Snapshot - Add a builder for manually constructing input snapshots (to be used for testing).
issueLink: https://github.com/solo-io/skv2/issues/124
- type: FIX
description: Output Snapshot - Explicitly define desired clusters for multicluster snapshots.
issueLink: https://github.com/solo-io/skv2/issues/125
- type: BREAKING_CHANGE
description: Output Snapshot - Create separate Apply methods for Local Cluster and Multiple Clusters.
issueLink: https://github.com/solo-io/skv2/issues/126
- type: NEW_FEATURE
description: Output Snapshot - Add a builder for more conveniently constructing output snapshots.
issueLink: https://github.com/solo-io/skv2/issues/127
- type: FIX
description: Sets - now sets accept an `ezkube.ResourceId` for most methods.
issueLink: https://github.com/solo-io/skv2/issues/128
- type: NEW_FEATURE
description: Sets - now sets List function accepts a filter function.
issueLink: https://github.com/solo-io/skv2/issues/129
- type: NEW_FEATURE
description: Sets - now nil sets will not panic when calling methods (other than Insert).
issueLink: https://github.com/solo-io/skv2/issues/130
- type: NEW_FEATURE
description: Ezkube - Add util method `MakeClientObjectKey` for creating `client.ObjectKey`s.
issueLink: https://github.com/solo-io/skv2/issues/131
8 changes: 8 additions & 0 deletions codegen/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ func (c Command) generateTopLevelTemplates(templates model.CustomTemplates) erro
return err
}

if templates.MockgenDirective {
render.PrependMockgenDirective(customCode)
}

if err := fileWriter.WriteFiles(customCode); err != nil {
return err
}
Expand All @@ -249,6 +253,10 @@ func (c Command) generateTopLevelTemplates(templates model.CustomTemplates) erro
// it is important to run this func before rendering as it attaches protos to the
// group model
func (c Command) addDescriptorsToGroup(grp *render.Group, descriptors []*skmodel.DescriptorWithPath) {
if len(descriptors) == 0 {
logrus.Debugf("no descriptors generated")
return
}
descriptorMap := map[string]*skmodel.DescriptorWithPath{}

for i, resource := range grp.Resources {
Expand Down
3 changes: 3 additions & 0 deletions codegen/model/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ type CustomTemplates struct {
// maps output filename to template text
Templates map[string]string

// Enable to add //go:generate mockgen directive to the top of generated Go files.
MockgenDirective bool

// custom template funcs which will be inserted into the
// default template funcmap at rendering time
Funcs template.FuncMap
Expand Down
26 changes: 1 addition & 25 deletions codegen/render/kube_types_renderer.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package render

import (
"fmt"
"path/filepath"
"regexp"
"strings"
)

// renders kubernetes from templates
Expand Down Expand Up @@ -118,29 +115,8 @@ func (r KubeCodeRenderer) RenderKubeCode(grp Group) ([]OutFile, error) {
}

if grp.MockgenDirective {
// prepend each .go file with a go:generate directive to run mockgen on the file
for i, file := range files {
if !strings.HasSuffix(file.Path, ".go") {
continue
}
// only add the directive if the file contains interfaces
if !containsInterface(file.Content) {
continue
}

baseFile := filepath.Base(file.Path)
mockgenComment := fmt.Sprintf("//go:generate mockgen -source ./%v -destination mocks/%v", baseFile, baseFile)

file.Content = fmt.Sprintf("%v\n\n%v", mockgenComment, file.Content)
files[i] = file
}
PrependMockgenDirective(files)
}

return files, nil
}

var interfaceRegex = regexp.MustCompile("type .* interface")

func containsInterface(content string) bool {
return interfaceRegex.MatchString(content)
}
33 changes: 33 additions & 0 deletions codegen/render/mockgen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package render

import (
"fmt"
"path/filepath"
"regexp"
"strings"
)

func PrependMockgenDirective(files []OutFile) {
// prepend each .go file with a go:generate directive to run mockgen on the file
for i, file := range files {
if !strings.HasSuffix(file.Path, ".go") {
continue
}
// only add the directive if the file contains interfaces
if !containsInterface(file.Content) {
continue
}

baseFile := filepath.Base(file.Path)
mockgenComment := fmt.Sprintf("//go:generate mockgen -source ./%v -destination mocks/%v", baseFile, baseFile)

file.Content = fmt.Sprintf("%v\n\n%v", mockgenComment, file.Content)
files[i] = file
}
}

var interfaceRegex = regexp.MustCompile("type .* interface")

func containsInterface(content string) bool {
return interfaceRegex.MatchString(content)
}
32 changes: 20 additions & 12 deletions codegen/test/api/things.test.io/v1/sets/mocks/sets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit b998dc4

Please sign in to comment.