Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ksaritek committed Oct 11, 2023
1 parent 5220571 commit 4ec7a09
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 55 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,16 @@ make provider.addtype provider=${provider_name} group=${group} kind=${type}

# generate the code
make generate

# run grpc server
go run ./grpc-server/main.go

# run controller
make run

# apply configs under package/crds
kubectl apply -f package/crds

# update example yaml
kubectl apply -f ./examples/sample/example.yaml
```
4 changes: 2 additions & 2 deletions examples/sample/example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ metadata:
name: example
spec:
forProvider:
id: "example"
name: "example"
id: "1"
name: "John Doe"
email: "john@example.com"
# providerConfigRef:
# name: example
47 changes: 0 additions & 47 deletions grpc-server/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,54 +8,7 @@ GRPCURL_VERSION=v1.8.7

export PATH := ${LOCAL_BIN}:$(PATH)

### General
.PHONY: all
all: clean tools build test

.PHONY: tools
tools: go-imports tidy grpcurl-install

### Golang
.PHONY: go-imports
go-imports:
GOBIN=$(LOCAL_BIN) go install golang.org/x/tools/cmd/goimports@$(GOIMPORTS_VERSION)

.PHONY: grpcurl-install
grpcurl-install:
GOBIN=$(LOCAL_BIN) go install github.com/fullstorydev/grpcurl/cmd/grpcurl@$(GRPCURL_VERSION)

.PHONY: build
build:
go build -o $(LOCAL_BIN)/$(BINARY_NAME) -a -race ./cmd/$(BINARY_NAME)

.PHONY: build-fast
build-fast:
go build -o $(LOCAL_BIN)/$(BINARY_NAME) ./cmd/$(BINARY_NAME)

.PHONY: run
run:
go run main.go

.PHONY: test
test:
go test -failfast -v -vet=off -race ./...

.PHONY: update
update: tidy
go get -u ./...

.PHONY: tidy
tidy:
go mod tidy

.PHONY: imports
imports:
$(LOCAL_BIN)/goimports -l -w .

.PHONY: fmt
fmt:
go fmt ./...

.PHONY: clean
clean:
rm -rf $(LOCAL_BIN)
17 changes: 11 additions & 6 deletions internal/controller/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
}

// These fmt statements should be removed in the real implementation.
fmt.Printf("Observing: %+v", cr)
fmt.Printf("Observed: %+v", user)
fmt.Printf(">>> Observing: %+v\n", cr)
fmt.Printf(">>> Observed: %+v\n", user)

return managed.ExternalObservation{
// Return false when the external resource does not exist. This lets
Expand All @@ -183,13 +183,13 @@ func (c *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
}

func (c *external) Create(ctx context.Context, mg resource.Managed) (managed.ExternalCreation, error) {
fmt.Println("Create is called")
fmt.Println(">>>> Create is called")
cr, ok := mg.(*v1alpha1.User)
if !ok {
return managed.ExternalCreation{}, errors.New(errNotUser)
}

fmt.Printf("Creating: %+v", cr)
fmt.Printf(">>>> Creating: %+v\n", cr)

name := ""
if cr.Spec.ForProvider.Name != nil {
Expand Down Expand Up @@ -220,7 +220,7 @@ func (c *external) Update(ctx context.Context, mg resource.Managed) (managed.Ext
return managed.ExternalUpdate{}, errors.New(errNotUser)
}

fmt.Printf("Updating: %+v", cr)
fmt.Printf(">>>> Updating: %+v\n", cr)

return managed.ExternalUpdate{
// Optionally return any details that may be required to connect to the
Expand All @@ -235,7 +235,12 @@ func (c *external) Delete(ctx context.Context, mg resource.Managed) error {
return errors.New(errNotUser)
}

fmt.Printf("Deleting: %+v", cr)
fmt.Printf(">>>> Deleting: %+v\n", cr)
user, err := c.service.userCli.DeleteUser(ctx, &userapi.GetRequest{Id: cr.Spec.ForProvider.Id})
if err != nil {
return errors.Wrap(err, "cannot delete user")
}

fmt.Printf(">>> Deleted: %+v\n", user)
return nil
}

0 comments on commit 4ec7a09

Please sign in to comment.