Skip to main content

Contributing & Development

We welcome contributions to the ShareKube project! This guide will help you set up a development environment and understand how to contribute to the project.

Development Environment Setup

Prerequisites

  • Go 1.19 or higher
  • Kubernetes cluster for testing (minikube, kind, or k3d work well)
  • Docker for building images
  • kubectl configured for your cluster
  • Operator SDK (optional, for operator development)

Getting the Source Code

Clone the repository:

git clone https://github.com/miloszsobczak/sharekube.git
cd sharekube

Local Development Workflow

This section provides detailed instructions for setting up a local development environment to build, test, and run ShareKube.

Building the Operator

cd packages/operator
export PATH=$PATH:/usr/local/go/bin # Ensure Go is in your PATH
go build -o bin/manager main.go

Setting Up a Local Kubernetes Cluster

For testing the ShareKube operator, you can set up a local Kubernetes cluster using kind:

# Install kind if not already installed
brew install kind # macOS with Homebrew
# or
curl -Lo ./kind https://kind.sigs.k8s.io/dl/v0.20.0/kind-$(uname)-amd64
chmod +x ./kind
sudo mv ./kind /usr/local/bin/kind

# Create a Kubernetes cluster
kind create cluster --name sharekube

# Save the kubeconfig to a file for easier access
kind get kubeconfig --name=sharekube > /tmp/kubeconfig

Deploying the CRD

# Apply the CRD definition
kubectl --kubeconfig=/tmp/kubeconfig apply -f config/crd/bases/sharekube.dev_sharekubes.yaml

Running the Operator

You can run the operator directly from your development environment:

./bin/manager --kubeconfig=/tmp/kubeconfig

For debugging purposes, you can increase the log level:

./bin/manager -zap-log-level=debug --kubeconfig=/tmp/kubeconfig

Testing with a Sample Resource

Create a sample ShareKube resource to test the operator:

cat > sample-sharekube.yaml << EOF
apiVersion: sharekube.dev/v1alpha1
kind: ShareKube
metadata:
name: test-sharekube
namespace: default
spec:
targetNamespace: shared-resources
ttl: "24h"
resources: []
EOF

kubectl --kubeconfig=/tmp/kubeconfig apply -f sample-sharekube.yaml

Verify that the operator has processed the resource:

# Check if the target namespace was created
kubectl --kubeconfig=/tmp/kubeconfig get namespaces

# Check the status of the ShareKube resource
kubectl --kubeconfig=/tmp/kubeconfig get sharekubes -o yaml

You should see the target namespace "shared-resources" created and the ShareKube resource with a status phase of "Ready".

Building from Source

Build the operator:

# Build the operator binary
make build

# Build the Docker image
make docker-build IMG=sharekube/operator:dev

Running Locally

Run the operator locally:

# Install CRDs
make install

# Run the operator
make run

Testing

Run tests:

# Run unit tests
make test

# Run integration tests
make test-integration

Project Structure

The KubeShare project follows a standard Kubernetes operator structure:

├── api/                  # API definitions (CRDs)
│ └── v1alpha1/ # API version
├── config/ # Operator configuration
├── controllers/ # Operator controllers
├── pkg/ # Shared packages
│ ├── resources/ # Resource management
│ └── transformation/ # Transformation logic (future)
└── test/ # Test files

Development Workflow

  1. Fork the Repository: Fork the ShareKube repository on GitHub
  2. Create a Branch: Create a branch for your feature or bug fix
  3. Make Changes: Develop and test your changes
  4. Write Tests: Add tests for your changes
  5. Submit a Pull Request: Open a PR with a description of your changes

Coding Standards

Go Code

  • Follow the Go Code Review Comments
  • Format code with gofmt
  • Document all exported functions, types, and constants
  • Write unit tests for all functionality

Kubernetes Resources

Adding a New Feature

  1. Design: Document the feature design and discuss in an issue
  2. API Changes: If changing the API, update the CRD definitions
  3. Implementation: Implement the feature with tests
  4. Documentation: Update documentation to reflect changes

Future Transformation Rules Development

When implementing transformation rules (planned future feature):

  1. Define the transformation in the pkg/transformation package
  2. Create a transformation handler for each resource type
  3. Add unit tests for transformations
  4. Update the API documentation

Release Process

  1. Version Bump: Update version numbers in the code and manifests
  2. Changelog: Update the CHANGELOG.md with a summary of changes
  3. Tag Release: Create a Git tag for the release
  4. CI/CD: The CI pipeline will build and publish artifacts

Community

Join our community:

  • GitHub Discussions: For feature discussions and community help
  • Issues: Bug reports and feature requests
  • Pull Requests: Code contributions

Code of Conduct

We follow the CNCF Code of Conduct. Please be respectful and collaborative in all interactions.

License

KubeShare is licensed under the Apache 2.0 License. All contributions must comply with this license.


Thank you for considering a contribution to KubeShare! Your help makes the project better for everyone.