Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: mayadata-io/d-operators
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v1.28.0
Choose a base ref
...
head repository: mayadata-io/d-operators
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 3 commits
  • 49 files changed
  • 2 contributors

Commits on Jan 4, 2021

  1. feat(crd): use unstructured type inplace of typed crd instance (#187)

    This commit makes exhaustive changes to handle CRD instances.
    CRD instances make use of unstructured types instead of typed
    instances. Both CRD versions i.e. v1beta1 & v1 are supported.
    
    Unstructured instances have proved to be generic & testable
    versus the typed counterparts especially for CRD schemas that
    can differ from each other. In other words, CRD schemas have a
    majority schemaless section that is well handled via
    unstructured type.
    
    This commit also includes a number of integration test cases
    to avoid bug injections if any.
    
    This closes #186
    partially. A better approach will be to use latest version of
    d-operators with clients that make use of unstructured instances
    directly instead of yaml strings that get converted to go
    structures.
    
    This commit is also a breaking change, since some of the
    structures have been modified. Clients that are already making use
    of this structure need to be modified accordingly.
    
    Signed-off-by: AmitKumarDas <[email protected]>
    Amit Kumar Das authored Jan 4, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    5fc998d View commit details

Commits on Feb 9, 2021

  1. chore(testing): update readme w.r.t programmatic vs declarative testi…

    …ng (#188)
    
    This commit makes changes to clearly indicate programmatic as well
    declarative way to test D-operators' Kubernetes controllers.
    
    It is important to note that the same model can be followed by other
    Operators repo if needed. This model has worked fine so far. It makes
    use of GitHub VM as launching machine & same VM used as a single node
    K3s cluster to run the tests (both declarative as well as programmatic).
    
    Signed-off-by: AmitKumarDas <[email protected]>
    Amit Kumar Das authored Feb 9, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ad823c7 View commit details

Commits on Feb 17, 2021

  1. feat(command): add support to delete dependants of command resource (#…

    …189)
    
    * feat(command): add support to delete dependents of command resource
    
    This PR does the following changes:
    - Add support to delete dependent resources when command resource is
      deleted.
    - Add support to launch the jobs periodically when command is configured
      for run always
    
    Signed-off-by: mittachaitu <[email protected]>
    sai chaithanya authored Feb 17, 2021

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a61dfc0 View commit details
Showing with 3,179 additions and 787 deletions.
  1. +8 −14 .github/workflows/test-release.yaml
  2. +1 −1 .gitignore
  3. +6 −4 Makefile
  4. +17 −11 README.md
  5. +8 −6 cmd/main.go
  6. +49 −1 config/metac.yaml
  7. +57 −0 controller/command/finalizer.go
  8. +11 −0 controller/command/reconciler.go
  9. +1 −1 deploy/crd.yaml
  10. +1 −0 go.mod
  11. +95 −11 pkg/command/reconciler.go
  12. +150 −92 pkg/command/reconciler_test.go
  13. +20 −394 pkg/recipe/apply.go
  14. +335 −0 pkg/recipe/apply_int_test.go
  15. +248 −0 pkg/recipe/crd.go
  16. +124 −0 pkg/recipe/crd_test.go
  17. +122 −0 pkg/recipe/crd_v1.go
  18. +230 −0 pkg/recipe/crd_v1_int_test.go
  19. +99 −0 pkg/recipe/crd_v1beta1.go
  20. +135 −0 pkg/recipe/crd_v1beta1_int_test.go
  21. +21 −194 pkg/recipe/create.go
  22. +235 −0 pkg/recipe/create_int_test.go
  23. +31 −2 pkg/recipe/fixture.go
  24. +18 −42 pkg/recipe/list.go
  25. +349 −0 pkg/recipe/list_int_crds_test.go
  26. +168 −0 pkg/recipe/list_int_items_test.go
  27. 0 pkg/recipe/{labeling_int_test.go → recipe_int_labeling_test.go}
  28. +159 −0 pkg/recipe/recipe_int_list_test.go
  29. +163 −0 pkg/recipe/recipe_int_simple_test.go
  30. 0 test/{e2e → declarative}/BEST_PRACTICES.md
  31. +26 −1 test/{e2e → declarative}/ci.yaml
  32. 0 test/{ → declarative}/experiments/assert-deprecated-daemonset.yaml
  33. 0 test/{ → declarative}/experiments/assert-github-search-invalid-method-neg.yaml
  34. 0 test/{ → declarative}/experiments/assert-github-search-invalid-method.yaml
  35. 0 test/{ → declarative}/experiments/assert-lock-persists-for-recipe-that-runs-once.yaml
  36. 0 test/{ → declarative}/experiments/assert-recipe-invalid-schema.yaml
  37. 0 test/{ → declarative}/experiments/assert-recipe-lock-is-garbage-collected.yaml
  38. 0 test/{ → declarative}/experiments/assert-recipe-teardown.yaml
  39. +232 −0 test/declarative/experiments/command-creation-deletion.yaml
  40. 0 test/{ → declarative}/experiments/create-assert-fifty-configmaps-in-time.yaml
  41. 0 test/{ → declarative}/experiments/create-assert-fifty-configmaps.yaml
  42. 0 test/{ → declarative}/experiments/crud-ops-on-pod.yaml
  43. +3 −3 test/{e2e → declarative}/inference.yaml
  44. 0 test/{e2e → declarative}/registries.yaml
  45. +15 −2 test/{e2e → declarative}/suite.sh
  46. +13 −6 test/integration/suite.sh
  47. +1 −1 types/command/command.go
  48. +15 −1 types/recipe/create.go
  49. +13 −0 types/recipe/list.go
22 changes: 8 additions & 14 deletions .github/workflows/test-release.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
---
name: Unit Test, E to E Test and Github Release (if on master)
name: Testing and Github Release (if on master)
on: [push, pull_request]
jobs:
unittest:
runs-on: ubuntu-18.04
strategy:
matrix:
test: ['test']
name: ${{ matrix.test }}
name: Unit Test
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Setup Golang
uses: actions/setup-go@v2
with:
go-version: 1.13.5
- run: make ${{ matrix.test }}
- run: make test
integrationtest:
runs-on: ubuntu-18.04
name: integrationtest
name: Integration Test
steps:
- name: Checkout Code
uses: actions/checkout@v2
@@ -27,24 +24,21 @@ jobs:
with:
go-version: 1.13.5
- run: sudo make integration-test-suite
e2etest:
declarativetest:
runs-on: ubuntu-18.04
strategy:
matrix:
test: ['e2e-test']
name: ${{ matrix.test }}
name: Declarative Test
steps:
- name: Checkout Code
uses: actions/checkout@v2
- name: Setup Golang
uses: actions/setup-go@v2
with:
go-version: 1.13.5
- run: sudo make ${{ matrix.test }}
- run: sudo make declarative-test-suite
release:
name: Make Github Release
runs-on: ubuntu-18.04
needs: ['unittest', 'e2etest', 'integrationtest']
needs: ['unittest', 'declarativetest', 'integrationtest']
steps:
- name: Checkout Code
uses: actions/checkout@v1
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ tools/d-action/vendor/
d-operators
test/bin/
test/kubebin/
test/e2e/uninstall-k3s.txt
test/declarative/uninstall-k3s.txt
test/integration/uninstall-k3s.txt
uninstall-k3s.txt
dope
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -35,12 +35,14 @@ testv:
@go test ./... -cover -v -args --logtostderr -v=2

.PHONY: integration-test
integration-test:
integration-test:
# Uncomment to list verbose output
# @go test ./... -cover --tags=integration -v -args --logtostderr -v=1
@go test ./... -cover --tags=integration

.PHONY: e2e-test
e2e-test:
@cd test/e2e && ./suite.sh
.PHONY: declarative-test-suite
declarative-test-suite:
@cd test/declarative && ./suite.sh

.PHONY: integration-test-suite
integration-test-suite:
28 changes: 17 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -54,34 +54,40 @@ It is important to understand that these declarative patterns are built upon pro
### When to use D-operators
D-operators is not meant to build complex controller logic like Deployment, StatefulSet or Pod in a declarative yaml. However, if one needs to use available Kubernetes resources to build new k8s controller(s) then d-operators should be considered to build one. D-operators helps implement the last mile automation needed to manage applications & infrastructure in Kubernetes clusters.
### E to E testing
### Declarative Testing
D-operators make use of its custom resource(s) to test its controllers. One can imagine these custom resources acting as the building blocks to implement a custom CI framework. One of the primary advantages with this approach, is to let custom resources remove the need to write code to implement test cases.
_NOTE: One can make use of these YAMLs (kind: Recipe) to test their own Kubernetes controllers declaratively_
_NOTE: One can make use of these YAMLs (kind: Recipe) to test any Kubernetes controllers declaratively_
Navigate to test/experiments to learn more on these YAMLs.
Navigate to test/declarative/experiments to learn more on these YAMLs.
```sh
# Following runs the e2e test suite
# Following runs the declarative test suite
#
# NOTE: test/e2e/suite.sh does the following:
# NOTE: test/declarative/suite.sh does the following:
# - d-operators' image known as 'dope' is built
# - a docker container is started & acts as the image registry
# - dope image is pushed to this image registry
# - k3s is installed with above image registry
# - d-operators' manifests are applied
# - experiments _(i.e. test code written as YAMLs)_ are applied
# - experiments are asserted
# - if all experiments pass then e2e is a success else it failed
# - if all experiments pass then this testing is a success else it failed
# - k3s is un-installed
# - local image registry is stopped
sudo make e2e-test
sudo make declarative-test-suite
```

### Deploying experiments using D-operators
To deploy experiments using d-operators apply the below commands:
- kubectl apply -f deploy/
- kubectl apply -f test/experiments/<experiment-yaml>
### Programmatic Testing
D-operators also lets one to write testing Kubernetes controllers using Golang. This involves building the docker image (refer Dockerfile.testing) of the entire codebase and letting it run as a Kubernetes pod (refer test/integration/it.yaml). The setup required run these tests can be found at test/integration folder. Actual test logic are regular _test.go files found in respective packages. These _test.go files need to be tagged appropriately. These mode of testing has the additional advantage of getting the code coverage.

```go
// +build integration
```

```sh
make integration-test-suite
```

### Available Kubernetes controllers
- [x] kind: Recipe
14 changes: 8 additions & 6 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -62,13 +62,15 @@ func main() {

// controller name & corresponding controller reconcile function
var controllers = map[string]generic.InlineInvokeFn{
"sync/recipe": recipe.Sync,
"finalize/recipe": recipe.Finalize,
"sync/http": http.Sync,
"sync/doperator": doperator.Sync,
"sync/run": run.Sync,
"sync/command": command.Sync,
"sync/recipe": recipe.Sync,
"finalize/recipe": recipe.Finalize,
"sync/http": http.Sync,
"sync/doperator": doperator.Sync,
"sync/run": run.Sync,
"sync/command": command.Sync,
"finalize/command": command.Finalize,
}

for name, ctrl := range controllers {
generic.AddToInlineRegistry(name, ctrl)
}
50 changes: 49 additions & 1 deletion config/metac.yaml
Original file line number Diff line number Diff line change
@@ -64,4 +64,52 @@ spec:
hooks:
sync:
inline:
funcName: sync/command
funcName: sync/command
---
apiVersion: dope/v1
kind: GenericController
metadata:
name: finalize-command
namespace: dope
spec:
watch:
apiVersion: dope.mayadata.io/v1
resource: commands
attachments:
# Delete pod
- apiVersion: v1
resource: pods
advancedSelector:
selectorTerms:
# select Pod if its labels has following
- matchReferenceExpressions:
- key: metadata.namespace
operator: EqualsWatchNamespace
- key: metadata.labels.job-name
operator: EqualsWatchName # match this lbl value against watch Name
# Delete job
- apiVersion: batch/v1
resource: jobs
advancedSelector:
selectorTerms:
# select job if its labels has following
- matchLabels:
command.dope.mayadata.io/controller: "true"
matchReferenceExpressions:
- key: metadata.labels.command\.dope\.mayadata\.io/uid
operator: EqualsWatchUID # match this lbl value against watch UID
- apiVersion: v1
resource: configmaps
advancedSelector:
selectorTerms:
# select ConfigMap if its labels has following
- matchLabels:
command.dope.mayadata.io/lock: "true"
matchReferenceExpressions:
- key: metadata.labels.command\.dope\.mayadata\.io/uid
operator: EqualsWatchUID # match this lbl value against watch Name
hooks:
finalize:
inline:
funcName: finalize/command
---
57 changes: 57 additions & 0 deletions controller/command/finalizer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
Copyright 2020 The MayaData Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package command

import (
"openebs.io/metac/controller/generic"
)

var (
defaultDeletionResyncTime = float64(30)
)

// Finalize implements the idempotent logic that gets executed when
// Command instance is deleted. A Command instance may have child job &
// dedicated lock in form of a ConfigMap.
// Finalize logic tries to delete child pod, job & ConfigMap
//
// NOTE:
// When finalize hook is set in the config metac automatically sets
// a finalizer entry against the Command metadata's finalizers field .
// This finalizer entry is removed when SyncHookResponse's Finalized
// field is set to true
//
// NOTE:
// SyncHookRequest is the payload received as part of finalize
// request. Similarly, SyncHookResponse is the payload sent as a
// response as part of finalize request.
//
// NOTE:
// Returning error will panic this process. We would rather want this
// controller to run continuously. Hence, the errors are handled.
func Finalize(request *generic.SyncHookRequest, response *generic.SyncHookResponse) error {
if request.Attachments.IsEmpty() {
// Since no Dependents found it is safe to delete Command
response.Finalized = true
return nil
}

response.ResyncAfterSeconds = defaultDeletionResyncTime
// Observed attachments will get deleted
response.ExplicitDeletes = request.Attachments.List()
return nil
}
11 changes: 11 additions & 0 deletions controller/command/reconciler.go
Original file line number Diff line number Diff line change
@@ -61,6 +61,17 @@ func (r *Reconciler) eval() {
}

func (r *Reconciler) sync() {
// Check for deletion timestamp on command resource
// if set then command is marked for deletion
if !r.observedCommand.DeletionTimestamp.IsZero() {
klog.V(1).Infof(
"Will skip command reconciliation: It is marked for deletion: Command %q / %q",
r.observedCommand.GetNamespace(),
r.observedCommand.GetName(),
)
return
}

// creating / deleting a Kubernetes Job is part of Command reconciliation
jobBuilder := command.NewJobBuilder(
command.JobBuildingConfig{
2 changes: 1 addition & 1 deletion deploy/crd.yaml
Original file line number Diff line number Diff line change
@@ -83,4 +83,4 @@ spec:
versions:
- name: v1
served: true
storage: true
storage: true
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ module mayadata.io/d-operators
go 1.13

require (
github.com/ghodss/yaml v1.0.0
github.com/go-resty/resty/v2 v2.2.0
github.com/google/go-cmp v0.4.0
github.com/pkg/errors v0.9.1
Loading