Skip to content

Commit

Permalink
scaffold
Browse files Browse the repository at this point in the history
  • Loading branch information
ksaritek committed Oct 11, 2023
1 parent c8685ab commit 2a129c1
Show file tree
Hide file tree
Showing 32 changed files with 299 additions and 299 deletions.
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ====================================================================================
# Setup Project
PROJECT_NAME := provider-template
PROJECT_NAME := provider-userprovider
PROJECT_REPO := github.com/crossplane/$(PROJECT_NAME)

PLATFORMS ?= linux_amd64 linux_arm64
Expand Down Expand Up @@ -30,7 +30,7 @@ GO111MODULE = on
# ====================================================================================
# Setup Images

IMAGES = provider-template
IMAGES = provider-userprovider
-include build/makelib/imagelight.mk

# ====================================================================================
Expand All @@ -40,12 +40,12 @@ XPKG_REG_ORGS ?= xpkg.upbound.io/crossplane
# NOTE(hasheddan): skip promoting on xpkg.upbound.io as channel tags are
# inferred.
XPKG_REG_ORGS_NO_PROMOTE ?= xpkg.upbound.io/crossplane
XPKGS = provider-template
XPKGS = provider-userprovider
-include build/makelib/xpkg.mk

# NOTE(hasheddan): we force image building to happen prior to xpkg build so that
# we ensure image is present in daemon.
xpkg.build.provider-template: do.build.images
xpkg.build.provider-userprovider: do.build.images

fallthrough: submodules
@echo Initial setup complete. Running make again . . .
Expand Down Expand Up @@ -93,9 +93,9 @@ dev: $(KIND) $(KUBECTL)
@$(KUBECTL) cluster-info --context kind-$(PROJECT_NAME)-dev
@$(INFO) Installing Crossplane CRDs
@$(KUBECTL) apply -k https://github.com/crossplane/crossplane//cluster?ref=master
@$(INFO) Installing Provider Template CRDs
@$(INFO) Installing Provider UserProvider CRDs
@$(KUBECTL) apply -R -f package/crds
@$(INFO) Starting Provider Template controllers
@$(INFO) Starting Provider UserProvider controllers
@$(GO) run cmd/provider/main.go --debug

dev-clean: $(KIND) $(KUBECTL)
Expand All @@ -120,7 +120,7 @@ $(GOMPLATE):

export GOMPLATE

# This target prepares repo for your provider by replacing all "template"
# This target prepares repo for your provider by replacing all "userprovider"
# occurrences with your provider name.
# This target can only be run once, if you want to rerun for some reason,
# consider stashing/resetting your git state.
Expand Down
24 changes: 12 additions & 12 deletions PROVIDER_CHECKLIST.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ Generally projects are named `provider-<name>`, with `name` being the API being
managed. Example project names are `provider-aws`, `provider-kubernetes`,
and `provider-github`.

