Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cosmos 2065 #166

Draft
wants to merge 43 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
8788d8c
NPT-632: Cosmos DM nexus compiler changes
vishnukavach Mar 15, 2023
ecfae16
COSMOS-856 and COSMOS-858 Fix
vishnukavach Mar 17, 2023
6dc6625
Add new type
vishnukavach Mar 17, 2023
680f308
Fix graphql resolver
vishnukavach Mar 17, 2023
4577d1d
Add new type NexusGenericObject
vishnukavach Mar 22, 2023
7a25149
Use upper case first letter for non global nodes
kacpersaw Mar 27, 2023
8cf2173
Use upper case first letter for field schema name
kacpersaw Mar 27, 2023
d78ffae
Add Node NotifyCallBack in nexus-client
vishnukavach Mar 27, 2023
547915e
Add RegisterCB function
vishnukavach Mar 28, 2023
b338227
Parse non nexus nodes and types and copy them to model dir
kacpersaw Mar 28, 2023
fe8c6e0
upgrade client-go to v0.26.3
vishnukavach Mar 28, 2023
0a36dba
upgrade client-go to v0.26.3
vishnukavach Mar 28, 2023
dbb684d
Pin k8s client-go version
vishnukavach Mar 29, 2023
db07d2e
COSMOS-893 Make graphql server as go binary directly to run , instead…
ramramu3433 Mar 29, 2023
396c95b
when commit pushed
janakiramanmesh7 Mar 29, 2023
c072d50
set apiextensions-apiserver as require
vishnukavach Mar 30, 2023
938136e
Update require k8s lib
vishnukavach Mar 30, 2023
7531f95
Merge branch 'npt-632' of github.com:vmware-tanzu/graph-framework-for…
vishnukavach Mar 30, 2023
b908325
Fatal node without parent
vishnukavach Mar 30, 2023
f3f5e5f
Fix GNS Plural issue
vishnukavach Mar 30, 2023
cb6f9ce
Fix plural issue GNS --> gnss
vishnukavach Mar 31, 2023
9a61429
revert kacper non global changes
vishnukavach Mar 31, 2023
2bd14a6
Reverted Plural fix and COSMOS Nexus Compiler version-1
vishnukavach Mar 31, 2023
9b230aa
Bring in Plural Fix as version-2
vishnukavach Mar 31, 2023
d303623
Fix issue in Delete{Node}ByName() method (#147)
LokeshvarKr Apr 3, 2023
2b9e9d6
Cleanup unused notify method
vishnukavach Apr 3, 2023
b439758
Skipping ignored dirs from config in preparser and node_parser
vipinakavarpu Apr 3, 2023
471d7e0
Merge pull request #149 from vmware-tanzu/npt-632-cosmos-datamodel-up…
xmen4xp Apr 5, 2023
e860c00
NPT-890: Modified RegisterCB return type
vishnukavach Apr 12, 2023
ce82f6e
COSMOS-1507: Modified return type template nexus client
vishnukavach Apr 13, 2023
f7a43e6
NPT-632 Cosmos datamodel non global packages support (#150)
kacpersaw Apr 18, 2023
7541c43
Fixed issue in graphql schema generation for non standard array type
vishnukavach Apr 18, 2023
4053da9
Add ForceRead support
vishnukavach Apr 19, 2023
7e1a590
COSMOS-1557: Check if parent exist before calling callback func (#151)
kacpersaw Apr 24, 2023
53ae696
Added singletone details in nexus directives
vishnukavach Apr 25, 2023
ada508c
COSMOS-1557: Fix data race (#153)
kacpersaw Apr 27, 2023
fc3cedf
Adding template for RegisterEventHandler (#154)
LokeshvarKr May 3, 2023
17a4212
Bump go version
kacpersaw May 5, 2023
e362b09
Pin cert-manager version
kacpersaw May 5, 2023
83580ac
Fix problem with hardcoded Global() in nexus client
kacpersaw May 8, 2023
b5c0351
Fix typo
kacpersaw May 8, 2023
8f34b5f
Use Parent's SimpleGroupName for force read
kacpersaw May 8, 2023
b220a29
nexus client logger and retry
vishnukavach May 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: Build Compiler image
on:
push:
branches:
- 'npt-632'
- 'main'
pull_request:
branches: [ main ]
jobs:
Expand All @@ -13,8 +17,6 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: '>=1.17.0'
- name: setup-docker
uses: docker-practice/actions-setup-docker@1.0.11
- name: 'Set up Cloud SDK'
uses: 'google-github-actions/setup-gcloud@v0'
- name: Build Compiler image
Expand Down Expand Up @@ -51,8 +53,6 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: '>=1.17.0'
- name: setup-docker
uses: docker-practice/actions-setup-docker@1.0.11
- name: Test Generate Code and Render templates
run: |
git config --global url."https://github.com/".insteadOf "git@github.com:"
Expand Down
1 change: 1 addition & 0 deletions compiler/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ cmd/nexus-openapi-gen
cmd/gqlgen
compiler.tar
_generated
_tsm_temp

### GoLand ###
.idea
Expand Down
2 changes: 1 addition & 1 deletion compiler/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ RUN CGO_ENABLED=0 go build --trimpath -o install.so ./cmd/validate
WORKDIR /go/src/github.com/vmware-tanzu/graph-framework-for-microservices/compiler
RUN go mod download

CMD make docker.gitlab_credentials && make generate_code
CMD make docker.gitlab_credentials && make preparser
59 changes: 49 additions & 10 deletions compiler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ CONFIG_FILE ?= ""
GENERATED_OUTPUT_DIRECTORY ?= generated
COMPILER_SRC_DIRECTORY ?= ""
FORCE ?= false
PREPARSER_MODPATH ?= model

NEXUS_KUBEOPENAPI_VERSION ?= 7416bd4754d3c0dd8b3fa37fff53d36594f11607
NEXUS_GRAPHQLGEN_VERSION ?= 32f028bce22efeb70b47a640195bd969dbb337f0
Expand Down Expand Up @@ -140,11 +141,48 @@ generate_example_in_container:
test_in_container: ${BUILDER_NAME}\:${BUILDER_TAG}.image.exists
$(call run_in_container, make test)

.PHONY: preparser
preparser:
@echo "Nexus Compiler: Start Preparser"
@echo "Cleaning up workdir"
rm -rf _generated
@echo "Copying generated_base_structure to create directory structure"
@echo "COMPILER_SRC_DIRECTORY: ${COMPILER_SRC_DIRECTORY}"
cp -R _generated_base_structure _generated
@echo "Cleaning up temp dir"
rm -rf _tsm_temp
@echo "Copying Datamodel to temp directory"
cp -R ${DATAMODEL_PATH} _tsm_temp
cp -R _generated_base_structure/* ${DATAMODEL_PATH}/build
@echo "Nexus Compiler: Running Preparser"
go run cmd/preparser/main.go -config-file ${CONFIG_FILE} -dsl _tsm_temp -output _generated -modpath ${PREPARSER_MODPATH}
@echo "Nexus Compiler: Remove empty directories from model directory"
@find _generated/model -depth -type d -empty -delete

@if [ -d "_tsm_temp/global" ]; then \
cp _tsm_temp/go.mod _tsm_temp/global/go.mod; \
for dir in _tsm_temp/*; do \
if [[ -d "$$dir" && "$$dir" != "_tsm_temp/global" && "$$dir" != "_tsm_temp/build" ]]; then \
cp -r "$$dir" _tsm_temp/global/; \
fi; \
done; \
$(MAKE) generate_code DATAMODEL_PATH=_tsm_temp/global; \
else \
$(MAKE) generate_code; \
fi

test_if:
for dir in _tsm_temp/*; do \
if [[ -d "$$dir" && "$$dir" != "_tsm_temp/global" && "$$dir" != "_tsm_temp/build" ]]; then \
cp -r "$$dir" _tsm_temp/global/; \
fi; \
done

.PHONY: generate_code
generate_code:
@echo "Nexus Compiler: Running compiler code generation"
@echo "Cleaning up workdir"
rm -rf _generated ${GOPATH}/src/nexustempmodule
rm -rf ${GOPATH}/src/nexustempmodule
@echo "Copying generated_base_structure to create directory structure"
@echo "COMPILER_SRC_DIRECTORY: ${COMPILER_SRC_DIRECTORY}"
cp -R _generated_base_structure _generated
Expand All @@ -164,28 +202,29 @@ generate_code:
@echo "Nexus Compiler: Generating CRD yamls"
go run cmd/generate-openapischema/generate-openapischema.go -yamls-path _generated/crds -existing-CRDs-Path ${GENERATED_OUTPUT_DIRECTORY}/crds -force ${FORCE}
git checkout -- pkg/openapi_generator/openapi/openapi_generated.go
rm -rf ${GENERATED_OUTPUT_DIRECTORY}/{client,apis,crds,common,nexus-client,helper,nexus-gql}
cp -r _generated/{client,apis,crds,common,nexus-client,helper,nexus-gql} ${GENERATED_OUTPUT_DIRECTORY}
rm -rf ${GENERATED_OUTPUT_DIRECTORY}/{client,apis,crds,common,nexus-client,helper,nexus-gql,tsm-nexus-gql,model}
cp -r _generated/{client,apis,crds,common,nexus-client,helper,nexus-gql,tsm-nexus-gql,model} ${GENERATED_OUTPUT_DIRECTORY}
@echo "Nexus Compiler: Generating GRAPHQL PKG"
cd _generated && goimports -w .
cd _generated && mv model/model.go model/model.tmp && goimports -w . && mv model/model.tmp model/model.go
cd _generated/nexus-gql && gqlgen generate
@echo "Nexus Compiler: GRAPHQL Generating completed"
cp -rf _generated/* ${GOPATH}/src/nexustempmodule/
cd ${GOPATH}/src/nexustempmodule && cd nexus-gql && go mod init && \
go mod edit -replace nexustempmodule=${GOPATH}/src/nexustempmodule && \
${COMPILER_SRC_DIRECTORY}/scripts/pin_graphql_build_version.sh ${COMPILER_SRC_DIRECTORY} && \
go mod tidy -e 2>/dev/null && \
CGO_ENABLED=1 GOOS=linux \
go build --trimpath -o graphql.so -buildmode=plugin server.go
go mod edit -go=1.18 && \
go mod tidy && \
CGO_ENABLED=1 GOARCH=amd64 GOOS=linux go build -ldflags="-w -s" server.go
@echo "Updating module name"
./scripts/replace_mod_path.sh
find . -name "*.bak" -type f -delete
@echo "Sorting imports"
cd _generated && goimports -w .
cd _generated && mv model/model.go model/model.tmp && goimports -w . && mv model/model.tmp model/model.go
@echo "Nexus Compiler: Moving files to output directory"
cp -r _generated/{client,apis,crds,common,nexus-client,helper,nexus-gql} ${GENERATED_OUTPUT_DIRECTORY}
cp -r ${GOPATH}/src/nexustempmodule/nexus-gql/graphql.so ${GENERATED_OUTPUT_DIRECTORY}/nexus-gql
mkdir -p ${GENERATED_OUTPUT_DIRECTORY}/install-validator
cp -r ${GOPATH}/src/github.com/vmware-tanzu/graph-framework-for-microservices/install-validator/install.so ${GENERATED_OUTPUT_DIRECTORY}/install-validator/install.so || echo "Could not find install.so file, skipping"
cp -r _generated/{client,apis,crds,common,nexus-client,helper,nexus-gql,tsm-nexus-gql,model} ${GENERATED_OUTPUT_DIRECTORY}
cp -r ${GOPATH}/src/nexustempmodule/nexus-gql/* ${GENERATED_OUTPUT_DIRECTORY}/nexus-gql/
@echo "Nexus Compiler: Compiler code generation completed"

.PHONY: test_generate_code_in_container
Expand Down
2 changes: 1 addition & 1 deletion compiler/_deps/github.com/kubernetes/code-generator
Submodule code-generator updated 107 files
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion compiler/builder/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#graphql's and compiler's builder/Dockerfile should be in sync
FROM gcr.io/nsx-sm/nexus/golang:1.18
FROM gcr.io/nsx-sm/nexus/golang:1.19

ENV GOPATH /go
ENV PATH $PATH:/usr/local/go/bin:/go/bin
Expand Down
5 changes: 3 additions & 2 deletions compiler/cmd/nexus-sdk/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ func main() {
config.ConfigInstance = conf
pkgs := parser.ParseDSLPkg(*dslDir)
graphlqQueries := parser.ParseGraphqlQuerySpecs(pkgs)
graph := parser.ParseDSLNodes(*dslDir, conf.GroupName, pkgs, graphlqQueries)
graph, nonNexusTypes, fileset := parser.ParseDSLNodes(*dslDir, conf.GroupName, pkgs, graphlqQueries)
methods, codes := rest.ParseResponses(pkgs)
graphqlFiles := parser.ParseGraphQLFiles(*dslDir)
if err = generator.RenderCRDTemplate(conf.GroupName, conf.CrdModulePath, pkgs, graph,
*crdDir, methods, codes); err != nil {
*crdDir, methods, codes, nonNexusTypes, fileset, graphqlFiles); err != nil {
log.Fatalf("Error rendering crd template: %v", err)
}
}
49 changes: 49 additions & 0 deletions compiler/cmd/preparser/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package main

import (
"flag"
"github.com/vmware-tanzu/graph-framework-for-microservices/compiler/pkg/config"

log "github.com/sirupsen/logrus"
"github.com/vmware-tanzu/graph-framework-for-microservices/compiler/pkg/preparser"
)

func main() {
configFile := flag.String("config-file", "", "Config file location.")
dslDir := flag.String("dsl", "datamodel", "DSL file location.")
outputDir := flag.String("output", "_generated", "output dir location.")
modPath := flag.String("modpath", "datamodel", "ModPath for rendered imports")
logLevel := flag.String("log-level", "ERROR", "Log level")
flag.Parse()

lvl, err := log.ParseLevel(*logLevel)
if err != nil {
log.Fatalf("Failed to configure logging: %v\n", err)
}
log.SetLevel(lvl)

conf := &config.Config{}
if *configFile != "" {
conf, err = config.LoadConfig(*configFile)
if err != nil {
log.Fatalf("Error loading config: %v", err)
}
}
config.ConfigInstance = conf
packages := preparser.Parse(*dslDir)
err = preparser.Render(*dslDir, packages)
if err != nil {
log.Fatal(err)
}

packages = preparser.Parse(*dslDir)
err = preparser.RenderImports(packages, *outputDir, *modPath)
if err != nil {
log.Fatal(err)
}

err = preparser.CopyPkgsToBuild(packages, *outputDir)
if err != nil {
log.Fatal(err)
}
}
2 changes: 1 addition & 1 deletion compiler/example/datamodel/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"net/http"

"github.com/vmware-tanzu/graph-framework-for-microservices/compiler/example/datamodel/config/gns"
"github.com/vmware-tanzu/graph-framework-for-microservices/compiler/example/datamodel/config/gns/service-group"
servicegroup "github.com/vmware-tanzu/graph-framework-for-microservices/compiler/example/datamodel/config/gns/service-group"
py "github.com/vmware-tanzu/graph-framework-for-microservices/compiler/example/datamodel/config/policy"
"github.com/vmware-tanzu/graph-framework-for-microservices/nexus/nexus"
)
Expand Down
3 changes: 3 additions & 0 deletions compiler/example/datamodel/config/gns/gns.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net/http"

cartv1 "github.com/vmware-tanzu/cartographer/pkg/apis/v1alpha1"
"k8s.io/apimachinery/pkg/util/intstr"

service_group "github.com/vmware-tanzu/graph-framework-for-microservices/compiler/example/datamodel/config/gns/service-group"
policypkg "github.com/vmware-tanzu/graph-framework-for-microservices/compiler/example/datamodel/config/policy"
Expand Down Expand Up @@ -171,6 +172,8 @@ type Gns struct {
//nexus-validation: Pattern=abc
Domain string
UseSharedGateway bool
Annotations string `nexus-graphql-jsonencoded:""`
TargetPort intstr.IntOrString `json:"targetPort,omitempty" mapstructure:"targetPort,omitempty"`
Description Description
GnsServiceGroups service_group.SvcGroup `nexus:"children"`
GnsAccessControlPolicy policypkg.AccessControlPolicy `nexus:"child" nexus-graphql:"type:string"`
Expand Down
2 changes: 1 addition & 1 deletion compiler/example/datamodel/config/policy/policy.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package policypkg

import (
"github.com/vmware-tanzu/graph-framework-for-microservices/compiler/example/datamodel/config/gns/service-group"
servicegroup "github.com/vmware-tanzu/graph-framework-for-microservices/compiler/example/datamodel/config/gns/service-group"
"github.com/vmware-tanzu/graph-framework-for-microservices/nexus/nexus"
)

Expand Down

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

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

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

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

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

Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ models:
fields:
PolicyConfigs:
resolver: true
policypkg_ACPConfig:
fields:
DestSvcGroups:
resolver: true
SourceSvcGroups:
resolver: true
policypkg_VMpolicy:
fields:
queryGns1:
Expand Down
Loading