Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
542 commits
Select commit Hold shift + click to select a range
c1a4e3e
changed function call for deferred events to processEvent
mcdillson May 18, 2026
21680f1
added error returns to applyEvent
mcdillson May 18, 2026
cca49bb
changed order of label copying
mcdillson May 18, 2026
f282938
fixed failing label test
mcdillson May 18, 2026
6afd0a6
Merge branch 'feat/target-creation' into feature/discovery-e2e-implem…
mcdillson May 18, 2026
b4153e7
Merge branch 'feature/pull-interface' into feature/discovery-e2e-impl…
mcdillson May 18, 2026
a8a55b6
fixed integration test resources for new DiscoveredTarget
mcdillson May 19, 2026
e802c7d
fix unit tests
Janooski May 20, 2026
0929af4
auth refactor
Janooski May 20, 2026
73a2773
change gin default router
Janooski May 20, 2026
9d35608
update targetsource
denyost May 14, 2026
bcc0b4f
cherry-pick 5d95c90: DiscoveredTarget type changes
mcdillson May 20, 2026
d523adb
renamed IP to Address
mcdillson May 20, 2026
2c0d7cb
disabled JWTAuthSpec validations
mcdillson May 20, 2026
77a5bd4
cherry-pick 6a83f49: added TargetProfile variable to DiscoveredTarget
mcdillson May 21, 2026
2d1f5fb
updated targetSource guide based on new CRD
mcdillson May 21, 2026
abbbee4
renamed response field ip to address
mcdillson May 21, 2026
21496fc
moved http into a subfile of TargetSource
mcdillson May 21, 2026
db090b3
restructured http chapter hierarchy
mcdillson May 21, 2026
69d82bb
changed example router names
mcdillson May 21, 2026
85571f4
return if pagination field is empty
denyost May 21, 2026
8cdd529
refactor
denyost May 21, 2026
f94e8d1
use itemsField independent of pagination
denyost May 21, 2026
29f201f
rename ItemsField to TargetsField
denyost May 21, 2026
4d008c2
make tls caBundle more user friendly
denyost May 21, 2026
a69abdd
increase default poll interval
denyost May 21, 2026
7adee4b
add acceptPush
Janooski May 21, 2026
4342d66
refactor fetchTargetsFromHTTPEndpoint
denyost May 21, 2026
7c1931d
Merge branch 'feature/discovery-e2e-implementation' into feature/push…
Janooski May 21, 2026
f158b53
openapi: correct routeloading, support udpated target fields
Janooski May 21, 2026
b9fd2dd
contract rendered as md
Janooski May 21, 2026
b2092c1
add _index.md
Janooski May 21, 2026
14883c9
move header to README.md
Janooski May 21, 2026
4f06a21
Merge branch 'main' into feature/type-updates
mcdillson May 21, 2026
0d744ba
added port + targetProfile handling to mapper
mcdillson May 21, 2026
5b612f2
added webhook spec for authorization
mcdillson May 21, 2026
58b77d4
removed inline credential fields
mcdillson May 21, 2026
aa023ab
use itemsField independent of pagination
denyost May 21, 2026
fc6008d
rename ItemsField to TargetsField
denyost May 21, 2026
0c1b414
changed assertion to new webhook spec
mcdillson May 21, 2026
7e06e14
moved TargetsField to ResponseMappingSpec
mcdillson May 21, 2026
421d40f
changed validation rule for url or webhook
mcdillson May 21, 2026
85c46b5
reworked kubebuilder validations
mcdillson May 21, 2026
e7a62df
generated manifests
mcdillson May 21, 2026
513e539
update targetsource CRD
denyost May 22, 2026
bc2182f
cleanup secret fetching
denyost May 22, 2026
022ed92
refactor
denyost May 22, 2026
214810c
removed old webhook statements
mcdillson May 22, 2026
89bfbf5
changed pushSpec comment
mcdillson May 22, 2026
feb3717
Merge branch 'feature/type-updates' of https://github.com/gnmic/opera…
denyost May 22, 2026
0e14751
update webhook to push
denyost May 22, 2026
8d9730f
Merge branch 'feature/type-updates' of https://github.com/gnmic/opera…
denyost May 22, 2026
51cbf8c
Merge branch 'feature/type-updates' of https://github.com/gnmic/opera…
denyost May 22, 2026
e8c298e
fix after unlean merge
denyost May 22, 2026
b62f3f5
refactor CRD
denyost May 22, 2026
b3f4bbb
Merge branch 'feature/type-updates' of https://github.com/gnmic/opera…
denyost May 22, 2026
f390eae
fixes after merge
denyost May 22, 2026
722f53c
fix ip/address after merge
denyost May 22, 2026
d5be9a8
implement secret and configmap fetcher
denyost May 22, 2026
647e2a9
replace JSONPath mapping with CEL mapping
denyost May 22, 2026
1a486b1
update targetsource base
denyost May 22, 2026
b931a02
mapping of labels via CEL
denyost May 23, 2026
c2d49cb
fix nil pointer issue
denyost May 25, 2026
a9ddacd
remove missleading old comment
denyost May 25, 2026
f4fcf78
enable CEL extensions for advanced mapping
denyost May 25, 2026
0995dfe
fix: add optional types for CEL regex
denyost May 25, 2026
5c337e6
fix CEL OptionalTypes order
denyost May 25, 2026
eecee72
add support for POST and custom headers and body
denyost May 25, 2026
8a17aad
Handle different map representations returned by CEL
denyost May 25, 2026
1316082
changed interface{} to any
denyost May 25, 2026
c4a553c
normalize CEL returns
denyost May 25, 2026
c6d751e
Merge branch 'main' into testing/message_processor
mcdillson May 25, 2026
fe4c4d6
added SyncStatus values to CRD
mcdillson May 25, 2026
ad6394b
generated manifests
mcdillson May 25, 2026
70594fc
added interface for StatusUpdate
mcdillson May 25, 2026
9396550
simplify normalization of maps for CEL
denyost May 27, 2026
aea803e
refactor improve readability of getLabels
denyost May 27, 2026
dfbdc54
set default http method in targetsource_types
denyost May 27, 2026
522e8bf
refactor buildHTTPClient and add guards
denyost May 27, 2026
3ef7a45
refactor timeout error
denyost May 27, 2026
01c28b4
add guards for default values
denyost May 27, 2026
3f77f8a
refactor basic auth authorization
denyost May 27, 2026
99d32a8
refactor reduce complexity of applyAuthorization
denyost May 27, 2026
6ab7731
refactor: reduce complexity of buildHTTPClient
denyost May 27, 2026
a020b2a
add unit tests
denyost May 27, 2026
34dea8a
changed status to include conditions and implemented interface
mcdillson May 27, 2026
3acfad4
Merge branch 'feature/status-updates' into ba-submission
mcdillson May 27, 2026
a868d5f
Merge branch 'testing/message_processor' into ba-submission
mcdillson May 27, 2026
8255f83
Merge branch 'main' into feature/push-interface
mcdillson May 27, 2026
a7747be
Merge branch 'feature/pull-interface' into feature/push-interface
mcdillson May 27, 2026
0f7a7c9
Merge branch 'feature/push-interface' into ba-submission
mcdillson May 27, 2026
47afe12
fix function call for Loader.Run()
mcdillson May 27, 2026
2453ebb
Merge branch 'feature/push-interface' into ba-submission
mcdillson May 27, 2026
bc3c2c6
fixed http integration test resources based on type changes
mcdillson May 28, 2026
4600fde
Merge branch 'feature/type-updates' into feature/push-interface
mcdillson May 28, 2026
10aee05
changed StatusUpdater functions to use only UpdateStatus() and create…
mcdillson May 29, 2026
db42ddf
added http targetsource to integration tests
mcdillson May 29, 2026
c6383e7
added targetsources to apply-test-resources
mcdillson May 29, 2026
e6fbf37
Merge branch 'feature/type-updates' into feature/status-updates
mcdillson May 29, 2026
69bab6b
go mod tidy
mcdillson May 29, 2026
7e11067
ran go mod tidy
mcdillson May 29, 2026
19c0082
Merge branch 'feature/type-updates' into feature/status-updates
mcdillson May 29, 2026
a1d9e49
fixed nil pointer reference in loader instantiation
mcdillson May 29, 2026
453af40
Merge branch 'feature/type-updates' into feature/status-updates
mcdillson May 29, 2026
9f10e4a
changed loader to comply with integration test
mcdillson May 29, 2026
f505630
Merge branch 'feature/type-updates' into feature/status-updates
mcdillson May 29, 2026
7c34171
update http provider documentation
denyost May 29, 2026
28d8027
tune the http provider doc
denyost May 29, 2026
00db2cc
update default values
denyost May 29, 2026
929a4c2
update default value of timeout
denyost May 29, 2026
c3fe3ca
fix CEL expression
denyost May 29, 2026
67b546c
remove todos
denyost May 29, 2026
63504e4
remove info logging for development
denyost May 29, 2026
0389b9f
docs: update pull mode
denyost May 29, 2026
5152917
update pagination: add scheme for Link headers and support CEL for se…
denyost May 29, 2026
e3eefb3
apply target updates done in demo/autodiscover
Janooski Jun 1, 2026
9117981
remove documentaiton
Janooski Jun 1, 2026
0296f9e
remove generated openAPI documentation
Janooski Jun 1, 2026
31fd036
update docs pagination and hybrid CEL mapping
denyost Jun 1, 2026
422767d
add noAuthentication as an option
Janooski Jun 1, 2026
11b954c
Merge branch 'feature/push-interface' of github.com:gnmic/operator in…
Janooski Jun 1, 2026
c12683d
add Netbox example
denyost Jun 1, 2026
b9ddb8b
imporve export template documentation
denyost Jun 1, 2026
9b7dc0b
docs: made TargetProfile optional
mcdillson Jun 1, 2026
24ea9cc
made targetProfile optional
mcdillson Jun 1, 2026
b479017
changed authorization to authentication
mcdillson Jun 1, 2026
926c40f
renamed AuthorizationSpec to AuthenticationSpec
mcdillson Jun 1, 2026
5086648
add netbox rest api example
denyost Jun 2, 2026
fc6af9c
fix incorrect namespace
denyost Jun 2, 2026
f0d63ff
update netbox export template guide
denyost Jun 2, 2026
0a2bc2b
Merge branch 'docs/targetsource-userguide' of https://github.com/gnmi…
denyost Jun 2, 2026
8aa4ac8
update authorization to authentication
denyost Jun 2, 2026
c3c58af
re-word credentialsSecretRef
denyost Jun 2, 2026
649aa33
re-word CredentialsSecretRef
denyost Jun 2, 2026
9e5b461
Merge branch 'feature/type-updates' of https://github.com/gnmic/opera…
denyost Jun 2, 2026
9f2dc6d
temporarily add working targetsource definitions
Janooski Jun 3, 2026
52cb668
push interface integration test
Janooski Jun 3, 2026
4fcc001
fix configmap file
Janooski Jun 3, 2026
62a53d9
adjust when e2e tests run
Janooski Jun 3, 2026
c7d1e7b
Merge branch 'feature/push-interface' into feature/discovery-e2e-impl…
Janooski Jun 3, 2026
04b97f8
adjust makefile syntax
Janooski Jun 3, 2026
76a620f
change url of curl
Janooski Jun 3, 2026
536ad0d
sleep 3s after port-forwarding
Janooski Jun 3, 2026
91decfe
udpate configmap
Jun 3, 2026
1adf4c5
e2e worked locally
Janooski Jun 3, 2026
279aa3c
Merge branch 'feature/discovery-e2e-implementation-push' of github.co…
Janooski Jun 3, 2026
c82a6f2
file cleanup
Janooski Jun 3, 2026
e102525
Merge pull request #88 from gnmic/feature/discovery-e2e-implementatio…
Janooski Jun 3, 2026
eaab66b
Merge branch 'feature/pull-interface' into feature/status-updates
mcdillson Jun 3, 2026
ad8a5a1
add check if push-interface is turned on
Janooski Jun 3, 2026
72c8bb6
added status updates to http loader
mcdillson Jun 3, 2026
878b946
added fake status updater for unit tests
mcdillson Jun 3, 2026
62c0c40
added interval to http resource
mcdillson Jun 3, 2026
ec45b03
add push config into common loader config
denyost Jun 4, 2026
2487b0d
refactor auth
Janooski Jun 4, 2026
43f0531
Merge branch 'feature/push-interface' of github.com:gnmic/operator in…
Janooski Jun 4, 2026
99d6bf7
fix reconcile bug
denyost Jun 4, 2026
5293eb6
Merge branch 'feature/push-interface' of github.com:gnmic/operator in…
Janooski Jun 4, 2026
7ea9ade
update targetsource structure
denyost Jun 4, 2026
918e132
push interface turned off works
Janooski Jun 4, 2026
6050368
ad subsecrtion targetsource provider
denyost Jun 4, 2026
4496527
bearer auth working again
Janooski Jun 4, 2026
6fc57fc
update reference
denyost Jun 4, 2026
89feb1d
update weights
denyost Jun 4, 2026
1643d48
update description
denyost Jun 4, 2026
bc456c5
update reference
denyost Jun 4, 2026
93f7a42
refactor BearerToken
Janooski Jun 4, 2026
0154766
refactor titles
denyost Jun 4, 2026
28e84d1
refactor http provider
denyost Jun 4, 2026
35ee9db
signature verification added
Janooski Jun 4, 2026
4db09f7
signature and bearer work combined
Janooski Jun 4, 2026
cf1104c
update netbox examples
denyost Jun 4, 2026
9fbb433
comment out relref
denyost Jun 4, 2026
80021b7
comment out relref
denyost Jun 4, 2026
9112eaf
comment out relref
denyost Jun 4, 2026
46ca88d
comment out links
denyost Jun 4, 2026
4ac7261
comment out netbox examples
denyost Jun 4, 2026
f9ea7cc
simplified label structure to map
Janooski Jun 4, 2026
e43fcda
try finding docu compiling error
denyost Jun 4, 2026
1d9d1e3
Merge branch 'feature/push-interface' into feature/discovery-e2e-impl…
Janooski Jun 4, 2026
3bd1c1e
try finding compile error
denyost Jun 4, 2026
c456806
add example folder NetBox
denyost Jun 4, 2026
ef97608
add example Netbox Export Template
denyost Jun 4, 2026
7a64601
minimize export template example
denyost Jun 4, 2026
3cd9666
add step 1
denyost Jun 4, 2026
9fb54c3
add step 2 & 3
denyost Jun 4, 2026
fcbd339
remove relref
denyost Jun 4, 2026
1dd827c
complete example without relrefs
denyost Jun 4, 2026
0bfd762
create secrets for apiserver e2e test
Janooski Jun 4, 2026
0da0fb0
add relrefs
denyost Jun 4, 2026
20accaa
add one relref
denyost Jun 4, 2026
47918d7
update relref
denyost Jun 4, 2026
e2d6000
replace relref
denyost Jun 4, 2026
36017a3
fix send-taret-to-apiserver make target
Janooski Jun 4, 2026
1d3f577
add rest api examples
denyost Jun 4, 2026
301abf9
Merge branch 'docs/targetsource-userguide' of github.com:gnmic/operat…
Janooski Jun 4, 2026
5642881
read netbox secret from correct namespace
Janooski Jun 4, 2026
8eb156e
update doc entry
denyost Jun 5, 2026
00555b4
generate docs
Janooski Jun 8, 2026
ad2b377
add header to generated md
Janooski Jun 8, 2026
3a0f5c8
tests with markdown templates
Janooski Jun 8, 2026
131d838
fix links
Janooski Jun 8, 2026
a7c6321
udpate folder structure
Janooski Jun 8, 2026
7aec4c2
fix links, cleanup some text
Janooski Jun 8, 2026
7732cb4
update inline md links
Janooski Jun 8, 2026
6d6c720
add signature
Janooski Jun 8, 2026
0424404
paths again and small corrections
Janooski Jun 8, 2026
ede85b6
remove #section hyperlink
Janooski Jun 8, 2026
8e8e251
add push-interface document structure
Janooski Jun 8, 2026
562fbb2
Merge branch 'main' of https://github.com/gnmic/operator into feature…
denyost Jun 8, 2026
5773c1a
fix targetsource types
denyost Jun 8, 2026
8d5a4a9
remove unused import
denyost Jun 8, 2026
871f42f
fix targetsource types
denyost Jun 8, 2026
7bc8886
first version push
Janooski Jun 8, 2026
6070547
Merge branch 'feature/pull-interface' into feature/status-updates
mcdillson Jun 8, 2026
5df4894
moved statusUpdater implementation
mcdillson Jun 8, 2026
a4cdf03
add Netbox webhook example
Janooski Jun 8, 2026
f0de865
Merge branch 'feature/pull-interface' into ba-submission
mcdillson Jun 8, 2026
9a20e71
Merge branch 'feature/status-updates' into ba-submission
mcdillson Jun 8, 2026
b17bf93
small grammar changes
Janooski Jun 8, 2026
5e5cca7
fix pages build
Janooski Jun 8, 2026
a9ad35f
remove unneeded files, cleanup
Janooski Jun 8, 2026
3246ecd
check OperationResult to correctly increment counter on event updates
mcdillson Jun 9, 2026
2ca8cbc
Merge branch 'feature/status-updates' into ba-submission
mcdillson Jun 9, 2026
0fb42a2
minor fixes
mcdillson Jun 9, 2026
5394f55
update recommended patterns of CEL expressions
denyost Jun 9, 2026
30bc076
Merge branch 'feature/pull-interface' into feature/discovery-e2e-impl…
mcdillson Jun 9, 2026
097612c
Merge branch 'feature/discovery-e2e-implementation' into ba-submission
mcdillson Jun 9, 2026
eeb23a1
added fakeStatusUpdater to MessageProcessor tests
mcdillson Jun 9, 2026
8984109
update webhook example
Janooski Jun 10, 2026
b2a27d7
remove link
Janooski Jun 10, 2026
a8dae87
restructure moustache templates
Janooski Jun 10, 2026
ea113ae
upate cluster address section
Janooski Jun 10, 2026
0d4d01c
add lines, fix title
Janooski Jun 10, 2026
34a8fc5
update descriptions on openAPI contract
Janooski Jun 10, 2026
8dc9304
pin netbox version, keep make netbox-sync-data working
Janooski Jun 10, 2026
89815fc
remove pointer on address
Janooski Jun 10, 2026
c24bb22
Merge branch 'feature/push-interface' into ba-submission
Janooski Jun 10, 2026
dde381a
updates after example playthrough
Janooski Jun 10, 2026
2fa4fd5
Merge branch 'docs/targetsource-userguide' of github.com:gnmic/operat…
Janooski Jun 10, 2026
aec169b
Merge branch 'docs/targetsource-userguide' into docs/targetsource-use…
Janooski Jun 10, 2026
c26889a
Merge pull request #91 from gnmic/docs/targetsource-userguide-push
Janooski Jun 10, 2026
979d7e6
run pipeline again
Janooski Jun 10, 2026
cb717ef
remove folders from .gitignore
Janooski Jun 10, 2026
36a1736
Merge branch 'docs/targetsource-userguide' into ba-submission
Janooski Jun 10, 2026
c93282c
Merge branch 'ba-submission' of github.com:gnmic/operator into ba-sub…
Janooski Jun 10, 2026
1ddabf2
add comments to targetsource types
Janooski Jun 10, 2026
297bf9b
Merge branch 'feature/push-interface' into ba-submission
Janooski Jun 10, 2026
5b689e1
Merge branch 'ba-submission' of github.com:gnmic/operator into ba-sub…
Janooski Jun 10, 2026
7f62a01
refactoring based on sonarqube
mcdillson Jun 12, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ docs/public
docs/resources/_gen/
docs/.hugo_build.lock
test/integration/**/clab-*
test/integration/clab-*
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ delete-outputs-dev-lab: ## Delete the outputs for the development lab cluster
kubectl delete -f lab/dev/resources/outputs