The [provider-template](https://github.com/crossplane/provider-template) repository can be
The [provider-userprovider](https://github.com/crossplane/provider-userprovider) repository can be
used as a starting point for new providers. For [terrajet](https://github.com/crossplane/terrajet)-based providers, the
[provider-jet-template](https://github.com/crossplane-contrib/provider-jet-template) is
[provider-jet-userprovider](https://github.com/crossplane-contrib/provider-jet-userprovider) is
available.

## Files
Expand All @@ -43,17 +43,17 @@ Most Crossplane providers include the following files:
[provider-gcp/README.md](https://github.com/crossplane/provider-gcp/blob/master/README.md)
as an example)
- [ ] Code is licensed under the [Apache 2.0
License](https://github.com/crossplane/provider-template/blob/main/LICENSE)
License](https://github.com/crossplane/provider-userprovider/blob/main/LICENSE)
- [ ] Include a “Developer Certificate of Origin”. Example:
[DCO](https://github.com/upbound/build/blob/master/DCO)
- [ ] Include the CNCF [Code of
Conduct](https://github.com/crossplane/crossplane/blob/master/CODE_OF_CONDUCT.md)
- [ ] Update
[OWNERS.md](https://github.com/crossplane/provider-template/blob/main/OWNERS.md)
[OWNERS.md](https://github.com/crossplane/provider-userprovider/blob/main/OWNERS.md)
with contacts for project Owners
- [ ] Ensure `hack/boilerplate.go.txt` (used in Code generation) includes
Crossplane Authors, Apache license and any other Copyright statements:
[https://github.com/crossplane/provider-template/blob/main/hack/boilerplate.go.txt](https://github.com/crossplane/provider-template/blob/main/hack/boilerplate.go.txt)
[https://github.com/crossplane/provider-userprovider/blob/main/hack/boilerplate.go.txt](https://github.com/crossplane/provider-userprovider/blob/main/hack/boilerplate.go.txt)
- [ ] Include Documentation on how to:
- [ ] Install Provider
- [ ] Contribute to Development
Expand All @@ -68,7 +68,7 @@ There are a number of build tools and processes that are common across the
Crossplane ecosystem. Using these ensures a consistent development environment
across projects.

The [provider-template](https://github.com/crossplane/provider-template)
The [provider-userprovider](https://github.com/crossplane/provider-userprovider)
repository contains most of these settings.

- [ ] Use the [Upbound build](https://github.com/upbound/build) submodule. (see
Expand All @@ -81,7 +81,7 @@ repository contains most of these settings.
- [ ] Create a [Crossplane
Package](https://crossplane.io/docs/master/concepts/packages.html)
configuration (see
[package/crossplane.yaml)](https://github.com/crossplane/provider-template/blob/main/package/crossplane.yaml)
[package/crossplane.yaml)](https://github.com/crossplane/provider-userprovider/blob/main/package/crossplane.yaml)

## Deployment of Artifacts

Expand All @@ -96,7 +96,7 @@ the publish and promotion workflows.
In general, providers should:

- [ ] Utilize GitHub workflows from
<https://github.com/crossplane/provider-template/tree/main/.github/workflows>
<https://github.com/crossplane/provider-userprovider/tree/main/.github/workflows>
- [ ] Create OCI image repos to push Package and Controller images.
- [ ] Automatically push Provider images and packages via CI
- [ ] Add GitHub Secrets to push to Docker repository. (To be performed by
Expand All @@ -112,7 +112,7 @@ to grant your project access to the GitHub org scoped secrets.

- [ ] Follow recommendations at
[https://github.com/crossplane/crossplane/blob/master/GOVERNANCE.md#repository-governance](https://github.com/crossplane/crossplane/blob/master/GOVERNANCE.md#repository-governance)
- [ ] Enable Issues on your project and configure Issue templates (examples at:
[.github/ISSUE_TEMPLATE](https://github.com/crossplane/provider-template/tree/master/.github/ISSUE_TEMPLATE))
- [ ] Create Pull Request Templates: (example:
[PULL_REQUEST_TEMPLATE.md](https://github.com/crossplane/provider-template/blob/master/.github/PULL_REQUEST_TEMPLATE.md))
- [ ] Enable Issues on your project and configure Issue userproviders (examples at:
[.github/ISSUE_TEMPLATE](https://github.com/crossplane/provider-userprovider/tree/master/.github/ISSUE_TEMPLATE))
- [ ] Create Pull Request UserProviders: (example:
[PULL_REQUEST_TEMPLATE.md](https://github.com/crossplane/provider-userprovider/blob/master/.github/PULL_REQUEST_TEMPLATE.md))
76 changes: 44 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,50 @@
# provider-template
# Crossplane sample that talks through Grpc Server

`provider-template` is a minimal [Crossplane](https://crossplane.io/) Provider
that is meant to be used as a template for implementing new Providers. It comes
with the following features that are meant to be refactored:
That project is an example for crossplane provider. Provider talks to grpc server to do CRUD operation

- A `ProviderConfig` type that only points to a credentials `Secret`.
- A `MyType` resource type that serves as an example managed resource.
- A managed resource controller that reconciles `MyType` objects and simply
prints their configuration in its `Observe` method.
## prepare local k8s cluster

## Developing
### kind

1. Use this repository as a template to create a new one.
1. Run `make submodules` to initialize the "build" Make submodule we use for CI/CD.
1. Rename the provider by running the following command:
```shell
export provider_name=MyProvider # Camel case, e.g. GitHub
make provider.prepare provider=${provider_name}
```bash
kind create cluster --name k8s-crossplane
kind get clusters
kubectl cluster-info --context kind-k8s-crossplane
## export kubeconfig
export KUBECONFIG="$(kind get kubeconfig --name='k8s-crossplane')"
```
4. Add your new type by running the following command:
```shell
export group=sample # lower case e.g. core, cache, database, storage, etc.
export type=MyType # Camel casee.g. Bucket, Database, CacheCluster, etc.
make provider.addtype provider=${provider_name} group=${group} kind=${type}

### crossplane install

```bash
helm repo add crossplane-stable https://charts.crossplane.io/stable
helm repo update
helm install crossplane \
--namespace crossplane-system \
--create-namespace crossplane-stable/crossplane
```

!!! if you run controller as an image instead of `make run`, use `host.docker.internal` to reach grpc-server running locally from local k8s cluster https://docs.docker.com/desktop/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host

## clone [provider userprovider](https://github.com/crossplane/provider-userprovider) and prepare provider

```bash
# fetch the [upbound/build] submodule by running the following
make submodules

# update template with your provider name
export provider_name=UserProvider
make provider.prepare provider=${provider_name}

# add User kind under playground group
export group=playground
export type=User
make provider.addtype provider=${provider_name} group=${group} kind=${type}

# register new APIs and Controllers
## 1. apis/userprovider.go
## 2. internal/controller/userprovider.go

# generate the code
make generate
```
5. Replace the *sample* group with your new group in apis/{provider}.go
5. Replace the *mytype* type with your new type in internal/controller/{provider}.go
5. Replace the default controller and ProviderConfig implementations with your own
5. Run `make reviewable` to run code generation, linters, and tests.
5. Run `make build` to build the provider.

Refer to Crossplane's [CONTRIBUTING.md] file for more information on how the
Crossplane community prefers to work. The [Provider Development][provider-dev]
guide may also be of use.

[CONTRIBUTING.md]: https://github.com/crossplane/crossplane/blob/master/CONTRIBUTING.md
[provider-dev]: https://github.com/crossplane/crossplane/blob/master/contributing/guide-provider-development.md
6 changes: 3 additions & 3 deletions apis/sample/sample.go → apis/playground/playground.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 The Crossplane Authors.
Copyright 2022 The Crossplane Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -14,5 +14,5 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package sample contains group Sample API versions
package sample
// Package playground contains group playground API versions
package playground
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 The Crossplane Authors.
Copyright 2022 The Crossplane Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha1 contains the v1alpha1 group Sample resources of the Template provider.
// Package v1alpha1 contains the v1alpha1 group Sample resources of the UserProvider provider.
// +kubebuilder:object:generate=true
// +groupName=sample.template.crossplane.io
// +groupName=playground.userprovider.crossplane.io
// +versionName=v1alpha1
package v1alpha1

Expand All @@ -27,7 +27,7 @@ import (

// Package type metadata.
const (
Group = "sample.template.crossplane.io"
Group = "playground.userprovider.crossplane.io"
Version = "v1alpha1"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2020 The Crossplane Authors.
Copyright 2022 The Crossplane Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -25,63 +25,62 @@ import (
xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1"
)

// MyTypeParameters are the configurable fields of a MyType.
type MyTypeParameters struct {
// UserParameters are the configurable fields of a User.
type UserParameters struct {
ConfigurableField string `json:"configurableField"`
}

// MyTypeObservation are the observable fields of a MyType.
type MyTypeObservation struct {
ConfigurableField string `json:"configurableField"`
ObservableField string `json:"observableField,omitempty"`
// UserObservation are the observable fields of a User.
type UserObservation struct {
ObservableField string `json:"observableField,omitempty"`
}

// A MyTypeSpec defines the desired state of a MyType.
type MyTypeSpec struct {
// A UserSpec defines the desired state of a User.
type UserSpec struct {
xpv1.ResourceSpec `json:",inline"`
ForProvider MyTypeParameters `json:"forProvider"`
ForProvider UserParameters `json:"forProvider"`
}

// A MyTypeStatus represents the observed state of a MyType.
type MyTypeStatus struct {
// A UserStatus represents the observed state of a User.
type UserStatus struct {
xpv1.ResourceStatus `json:",inline"`
AtProvider MyTypeObservation `json:"atProvider,omitempty"`
AtProvider UserObservation `json:"atProvider,omitempty"`
}

// +kubebuilder:object:root=true

// A MyType is an example API type.
// A User is an example API type.
// +kubebuilder:printcolumn:name="READY",type="string",JSONPath=".status.conditions[?(@.type=='Ready')].status"
// +kubebuilder:printcolumn:name="SYNCED",type="string",JSONPath=".status.conditions[?(@.type=='Synced')].status"
// +kubebuilder:printcolumn:name="EXTERNAL-NAME",type="string",JSONPath=".metadata.annotations.crossplane\\.io/external-name"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp"
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,template}
type MyType struct {
// +kubebuilder:resource:scope=Cluster,categories={crossplane,managed,userprovider}
type User struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec MyTypeSpec `json:"spec"`
Status MyTypeStatus `json:"status,omitempty"`
Spec UserSpec `json:"spec"`
Status UserStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// MyTypeList contains a list of MyType
type MyTypeList struct {
// UserList contains a list of User
type UserList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []MyType `json:"items"`
Items []User `json:"items"`
}

// MyType type metadata.
// User type metadata.
var (
MyTypeKind = reflect.TypeOf(MyType{}).Name()
MyTypeGroupKind = schema.GroupKind{Group: Group, Kind: MyTypeKind}.String()
MyTypeKindAPIVersion = MyTypeKind + "." + SchemeGroupVersion.String()
MyTypeGroupVersionKind = SchemeGroupVersion.WithKind(MyTypeKind)
UserKind = reflect.TypeOf(User{}).Name()
UserGroupKind = schema.GroupKind{Group: Group, Kind: UserKind}.String()
UserKindAPIVersion = UserKind + "." + SchemeGroupVersion.String()
UserGroupVersionKind = SchemeGroupVersion.WithKind(UserKind)
)

func init() {
SchemeBuilder.Register(&MyType{}, &MyTypeList{})
SchemeBuilder.Register(&User{}, &UserList{})
}
Loading

0 comments on commit 2a129c1

Please sign in to comment.