-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(controller-runtime): Implement stream controller (#211)
* Add account, consumer and stream controller stubs to be implemented Controllers and tests are based on files generated by operator-sdk. Adds a minimal test suite for the controllers with a etcd test env and a test nats jetStream server to test against. * Add logs to Reconcile functions * Add jsClient to test suit variables * Remove format from log string * Make upsertCondition public to be used in new controllers * Implement basic cases for stream reconciliation See TODOs on what still needs to be implemented. * refactor to use shared base controller * Support jetstream connection options in stream spec * implement stream deletion * update observedGeneration of status * check Spec.PreventDelete before stream deletion * remove base js client Use a single use client on every connection. This should be replaced by a client pool in the future. * move asJsonString to jetstream_controller * check namespace read only and prevent update mode * Update comments and log * Fix test docs and check precondition * Add preventUpdate test cases * Add tests for read-only or namespace restricted mode * fix empty ca when no ca set Setting CAs: []string{*ca} resulted in []string{""} when no CA was set, leading to an error when creating clients. * simplify error message * fix error loop when the underlying stream was deleted * refactor each phase into separate method * Fix errors during parallel reconciliation & Refactor tests - Trigger only on generation changes - Split initialization and create into separate calls to Reconcile * make test description strings more uniform * Update docs and log messages * extract configuration to buildNatsConfig method * fix checking for preventDelete in the update step Instead check for preventUpdate. Introduced during refactor. * fix k8s binaries not downloaded for tests * add /bin to gitignore * rename stream helper functions Prefix with stream to prevent conflict with other resources. * update naming as suggested * fix assumed reason in log message * Update todo comments marked with review - Add note on opts.Account - Add comment on possible feature to expose TLSFirst in the spec. * separate CA config from client cert and key * set streamName and consumerName fields once on logger Reword log messages.
- Loading branch information
1 parent
895dc1c
commit 0f218f5
Showing
20 changed files
with
1,440 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,4 +18,5 @@ | |
/nats-boot-config | ||
/nats-boot-config.docker | ||
/tools | ||
/bin | ||
/.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package controller | ||
|
||
import ( | ||
api "github.com/nats-io/nack/pkg/jetstream/apis/jetstream/v1beta2" | ||
"github.com/nats-io/nats-server/v2/server" | ||
natsserver "github.com/nats-io/nats-server/v2/test" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
v1 "k8s.io/api/core/v1" | ||
|
||
"os" | ||
"time" | ||
) | ||
|
||
func assertReadyStateMatches(condition api.Condition, status v1.ConditionStatus, reason string, message string, transitionTime time.Time) { | ||
GinkgoHelper() | ||
|
||
Expect(condition.Type).To(Equal(readyCondType)) | ||
Expect(condition.Status).To(Equal(status)) | ||
Expect(condition.Reason).To(Equal(reason)) | ||
Expect(condition.Message).To(ContainSubstring(message)) | ||
|
||
// Assert valid transition time | ||
t, err := time.Parse(time.RFC3339Nano, condition.LastTransitionTime) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(t).To(BeTemporally("~", transitionTime, time.Second)) | ||
} | ||
|
||
func CreateTestServer() *server.Server { | ||
opts := &natsserver.DefaultTestOptions | ||
opts.JetStream = true | ||
opts.Port = -1 | ||
opts.Debug = true | ||
|
||
dir, err := os.MkdirTemp("", "nats-*") | ||
Expect(err).NotTo(HaveOccurred()) | ||
opts.StoreDir = dir | ||
|
||
ns := natsserver.RunServer(opts) | ||
Expect(err).NotTo(HaveOccurred()) | ||
|
||
return ns | ||
} |
Oops, something went wrong.