Skip to content

Commit

Permalink
Merge branch 'main' into add-liveness-and-readiness-probes
Browse files Browse the repository at this point in the history
  • Loading branch information
dimakis authored Jun 26, 2023
2 parents 1712272 + 9a7746b commit 73a39af
Show file tree
Hide file tree
Showing 67 changed files with 3,551 additions and 121 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/precommit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
volumes:
- /cache
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Activate cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: /cache
key: ${{ runner.os }}-cache-${{ hashFiles('**/go.sum', '.pre-commit-config.yaml') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tag-and-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: actions/checkout@v3

- name: Activate cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: /cache
key: ${{ runner.os }}-cache-${{ hashFiles('**/go.sum', '.pre-commit-config.yaml') }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:
volumes:
- /cache
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Activate cache
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: /cache
key: ${{ runner.os }}-cache-${{ hashFiles('**/go.sum', '.pre-commit-config.yaml') }}
Expand Down
11 changes: 9 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,21 @@ If changes are made to any Go code (like in the `controllers` dir for example),
- This will check and build/compile the modified code

For building and pushing a new version of the operator image:
- `make image-build -e IMG=<image-repo/image-name>`
- `make image-push -e IMG<image-repo/image-name>`
- `make image-build -e IMAGE_TAG_BASE=<image-repo/image-name> VERSION=<semver>`
- `make image-push -e IMAGE_TAG_BASE=<image-repo/image-name> VERSION=<semver>`

For deploying onto a cluster:
- First, either set `KUBECONFIG` or ensure you are logged into a cluster in your environment
- `make install`
- `make deploy -e IMG=<image-repo/image-name>`

For building and pushing a new version of the bundled operator image:
- `make bundle-build -e IMAGE_TAG_BASE=<image-repo/image-name> VERSION=<new semver> PREVIOUS_VERSION=<semver to replace>`
- `make bundle-push -e IMAGE_TAG_BASE=<image-repo/image-name> VERSION=<new semver> PREVIOUS_VERSION=<semver to replace>`

To create a new openshift-community-operator-release:
- `make openshift-community-operator-release -e IMAGE_TAG_BASE=<image-repo/image-name> VERSION=<new semver> PREVIOUS_VERSION=<semver to replace>`

## Testing
The CodeFlare Operator currently has unit tests and pre-commit checks
- To enable and view pre-commit checks: `pre-commit install`
Expand Down
99 changes: 96 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
# best if we could detect this. If we cannot, we need to document it somewhere.
# then we can add a patch in the `PHONY: bundle`

PREVIOUS_VERSION ?= 0.0.3
VERSION ?= 0.0.3-dev
PREVIOUS_VERSION ?= 0.0.0-dev
VERSION ?= 0.0.0-dev

# INSTASCALE_VERSION defines the default version of the InstaScale controller
INSTASCALE_VERSION ?= v0.0.3
INSTASCALE_VERSION ?= v0.0.4

# MCAD_VERSION defines the default version of the MCAD controller
MCAD_VERSION ?= v1.31.0
# MCAD_REF, MCAD_REPO and MCAD_CRD define the reference to MCAD CRD resources
MCAD_REF ?= release-${MCAD_VERSION}
MCAD_REPO ?= github.com/project-codeflare/multi-cluster-app-dispatcher
MCAD_CRD ?= ${MCAD_REPO}/config/crd?ref=${MCAD_REF}

# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
Expand Down Expand Up @@ -125,6 +132,38 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

.PHONY: generate-client ## Generate client packages
generate-client: code-generator
rm -rf client
$(APPLYCONFIGURATION_GEN) \
--input-dirs="github.com/project-codeflare/codeflare-operator/api/codeflare/v1alpha1" \
--go-header-file="hack/boilerplate.go.txt" \
--output-package="github.com/project-codeflare/codeflare-operator/client/applyconfiguration" \
--trim-path-prefix "github.com/project-codeflare/codeflare-operator"
$(CLIENT_GEN) \
--input="codeflare/v1alpha1" \
--input-base="github.com/project-codeflare/codeflare-operator/api" \
--apply-configuration-package="github.com/project-codeflare/codeflare-operator/client/applyconfiguration" \
--go-header-file="hack/boilerplate.go.txt" \
--clientset-name "versioned" \
--output-package="github.com/project-codeflare/codeflare-operator/client/clientset" \
--output-base="." \
--trim-path-prefix "github.com/project-codeflare/codeflare-operator"
$(LISTER_GEN) \
--input-dirs="github.com/project-codeflare/codeflare-operator/api/codeflare/v1alpha1" \
--go-header-file="hack/boilerplate.go.txt" \
--output-base="." \
--output-package="github.com/project-codeflare/codeflare-operator/client/listers" \
--trim-path-prefix "github.com/project-codeflare/codeflare-operator"
$(INFORMER_GEN) \
--input-dirs="github.com/project-codeflare/codeflare-operator/api/codeflare/v1alpha1" \
--versioned-clientset-package="github.com/project-codeflare/codeflare-operator/client/clientset/versioned" \
--listers-package="github.com/project-codeflare/codeflare-operator/client/listers" \
--go-header-file="hack/boilerplate.go.txt" \
--output-base="." \
--output-package="github.com/project-codeflare/codeflare-operator/client/informer" \
--trim-path-prefix "github.com/project-codeflare/codeflare-operator"

.PHONY: fmt
fmt: ## Run go fmt against code.
go fmt ./...
Expand Down Expand Up @@ -168,8 +207,10 @@ uninstall: manifests kustomize ## Uninstall CRDs from the K8s cluster specified

.PHONY: deploy
deploy: manifests kustomize ## Deploy controller to the K8s cluster specified in ~/.kube/config.
$(KUSTOMIZE) fn run config/crd/mcad --image gcr.io/kpt-fn/apply-setters:v0.2.0 -- MCAD_CRD=$(MCAD_CRD)
cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG}
$(KUSTOMIZE) build config/default | kubectl apply -f -
git restore config/*

.PHONY: undeploy
undeploy: ## Undeploy controller from the K8s cluster specified in ~/.kube/config. Call with ignore-not-found=true to ignore resource not found errors during deletion.
Expand All @@ -184,21 +225,62 @@ $(LOCALBIN):

## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
APPLYCONFIGURATION_GEN ?= $(LOCALBIN)/applyconfiguration-gen
CLIENT_GEN ?= $(LOCALBIN)/client-gen
LISTER_GEN ?= $(LOCALBIN)/lister-gen
INFORMER_GEN ?= $(LOCALBIN)/informer-gen
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
OPERATOR_SDK ?= $(LOCALBIN)/operator-sdk
GH_CLI ?= $(LOCALBIN)/gh

## Tool Versions
KUSTOMIZE_VERSION ?= v4.5.4
CODEGEN_VERSION ?= v0.27.2
CONTROLLER_TOOLS_VERSION ?= v0.9.2
OPERATOR_SDK_VERSION ?= v1.27.0
GH_CLI_VERSION ?= 2.30.0

KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary.
$(KUSTOMIZE): $(LOCALBIN)
test -s $(LOCALBIN)/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(LOCALBIN); }

GH_CLI_DL_URL := https://github.com/cli/cli/releases/download/v$(GH_CLI_VERSION)
GH_CLI_DL_FILENAME := gh_$(GH_CLI_VERSION)_$(shell go env GOOS)_$(shell go env GOARCH)
.PHONY: install-gh-cli
install-gh-cli: $(GH_CLI)
$(GH_CLI): $(LOCALBIN)
curl -L $(GH_CLI_DL_URL)/$(GH_CLI_DL_FILENAME).tar.gz --output $(GH_CLI_DL_FILENAME).tar.gz
tar -xvzf $(GH_CLI_DL_FILENAME).tar.gz
cp $(GH_CLI_DL_FILENAME)/bin/gh $(GH_CLI)
rm -rf $(GH_CLI_DL_FILENAME)
rm $(GH_CLI_DL_FILENAME).tar.gz

.PHONY: code-generator
code-generator: $(APPLYCONFIGURATION_GEN) $(CLIENT_GEN) $(LISTER_GEN) $(INFORMER_GEN)

.PHONY: applyconfiguration-gen
applyconfiguration-gen: $(APPLYCONFIGURATION_GEN)
$(APPLYCONFIGURATION_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/applyconfiguration-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/applyconfiguration-gen@$(CODEGEN_VERSION)

.PHONY: client-gen
client-gen: $(CLIENT_GEN)
$(CLIENT_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/client-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/client-gen@$(CODEGEN_VERSION)

.PHONY: lister-gen
lister-gen: $(LISTER_GEN)
$(LISTER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/lister-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/lister-gen@$(CODEGEN_VERSION)

.PHONY: informer-gen
informer-gen: $(INFORMER_GEN)
$(INFORMER_GEN): $(LOCALBIN)
test -s $(LOCALBIN)/informer-gen || GOBIN=$(LOCALBIN) go install k8s.io/code-generator/cmd/informer-gen@$(CODEGEN_VERSION)

.PHONY: controller-gen
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.
$(CONTROLLER_GEN): $(LOCALBIN)
Expand All @@ -223,11 +305,13 @@ validate-bundle: install-operator-sdk
.PHONY: bundle
bundle: defaults manifests kustomize install-operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
$(OPERATOR_SDK) generate kustomize manifests -q
$(KUSTOMIZE) fn run config/crd/mcad --image gcr.io/kpt-fn/apply-setters:v0.2.0 -- MCAD_CRD=$(MCAD_CRD)
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
cd config/manifests && $(KUSTOMIZE) edit add patch --patch '[{"op":"add", "path":"/metadata/annotations/containerImage", "value": "$(IMG)" }]' --kind ClusterServiceVersion
cd config/manifests && $(KUSTOMIZE) edit add patch --patch '[{"op":"add", "path":"/spec/replaces", "value": "codeflare-operator.v$(PREVIOUS_VERSION)" }]' --kind ClusterServiceVersion
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle $(BUNDLE_GEN_FLAGS)
$(MAKE) validate-bundle
git restore config/*

.PHONY: bundle-build
bundle-build: bundle ## Build the bundle image.
Expand All @@ -237,6 +321,15 @@ bundle-build: bundle ## Build the bundle image.
bundle-push: ## Push the bundle image.
$(MAKE) image-push IMG=$(BUNDLE_IMG)

.PHONY: openshift-community-operator-releases
openshift-community-operator-release: install-gh-cli bundle ## build bundle and create PR in OpenShift community operators repository
gh repo clone [email protected]:project-codeflare/community-operators-prod.git
cd community-operators-prod && git pull upstream main && git push origin main
cp -r bundle community-operators-prod/operators/codeflare-operator/$(VERSION)
cd community-operators-prod && git checkout -b codeflare-release-$(VERSION) && git add operators/codeflare-operator/$(VERSION)/* && git commit -s -m "add bundle manifests codeflare version $(VERSION)" && git push origin codeflare-release-$(VERSION)
gh pr create --repo redhat-openshift-ecosystem/community-operators-prod --title "CodeFlare $(VERSION)" --body "New release of codeflare operator" --head project-codeflare:codeflare-release-$(VERSION) --base main
rm -rf community-operators-prod

.PHONY: opm
OPM = ./bin/opm
opm: ## Download opm locally if necessary.
Expand Down
1 change: 1 addition & 0 deletions OWNERS
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
approvers:
- anishasthana
- astefanutti
- jbusche
- kpostoffice
- maxusmusti
Expand Down
43 changes: 43 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,45 @@
# codeflare-operator
Operator for installation and lifecycle management of CodeFlare distributed workload stack, starting with MCAD and InstaScale

CodeFlare Stack Compatibility Matrix

| Component | Version |
|------------------------------|---------|
| CodeFlare Operator | v0.0.4 |
| Multi-Cluster App Dispatcher | v1.31.0 |
| CodeFlare-SDK | v0.4.4 |
| InstaScale | v0.0.4 |
| KubeRay | v0.5.0 |

## Release process

Prerequisite:
- Build and release [MCAD](https://github.com/project-codeflare/multi-cluster-app-dispatcher)
- Build and release [InstaScale](https://github.com/project-codeflare/instascale)
- Build and release [CodeFlare-SDK](https://github.com/project-codeflare/codeflare-sdk)

Release steps:
1. Invoke [tag-and-build.yml](https://github.com/project-codeflare/codeflare-operator/actions/workflows/tag-and-build.yml) GitHub action, this action will create a repository tag, build and push operator image.

2. Check result of [tag-and-build.yml](https://github.com/project-codeflare/codeflare-operator/actions/workflows/tag-and-build.yml) GitHub action, it should pass.

3. Update CodeFlare Stack Compatibility Matrix in operator README.

4. Update InstaScale and MCAD versions:
- in [Makefile](https://github.com/project-codeflare/codeflare-operator/blob/02e14b535b4f7172b0b809bcae4025008a1a968b/Makefile#L12-L16).
- in [mcad/deployment.yaml.tmpl](https://github.com/project-codeflare/codeflare-operator/blob/main/config/internal/mcad/deployment.yaml.tmpl#L28)
- in [controllers/defaults.go](https://github.com/project-codeflare/codeflare-operator/blob/main/controllers/defaults.go) by running `make defaults`
- in [controllers/testdata/instascale_test_results/case_1/deployment.yaml](https://github.com/project-codeflare/codeflare-operator/blob/main/controllers/testdata/instascale_test_results/case_1/deployment.yaml) and [controllers/testdata/instascale_test_results/case_2/deployment.yaml](https://github.com/project-codeflare/codeflare-operator/blob/main/controllers/testdata/instascale_test_results/case_2/deployment.yaml)

5. Create a release in CodeFlare operator repository, release notes should include new support matrix.

6. Open a pull request to OpenShift community operators repository with latest bundle using make command, check that the created PR has proper content.
```
make openshift-community-operator-release
```

7. Once merged, update component stable tags to point at the latest image release.

8. Announce the new release in slack and mail lists, if any.

9. Update the Distributed Workloads component in ODH (also copy/update the compatibility matrix).
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,8 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

// Package v1alpha1 contains API Schema definitions for the codeflare v1alpha1 API group
// +k8s:deepcopy-gen=package,register
// +kubebuilder:object:generate=true
// +groupName=codeflare.codeflare.dev
package v1alpha1

import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "codeflare.codeflare.dev", Version: "v1alpha1"}

// SchemeBuilder is used to add go types to the GroupVersionKind scheme
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}

// AddToScheme adds the types in this group-version to the given scheme.
AddToScheme = SchemeBuilder.AddToScheme
)
package v1alpha1
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type InstaScaleStatus struct {
Ready bool `json:"ready"`
}

// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

Expand All @@ -80,7 +81,3 @@ type InstaScaleList struct {
metav1.ListMeta `json:"metadata,omitempty"`
Items []InstaScale `json:"items"`
}

func init() {
SchemeBuilder.Register(&InstaScale{}, &InstaScaleList{})
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type MCADSpec struct {
// PodCreationTimeout determines timeout in milliseconds for pods to be created after dispatching job.
// +kubebuilder:default=-1
PodCreationTimeout int `json:"podCreationTimeout,omitempty"`
//podCreationTimeout: //int (default blank)
// podCreationTimeout: //int (default blank)

// ControllerResources defines the cpu and memory resource requirements for the MCAD Controller
// +kubebuilder:default={}
Expand All @@ -63,8 +63,9 @@ type MCADStatus struct {
Ready bool `json:"ready"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// MCAD is the Schema for the mcads API
type MCAD struct {
Expand All @@ -75,15 +76,11 @@ type MCAD struct {
Status MCADStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true
// +kubebuilder:object:root=true

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

func init() {
SchemeBuilder.Register(&MCAD{}, &MCADList{})
}
Loading

0 comments on commit 73a39af

Please sign in to comment.