.PHONY: apply-pipelines-dev-lab
apply-pipelines-dev-lab: ## Apply the pipelines for the development lab cluster
§apply-pipelines-dev-lab: ## Apply the pipelines for the development lab cluster
kubectl apply -f lab/dev/resources/pipelines

.PHONY: delete-pipelines-dev-lab
Expand All @@ -308,9 +308,10 @@ delete-targetsources-dev-lab: ## Delete the target sources for the development l
##@ Testing Lab

.PHONY: run-integration-tests
run-integration-tests: docker-build undeploy-test-cluster deploy-test-cluster install-test-cluster-dependencies load-test-image deploy install-kubectl install-gnmic install-containerlab deploy-test-topology apply-test-resources
run-integration-tests: docker-build undeploy-test-cluster deploy-test-cluster install-test-cluster-dependencies load-test-image deploy deploy-test-http-server create-secrets-for-apiserver install-kubectl install-gnmic install-containerlab deploy-test-topology apply-test-resources send-target-to-apiserver
kubectl wait --for=condition=Ready cluster --all --timeout=180s
kubectl wait --for=condition=Ready pipeline --all --timeout=180s
kubectl wait --for=condition=Ready targetsource --all --timeout=180s
kubectl wait --for=jsonpath='{.status.connectionState}'=READY target --all --timeout=180s
kubectl get subscriptions -o yaml
kubectl get outputs -o yaml
Expand Down
272 changes: 231 additions & 41 deletions api/v1alpha1/targetsource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,64 @@ type HTTPConfig struct {
// +kubebuilder:validation:Optional
URL string `json:"url,omitempty"`

// HTTP method used for the request.
//
// Defaults to GET if not specified.
//
// Supported values:
// - GET (default, no request body)
// - POST (supports request body)
//
// +kubebuilder:validation:Enum=GET;POST
// +kubebuilder:default="GET"
// +kubebuilder:validation:Optional
Method string `json:"method,omitempty"`

// Optional HTTP headers to include in the request.
//
// These map directly to HTTP headers (key-value pairs).
//
// Example:
// headers:
// Content-Type: application/json
// X-Custom-Header: value
//
// Precedence:
// - Authentication configuration overrides any conflicting headers e.g. Authorization
//
// +kubebuilder:validation:Optional
Headers map[string]string `json:"headers,omitempty"`

// Optional raw request body.
//
// Typically used with POST requests and contains JSON payload.
//
// Example:
// body: |
// {
// "limit": 100,
// "status": "active"
// }
//
// Notes:
// - Ignored for GET requests
// - User must set appropriate Content-Type header if needed
//
// +kubebuilder:validation:Optional
Body string `json:"body,omitempty"`

// Optional authentication configuration for accessing the HTTP endpoint
// +kubebuilder:validation:Optional
Authentication *AuthenticationSpec `json:"authentication,omitempty"`

// Optional interval for polling the HTTP endpoint for targets
// TODO: document about default value
// +kubebuilder:default="6h"
// +kubebuilder:default="30m"
// +kubebuilder:validation:Optional
Interval *metav1.Duration `json:"interval,omitempty"`

// Optional timeout for HTTP requests to the endpoint
// +kubebuilder:default="10s"
// +kubebuilder:default="30s"
// +kubebuilder:validation:Optional
Timeout *metav1.Duration `json:"timeout,omitempty"`

Expand Down Expand Up @@ -132,94 +178,238 @@ type TokenAuthSpec struct {
TokenSecretRef *corev1.SecretKeySelector `json:"tokenSecretRef,omitempty"`
}

// PaginationSpec defines the configuration for paginating through responses from providers
// PaginationSpec defines how pagination is handled for HTTP APIs.
//
// The pagination mechanism is fully server-driven. The loader will repeatedly:
// 1. Extract the "next" reference from the response
// 2. Use it to construct the next request
// 3. Continue until no next reference is returned
//
// Supported pagination styles:
// 1. Cursor-based:
// - Response returns a token (e.g. "next_page_token")
// - Client sends it back via a query parameter (e.g. "page_token")
// 2. URL-based (nextLink):
// - Response returns a full URL
// - Client follows it directly without modification
// 3. Expression-based extraction:
// - The next reference is extracted using a CEL expression
// - This allows access to nested fields or special keys
// (e.g. "@odata.nextLink")
//
// Behavior:
// - If the extracted value is a full URL, it will be used as-is
// - Otherwise, it is treated as a token and appended using RequestParam
// - The token is treated as opaque and must not be interpreted
//
// Example:
//
// pagination:
// nextField: "self.next_page_token"
// requestParam: "page_token"
//
// pagination:
// nextField: "self['@odata.nextLink']"
type PaginationSpec struct {
// Field name in the JSON response that contains the next page reference.
// The value can be either:
// - a full URL (used directly for the next request), or
// - a pagination token (appended as a query parameter using this field name as the key).
// CEL expression used to extract the next page reference from the response.
//
// The expression is evaluated with:
// self -> full JSON response
//
// Must refer to a top-level key in the response object.
// Example: "next" or "nextToken"
// It must evaluate to either:
// - string (full URL OR token), or
// - null (indicates end of pagination)
//
// Examples:
// "self.next"
// "self.next_page_token"
// "self['@odata.nextLink']"
//
// +kubebuilder:validation:Optional
NextField string `json:"nextField,omitempty"`

// Query parameter name used when the extracted value is a token.
//
// Required for token-based pagination.
// Ignored when NextField resolves to a full URL.
//
// Example:
// requestParam: "page_token"
//
// +kubebuilder:validation:Optional
RequestParam string `json:"requestParam,omitempty"`
}

// CEL expressions to extract target fields from the response
// and map them to the corresponding Target fields.
// ResponseMappingSpec controls how targets are extracted from an HTTP JSON response.
//
// This allows you to map fields from a JSON API into targets using either:
// - simple direct field access (e.g. item["name"])
// - or CEL expressions for more advanced logic
//
// General behavior:
//
// 1. Selecting targets:
// - `targetsField` is a CEL expression that selects the list of targets
// - It runs once on the full response (`self`) and MUST return a list
// - If not set, the response itself must be a JSON array
//
// 2. Extracting fields:
// - Each field (name, address, port, labels, etc.) is handled independently
// - If a CEL expression is provided → it is evaluated
// - If not provided → the value is read directly from the target object
//
// 3. Available variables in CEL:
// - item -> the current target object
// - self -> the full HTTP response JSON
//
// Example:
//
// Response:
// {
// "results": [
// { "name": "device1", "ip": "10.0.0.1", "env": "prod" }
// ],
// "meta": { "region": "eu-west" }
// }
//
// Mapping:
// targetsField: "self.results"
//
// name: "" # direct → item["name"]
// address: "item.ip" # CEL
//
// labels:
// env: "item.env"
// region: "self.meta.region"
type ResponseMappingSpec struct {
// Field name in the JSON response that contains the list of items (targets).
// If not specified, the entire response is expected to be a list of items.
// All subsequent fields are specified relative to this field
// Example: "results" if the response is of the form {"results": [ ... list of items ... ]}
// CEL expression that selects the list of target objects from the response.
//
// This is evaluated once using:
// self -> full JSON response
//
// Example:
// targetsField: "self.results"
//
// If not set, the response itself must be a JSON array with the targets.
//
// +kubebuilder:validation:Optional
TargetsField string `json:"targetsField,omitempty"`

// CEL expression to extract the target name from the response
// If TargetsField is specified, this should be relative to TargetsField
// CEL expression for the target name.
//
// If not set, defaults to:
// item["name"]
//
// Example:
// "item.hostname"
//
// +kubebuilder:validation:Optional
Name string `json:"name"`
Name string `json:"name,omitempty"`

// CEL expression to extract the target Address from the response
// If TargetsField is specified, this should be relative to TargetsField
// CEL expression for the target address.
//
// If not set, defaults to:
// item["address"]
//
// Example:
// "item.ip"
//
// +kubebuilder:validation:Optional
Address string `json:"address"`
Address string `json:"address,omitempty"`

// CEL expression to extract the target port from the response
// If TargetsField is specified, this should be relative to TargetsField
// CEL expression for the target port.
//
// If not set, defaults to:
// item["port"]
//
// Example:
// "item.port"
//
// +kubebuilder:validation:Optional
Port string `json:"port,omitempty"`

// CEL expression to extract the target labels from the response
// CEL expression that returns a map of labels.
// The expression must evaluate to an object (map).
//
// Example:
//
// labels: |
// {
// "env": item.environment,
// "region": self.meta.region,
// item.dynamicKey: "value"
// }
//
// If not set, defaults to:
// item["labels"]
//
// The resulting map will be converted into labels.
// The extracted labels will be merged with the static TargetLabels defined in the TargetSourceSpec,
// with values from the response taking precedence in case of conflicts.
//
// +kubebuilder:validation:Optional
Labels map[string]string `json:"labels,omitempty"`
Labels string `json:"labels,omitempty"`

// CEL expression to extract the target profile from the response
// If TargetsField is specified, this should be relative to TargetsField
// CEL expression for the target profile.
//
// If not set, defaults to:
// item["targetProfile"]
//
// Example:
// "item.type == 'edge' ? 'edge-profile' : 'default'"
//
// +kubebuilder:validation:Optional
TargetProfile string `json:"targetProfile,omitempty"`
}

// PushSpec defines the settings for event-based update mechanism (i.e. webhooks sent from the server)
type PushSpec struct {
// Enables the applyTargets endpoint; when disabled, incoming requests are rejected.
// +kubebuilder:validation:Required
// +kubebuilder:default=false
Enabled bool `json:"enabled"`

// Enables Authentication; when empty, authentication is not checked
// +kubebuilder:validation:Optional
Auth *PushAuthSpec `json:"auth,omitempty"`

// Enables Signature verification; when empty, signature is not checked
// +kubebuilder:validation:Optional
Signature *PushSignatureSpec `json:"signature,omitempty"`
}

// +kubebuilder:validation:ExactlyOneOf:=bearer;signature
// +kubebuilder:validation:Optional
type PushAuthSpec struct {
Bearer *PushBearerAuthSpec `json:"bearer,omitempty"`
Signature *PushSignatureAuthSpec `json:"signature,omitempty"`
// Spec for Bearer Token authentication
Bearer *PushBearerAuthSpec `json:"bearer,omitempty"`
}

// +kubebuilder:validation:Required
type PushBearerAuthSpec struct {
// Reference to a secret containing a token that is checked to the Bearer token found in the
// authorization header of the incoming HTTP request.
TokenSecretRef *corev1.SecretKeySelector `json:"tokenSecretRef,omitempty"`
}

// +kubebuilder:validation:Required
type PushSignatureAuthSpec struct {
SecretRef *corev1.SecretKeySelector `json:"secretRef"`

// Header containing the signature
// +kubebuilder:validation:MinLength=1
Header string `json:"header"`
type PushSignatureSpec struct {
// Reference to a secret containing a signature key. HMAC calculated with secret and HTTP body
// to calculate X-Hook-Signature. Compared with X-Hook-Signature in HTTP header
SecretRef *corev1.SecretKeySelector `json:"secretRef,omitempty"`

// Enum to select hashing algorithm during HMAC calculation
// +kubebuilder:default="sha512"
// +kubebuilder:validation:Enum=sha1;sha256;sha512
// +kubebuilder:validation:Enum=sha256;sha512
Algorithm string `json:"algorithm"`
}


// TargetSourceStatus defines the observed state of TargetSource
type TargetSourceStatus struct {
Status string `json:"status,omitempty"`
ObservedGeneration int64 `json:"observedGeneration"`
TargetsCount int32 `json:"targetsCount,omitempty"`
LastSync metav1.Time `json:"lastSync,omitempty"`
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
TargetsCount int32 `json:"targetsCount,omitempty"`
LastSync metav1.Time `json:"lastSync,omitempty"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
Loading
Loading