Skip to content

frigaut-orange/test-provider

Repository files navigation

Test provider for crossplane

Garbage test provider only for tests and pure amusement

How I generated and used this repo

Note : This repo is malformed in the way that repositories for crossplane providers should be name provider-xxx. Some of the commands in this section are only run to fix this issue, but it may be useful if we want to have a provider name that differs from the repository's name for some reason.

Run :

export provider_name=TestProvider
make provider.prepare provider=${provider_name}
export group=TestGroup
export type=TestType
make provider.addtype provider=${provider_name} group=${group} kind=${type}

Then :

  • edit apis/testprovider.go and put correct path at L24
  • edit internal/controller/testprovider.go and put correct path at L24 + replace accordingly at L32
  • edit apis/testgrop/v1alpha1/testtype_types.go and replace attribute names at L30 and L35
  • run make generate
  • edit Makefile :
    • replace PROJECT_NAME (L3), IMAGES (L33) and XPKGS (L43) values to match the repo's name
    • replace PROJECT_REPO value at L4 to match the repo's path
    • remove linux_arm64 from PLATFORMS value at L6
    • replace XPKG_REG_ORGS (L39) and XPKG_REG_ORGS_NO_PROMOTE (L42) values to match our artifactory's path
  • rename cluster/images/provider-testprovider folder to cluster/images/test-provider to match the repo's name
  • run a big sed to replace github.com/crossplane/provider-testprovider with github.com/frigaut-orange/test-provider
  • run VERSION=v0.0.1-rc1 make build
  • run VERSION=v0.0.1-rc1 make publish
  • deploy with crossplane xpkg install provider kaastools-xpkg/test-provider:v0.0.1-rc1 --package-pull-secrets=kaastoolsbot-docker-creds
  • if you want to, deploy test resources with kubectl apply -f examples/provider/config.yaml and kubectl apply -f examples/sample/testtype.yaml

Note : I also tried a version where I edited build/makelib/xpkg.mk (git submodule) to use crossplane xpkg build instead of up build (L72). It included :

  • a renaming of the --controller option with --embed-runtime-image
  • a removal of the --auth-ext option, which doesn't exist with the crossplane command
  • a renaming of the --output command with --package-file

Useful notes

Since crossplane expects an XPKG-formatted OCI image, you can't just docker build and docker push (hence the makefile build and release commands). You have to use xpkg build and xpkg push (run by makefile). Otherwise, the provider's pod won't create with an error saying something like package.yaml not found (annotated layer: false).

When creating TestType objects, the provider will say "external resources ready". It is because the logic in internal/controller/testtype/testtype.go:Observe (L134) always returns ResourceExists: true (L147). This is where we would add the logic for our managed resources.


The following text is what was automatically generated by the makefile, left here as an example.


provider-testprovider

provider-testprovider is a minimal Crossplane Provider that is meant to be used as a testprovider for implementing new Providers. It comes with the following features that are meant to be refactored:

  • 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.

Developing

  1. Use this repository as a testprovider to create a new one.
  2. Run make submodules to initialize the "build" Make submodule we use for CI/CD.
  3. Rename the provider by running the following command:
  export provider_name=MyProvider # Camel case, e.g. GitHub
  make provider.prepare provider=${provider_name}
  1. Add your new type by running the following command:
  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}
  1. Replace the sample group with your new group in apis/{provider}.go
  2. Replace the mytype type with your new type in internal/controller/{provider}.go
  3. Replace the default controller and ProviderConfig implementations with your own
  4. 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 guide may also be of use.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published