Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
245 commits
Select commit Hold shift + click to select a range
c902d05
first draft to create targets
mcdillson Apr 7, 2026
95be5ab
added deletion of targets
mcdillson Apr 7, 2026
4e3104e
renamed client functions
mcdillson Apr 7, 2026
32eb936
added update functionality
mcdillson Apr 7, 2026
3c4141f
refactored crud options into separate function with struct
mcdillson Apr 7, 2026
590a494
refactored delete to use map lookup
mcdillson Apr 7, 2026
2666986
added comments
mcdillson Apr 7, 2026
b9cd85e
fixed bug with deleted object name being empty
mcdillson Apr 7, 2026
109a85e
added info logs
mcdillson Apr 7, 2026
372fe71
merged initial folder structure & moved existing files
mcdillson Apr 8, 2026
3290233
Merge remote-tracking branch 'origin/feature/target-loading-architect…
mcdillson Apr 13, 2026
402c70a
changed NewLoader function call
mcdillson Apr 13, 2026
7f83285
added discovery message to types
mcdillson Apr 13, 2026
7d03411
changed target source channel type
mcdillson Apr 13, 2026
4fb0373
fixed http_pull implementation based on new types
mcdillson Apr 13, 2026
2294f1e
implemented first draft of target creation using loaders
mcdillson Apr 13, 2026
912e05a
removed manual targetsource spec
mcdillson Apr 14, 2026
bf28aad
cleaned up reconciliation loop and refactored into target manager
mcdillson Apr 14, 2026
aa17c82
Merge branch 'feature/targetsource-crd-fields' into feat/target-creation
mcdillson Apr 14, 2026
022dbae
restructured project to introduce new architecture
mcdillson Apr 15, 2026
4dc2eb3
renamed targetsource package to discovery
mcdillson Apr 15, 2026
ad172c9
removed unnecessary files and updated gitignore
mcdillson Apr 15, 2026
181ea95
extend TargetSource CRD by http token
denyost Apr 16, 2026
2fddddf
add pull logic as poc
denyost Apr 16, 2026
64a83cd
fix request header typo
denyost Apr 16, 2026
98823e8
refactor pull implementation
denyost Apr 16, 2026
cfe0273
Merge branch 'feature/target-loading-architecture' of https://github.…
denyost Apr 16, 2026
e76c6f3
restructure discovery structs
denyost Apr 17, 2026
3c18fb5
offload sending logic from loader implementation
denyost Apr 17, 2026
86ab0f3
implement type assertion based on received message
denyost Apr 17, 2026
10a9978
Merge branch 'feature/limit-target-loading' of https://github.com/gnm…
denyost Apr 17, 2026
8b36d7d
add http_push skeleton
denyost Apr 17, 2026
efbf727
add http_push skeleton
denyost Apr 17, 2026
60a5eb3
refactor targetsource_controller.go
denyost Apr 17, 2026
1bc5d2b
remove targetsource ressource to not impact main
denyost Apr 17, 2026
14e7765
add batching to DiscoveryEvent's
denyost Apr 17, 2026
b4337ea
refactored sender.go
denyost Apr 17, 2026
30f3ecb
load buffer and chunk size from env variable
denyost Apr 17, 2026
6579a7d
Merge branch 'feature/targetsource-crd-fields' into feat/target-creation
mcdillson Apr 17, 2026
4ef6268
Merge branch 'feature/limit-target-loading' into feat/target-creation
mcdillson Apr 17, 2026
6684aa9
ran go mod tidy
mcdillson Apr 17, 2026
c952cbf
changed events to delete/apply and implemented draft with snapshots
mcdillson Apr 18, 2026
d4a9053
first implementation for full snapshot processing
mcdillson Apr 20, 2026
5af4f5e
fixed mapper function to work for empty existing targets
mcdillson Apr 20, 2026
d5ea4da
introduce observedGeneration for pipeline restart
mcdillson Apr 20, 2026
fe086e2
tests with targetsource status field to restart pipeline
mcdillson Apr 20, 2026
bd60568
added status update to targetmanager
mcdillson Apr 20, 2026
1e81e11
separated status updates & cleaned up functions
mcdillson Apr 20, 2026
d3e708c
restructured target manager logic to handle events
mcdillson Apr 21, 2026
9a78cf4
fixed small issues
mcdillson Apr 21, 2026
201ccb3
Merge branch 'feature/targetsource-crd-fields' into feature/limit-tar…
mcdillson Apr 21, 2026
c8dfdf1
Merge branch 'feature/limit-target-loading' of https://github.com/gnm…
denyost Apr 22, 2026
6cc0eb1
Merge branch 'feature/target-loading-architecture' of https://github.…
denyost Apr 22, 2026
e7ff5f8
Merge branch 'feature/limit-target-loading' of https://github.com/gnm…
denyost Apr 22, 2026
3cb9160
Merge branch 'feature/limit-target-loading' of https://github.com/gnm…
denyost Apr 22, 2026
586001e
rename file to helpers
denyost Apr 22, 2026
7430815
rebuild and reformat
denyost Apr 22, 2026
4fb6755
removed unnecessary map
mcdillson Apr 22, 2026
aaf9f2b
added prefix to targets
mcdillson Apr 22, 2026
255a1f3
consolidate pull and push to http
denyost Apr 23, 2026
bd2b45f
rename target manager to target applier
denyost Apr 23, 2026
5a561a7
implement a generic registry
denyost Apr 23, 2026
f5481b8
add a discoveryTegistry to share targetchannel between apiserver and …
denyost Apr 23, 2026
22683f4
remove unused event action from DiscoverySnapshot
denyost Apr 23, 2026
922bbc6
rename target manager to target applier
denyost Apr 24, 2026
733927f
implement key for registry as a comparable
denyost Apr 24, 2026
9d30560
fix error message and add a word of caution for key comparables
denyost Apr 24, 2026
dafa82b
consistently use namespaced name as refference to the targetsource
denyost Apr 24, 2026
2973c03
improve context cancling and error handling
denyost Apr 24, 2026
c95bdaf
add supervised goroutines
denyost Apr 24, 2026
0aa883d
refactor target applier
denyost Apr 24, 2026
27b2b1f
add supervisor for the discovery pipelines
denyost Apr 24, 2026
22fe2d8
improve readability
denyost Apr 24, 2026
58538c7
remove side-effects from getter getTargetSource
denyost Apr 24, 2026
4f0457e
redesign supervisor
denyost Apr 24, 2026
2b728c4
added const file for common labels
mcdillson Apr 24, 2026
5abbd63
simplified name and namespace calls for objects
mcdillson Apr 24, 2026
3d7ff38
changed label handling and target object creation
mcdillson Apr 24, 2026
4d0a937
fixed label filtering for existing targets
mcdillson Apr 24, 2026
60491be
add dependency handling of discovery pipeline components
denyost Apr 25, 2026
b8a6d27
refactor code
denyost Apr 25, 2026
eedfedf
improve context handling of and target applier semantics
denyost Apr 25, 2026
1715ae1
Merge branch 'feature/limit-target-loading' into feat/target-creation
mcdillson Apr 27, 2026
a66accb
moved finalizer label into const file
mcdillson Apr 27, 2026
3b2d925
fixed typo
mcdillson Apr 27, 2026
3ba86cb
restructured loaders package
mcdillson Apr 27, 2026
d0ac86b
restructured target handler
mcdillson Apr 27, 2026
240a2bc
ran go mod tidy
mcdillson Apr 27, 2026
5a7ba1a
Merge branch 'feature/limit-target-loading' into feat/target-creation
mcdillson Apr 27, 2026
7ef1281
renamed target applier to message processor & created client.go for g…
mcdillson Apr 27, 2026
7bcbcc0
added const file for common labels
mcdillson Apr 24, 2026
4fa58b6
Merge branch 'feature/limit-target-loading' into feature/restructuring
mcdillson Apr 27, 2026
d10fc9a
removed all package
mcdillson Apr 27, 2026
108bd2d
changed error lookup to apierrors
mcdillson Apr 27, 2026
b7dd036
remove unused fiels
denyost Apr 29, 2026
d3a9b5c
rename files and restructure packages
denyost Apr 29, 2026
0c80394
rename target handler to target reconciler
denyost Apr 29, 2026
04208bf
rename handler to reconciler
denyost Apr 29, 2026
c3818ce
clarify interface files
denyost Apr 29, 2026
e4df0d4
define EventAction to be go idomatic
denyost Apr 29, 2026
86c0af0
add webhook activation info to metadata of DiscoveryRegistry
denyost Apr 29, 2026
284b1f2
moved reconciler files to discovery
mcdillson Apr 29, 2026
b59897c
renamed messageProcessor to targetReconciler
mcdillson Apr 29, 2026
c268808
moved registry.go to discovery
mcdillson Apr 29, 2026
0295896
moved supervisor to discovery
mcdillson Apr 29, 2026
4d32c40
moved factory.go to discovery/loaders.go
mcdillson Apr 29, 2026
7671c1a
moved send.go to loaders package
mcdillson Apr 29, 2026
5f1e9cb
eliminated message.go
mcdillson Apr 29, 2026
6d67537
moved const.go to discovery.go
mcdillson Apr 29, 2026
3914630
renamed core package within targetsource controller
mcdillson Apr 29, 2026
931a4cf
Merge branch 'feature/limit-target-loading' into feat/target-creation
mcdillson Apr 29, 2026
46a201f
changed events to delete / apply
mcdillson Apr 29, 2026
7b17f7e
moved send.go into separate utils for loaders
mcdillson Apr 29, 2026
f37e172
Merge branch 'feature/restructuring' into feat/target-creation
mcdillson Apr 29, 2026
4540163
replaced legacy registry package
mcdillson Apr 29, 2026
2c3260e
Merge pull request #57 from gnmic/feature/restructuring
mcdillson Apr 29, 2026
090fa26
Merge branch 'feature/limit-target-loading' into feat/target-creation
mcdillson Apr 29, 2026
183abe2
moved client/mapper functions out of target_reconciler.go
mcdillson Apr 29, 2026
0811afd
renamed functions
mcdillson Apr 29, 2026
f269a85
Merge branch 'main' of https://github.com/gnmic/operator into feature…
denyost Apr 30, 2026
c728fa2
add supervisor restart policy to targetsource spec configuration
denyost Apr 30, 2026
589bc9f
add targetsource example for lab
denyost Apr 30, 2026
a5dde06
remove targetsource example to not add unnecassary logging to main
denyost Apr 30, 2026
4be9c27
update gitignore to not push targetsources in order to prevent loggin…
denyost Apr 30, 2026
65eb7f6
Merge branch 'feature/limit-target-loading' of https://github.com/gnm…
denyost Apr 30, 2026
7337541
add component info to logging
denyost Apr 30, 2026
4ec0bb6
Merge branch 'feature/limit-target-loading' of https://github.com/gnm…
denyost Apr 30, 2026
41d5498
make snapshot id a bit smaller
denyost Apr 30, 2026
3ec3203
if context is canceled return with ctx.Err() not a clean exit
denyost Apr 30, 2026
0eaffdc
applied kubebuilder best-practise logging
denyost Apr 30, 2026
5140605
Merge branch 'feature/limit-target-loading' of https://github.com/gnm…
denyost Apr 30, 2026
e447b3b
improved logging
denyost Apr 30, 2026
fca37e0
improved logging
denyost Apr 30, 2026
fd4abe7
improved logging
denyost Apr 30, 2026
a6bc114
simplified pipeline context handling
denyost Apr 30, 2026
34cd51e
Merge branch 'feature/limit-target-loading' of https://github.com/gnm…
denyost Apr 30, 2026
54c41fd
add timeout as a const
denyost Apr 30, 2026
535ee49
rename target reconciler to message processor
denyost May 1, 2026
c09c68f
rename pipeline to runtime
denyost May 1, 2026
e4c01ba
removed supervisor
denyost May 1, 2026
77dbd7e
tidy loader configuration abstraction
denyost May 1, 2026
fe900e3
regenearte manifests without restartPolicy
denyost May 1, 2026
c1d7a91
tidy up comments
denyost May 1, 2026
05c7538
move webhook spec into provider and rename it to acceptPush
denyost May 1, 2026
061d4b8
regenerate manifests
denyost May 1, 2026
41655a0
remove spec from laoder config
denyost May 1, 2026
97849ae
update LoaderConfig in registry
denyost May 1, 2026
e977868
Merge branch 'feature/limit-target-loading' into feat/target-creation
mcdillson May 3, 2026
1bdc294
moved updateStatus function to client.go
mcdillson May 4, 2026
9255240
changed updateStauts handling
mcdillson May 4, 2026
29c4974
removed owned targets from targetsource reconciliation
mcdillson May 4, 2026
24cc376
added predicate for targetsource reconciliation
mcdillson May 4, 2026
8da8052
changed updateStatus calling for event
mcdillson May 4, 2026
f4d6bac
added comments to mapper.go
mcdillson May 4, 2026
41c1fec
added more comments
mcdillson May 4, 2026
4a46908
added initial targetCount fetch to deal with process restarts
mcdillson May 4, 2026
a0b55b3
added comment
mcdillson May 4, 2026
426e27a
fix: use defined variable
denyost May 4, 2026
d14b10c
fixed cluster variable for netbox deployment
mcdillson May 4, 2026
f04c130
added netbox integration test setup
mcdillson May 4, 2026
765c6ed
renamed sync-test-netbox-data
mcdillson May 4, 2026
935c49f
moved netbox clab topology into netbox folder
mcdillson May 4, 2026
5fb7700
added targetsource integration resource
mcdillson May 4, 2026
1c349ae
added comments + fixed netbox test topology path
mcdillson May 5, 2026
6c22ef1
Merge branch 'feature/limit-target-loading' into feature/discovery-e2…
mcdillson May 5, 2026
a0d48ca
Merge branch 'feat/target-creation' into feature/discovery-e2e-implem…
mcdillson May 5, 2026
60736be
Merge branch 'testing/netbox-integration-setup' into feature/discover…
mcdillson May 5, 2026
012a6a5
fixed missing separator
mcdillson May 5, 2026
09aaaa4
fixed targetProfile key
mcdillson May 5, 2026
631eeaf
Merge branch 'testing/netbox-integration-setup' into feature/discover…
mcdillson May 5, 2026
4bcd01e
fixed name normalization
mcdillson May 5, 2026
ecbef25
Merge branch 'feat/target-creation' into feature/discovery-e2e-implem…
mcdillson May 5, 2026
47e4851
Merge remote-tracking branch 'refs/remotes/origin/feature/discovery-e…
mcdillson May 5, 2026
b9ab471
eliminated recursive make calls
mcdillson May 5, 2026
1a6239a
added recursive clab folder to gitignore
mcdillson May 5, 2026
4f879aa
added resources for http static server test
mcdillson May 5, 2026
a534406
added make targets for http testing pod
mcdillson May 5, 2026
c472f48
Merge branch 'feature/limit-target-loading' of https://github.com/gnm…
denyost May 6, 2026
a6e449d
load spec into loader
denyost May 6, 2026
e908953
update httpconfig
denyost May 6, 2026
85278df
use httpconfig within loader
denyost May 6, 2026
6c82320
refactor
denyost May 6, 2026
deb9e90
git ignore sonar scanner
denyost May 8, 2026
b088db2
add defaulting for targetsource crd
denyost May 8, 2026
f5e822d
Merge branch 'testing/netbox-integration-setup' into feature/discover…
mcdillson May 8, 2026
9ff3ba1
fixed make target name
mcdillson May 8, 2026
0031b5a
added http targetsource integration test to Makefile
mcdillson May 8, 2026
c3dc34c
changed resource names + mapped target inventory to clab
mcdillson May 8, 2026
efead83
fixed http target url and profile
mcdillson May 8, 2026
4d461a3
removed netbox targetsource for integration test
mcdillson May 8, 2026
f7c627a
mapped operator resources to new http test
mcdillson May 8, 2026
f37cc4a
removed netbox clab and changed address
mcdillson May 8, 2026
4f4abf7
Merge branch 'testing/netbox-integration-setup' into feature/discover…
mcdillson May 8, 2026
000d405
changed resource names + mapped target inventory to clab
mcdillson May 8, 2026
858600b
fixed http target url and profile
mcdillson May 8, 2026
bbbceec
removed netbox targetsource for integration test
mcdillson May 8, 2026
bfaf0e3
mapped operator resources to new http test
mcdillson May 8, 2026
f7e6ac0
removed netbox clab and changed address
mcdillson May 8, 2026
61ef95d
generated manifests
mcdillson May 8, 2026
d64bf6a
added tests for mapper.go
mcdillson May 8, 2026
17bd490
rewrote and added more tests for mapper.go
mcdillson May 9, 2026
9208766
remove closeChannel and fix cleanup logic
denyost May 13, 2026
209948e
fix: resolved pointer and returns smells
denyost May 13, 2026
1a0f447
improved logging message
denyost May 13, 2026
d94c23f
improved error handling
denyost May 13, 2026
e3f18d8
refactor: ctx should flow not be stored
denyost May 13, 2026
bc1b350
refactor: resetSnapshot
denyost May 13, 2026
020be5a
refactor: context cancellation
denyost May 13, 2026
3280229
refactor: default error handling now logs errors instead of terminati…
denyost May 13, 2026
cf49f83
Merge branch 'feature/limit-target-loading' of https://github.com/gnm…
denyost May 13, 2026
39f1650
refactor: pointer missuse
denyost May 13, 2026
f1d8c31
move defaulting logic to kubebuilder:default
denyost May 13, 2026
b0c63ff
remove pointer from bool
denyost May 13, 2026
c422dff
update deepcopy
denyost May 13, 2026
abb7180
fix: pointer issue
denyost May 13, 2026
8f2b55a
Merge branch 'testing/netbox-integration-setup' into feat/target-crea…
mcdillson May 13, 2026
89b6660
Merge branch 'testing/netbox-integration-setup' into feat/target-crea…
mcdillson May 13, 2026
6d17a7f
Merge branch 'feature/limit-target-loading' into feat/target-creation
mcdillson May 13, 2026
6ccf4ba
added handling for unknown operator labels
mcdillson May 13, 2026
6b01748
removed value for log verbosity
mcdillson May 13, 2026
36cf9fd
add helper to read secrets
denyost May 14, 2026
4f70c43
implement basic and token authentication
denyost May 14, 2026
966cd59
support .Key for TokenSecretRef
denyost May 14, 2026
862e28d
update targetsource
denyost May 14, 2026
e6e9439
support TLS verification
denyost May 14, 2026
055bfb0
make manifest and generate
denyost May 14, 2026
1deb8cc
fix CRD issues
denyost May 14, 2026
816b04f
add support for pagination
denyost May 15, 2026
c01b199
refactor
denyost May 15, 2026
5d95c90
add support for JSONPath mapping
denyost May 15, 2026
6a83f49
add support for TargetProfile supplied by provider
denyost May 15, 2026
1e9feb6
refactor
denyost May 15, 2026
0e8ea1a
fix interfaces
denyost May 15, 2026
262760c
fix incorrect conversion between integer types
denyost May 15, 2026
a4bb9b9
Merge branch 'main' into feat/target-creation
mcdillson May 17, 2026
c56d657
added comment to temporary message snapshots
mcdillson May 17, 2026
72cfa78
renamed function to String()
mcdillson May 17, 2026
ed5b8cc
return the values of reconcileDeletion directly
mcdillson May 18, 2026
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
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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 install-kubectl install-gnmic install-containerlab deploy-test-topology apply-test-resources
kubectl wait --for=condition=Ready cluster --all --timeout=180s
kubectl wait --for=condition=Ready pipeline --all --timeout=180s
kubectl wait --for=jsonpath='{.status.targetsCount}'=3 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
185 changes: 175 additions & 10 deletions api/v1alpha1/targetsource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,209 @@ limitations under the License.
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// TargetSourceSpec defines the desired state of TargetSource
// +kubebuilder:validation:Required
type TargetSourceSpec struct {
// Provider defines the source of targets for this TargetSource
// Only one provider can be specified per TargetSource
// +kubebuilder:validation:Required
Provider *ProviderSpec `json:"provider"`

// TODO: implement in message processor
// Optional port to use for discovered targets if not specified by the provider
// +kubebuilder:validation:Optional
TargetPort int32 `json:"targetPort,omitempty"`

// Optional labels to apply to all targets discovered by this TargetSource
// +kubebuilder:validation:Optional
TargetLabels map[string]string `json:"targetLabels,omitempty"`

// The TargetProfile to use for targets discovered by this TargetSource
// +kubebuilder:validation:Required
// +kubebuilder:validation:MinLength=1
TargetProfile string `json:"targetProfile"`
}

// +kubebuilder:validation:ExactlyOneOf=http;consul
// ProviderSpec defines the source of targets for a TargetSource
// Only one provider can be specified per TargetSource
// +kubebuilder:validation:ExactlyOneOf=http
type ProviderSpec struct {
HTTP *HTTPConfig `json:"http,omitempty"`
Consul *ConsulConfig `json:"consul,omitempty"`
// HTTP defines the configuration for a HTTP provider
HTTP *HTTPConfig `json:"http,omitempty"`
}

// HTTPConfig defines the configuration for the HTTP provider
// +kubebuilder:validation:AtLeastOneOf=url;acceptPush
type HTTPConfig struct {
// +kubebuilder:validation:MinLength=1
URL string `json:"url"`
// URL of the HTTP endpoint to pull targets from
// If defined, the loader will periodically poll this endpoint for targets
// +kubebuilder:validation:Optional
URL string `json:"url,omitempty"`

// If true, the loader will accept pushed target updates to the controller endpoint
// The endpoint will be /{namespace}/{targetsource}/<todo>
// +kubebuilder:default=false
// +kubebuilder:validation:Optional
AcceptPush bool `json:"acceptPush,omitempty"`

// Optional authorization configuration for accessing the HTTP endpoint
// +kubebuilder:validation:Optional
Authorization *AuthorizationSpec `json:"authorization,omitempty"`

// Optional interval for polling the HTTP endpoint for targets
// TODO: increase default value
// +kubebuilder:default="30s"
// +kubebuilder:validation:Optional
PollInterval *metav1.Duration `json:"interval,omitempty"`

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

// Optional TLS configuration for connecting to the HTTP endpoint
// +kubebuilder:validation:Optional
TLS *ClientTLSConfig `json:"tls,omitempty"`

// Optional pagination configuration for parsing responses from the HTTP endpoint
// +kubebuilder:validation:Optional
Pagination *PaginationSpec `json:"pagination,omitempty"`

// Optional mapping configuration for parsing responses from the HTTP endpoint
// +kubebuilder:validation:Optional
ResponseMapping *ResponseMappingSpec `json:"mapping,omitempty"`
}

type ConsulConfig struct {
// +kubebuilder:validation:XValidation:rule="!(has(self.caBundle) && has(self.caBundleSecretRef))",message="caBundle and caBundleSecretRef are mutually exclusive"
type ClientTLSConfig struct {
// Skip TLS verification of the Provider's certificate.
// +kubebuilder:default:=false
InsecureSkipVerify bool `json:"insecureSkipVerify,omitempty"`

// Base64-encoded bundle of PEM CAs which will be used to validate the certificate
// chain presented by the Provider. Only used if using HTTPS to connect to Provider and
// ignored for HTTP connections.
// Mutually exclusive with CABundleSecretRef.
// +optional
CABundle []byte `json:"caBundle,omitempty"`

// Reference to a Secret containing a bundle of PEM-encoded CAs to use when
// verifying the certificate chain presented by the Provider when using HTTPS.
// Mutually exclusive with CABundle.
CABundleSecretRef *corev1.SecretKeySelector `json:"caBundleSecretRef,omitempty"`
}

// AuthorizationSpec defines the configuration for authentication
// +kubebuilder:validation:ExactlyOneOf=basic;token
type AuthorizationSpec struct {
// Basic authentication configuration
Basic *BasicAuthSpec `json:"basic,omitempty"`
// Token-based authentication configuration
Token *TokenAuthSpec `json:"token,omitempty"`
// JWT *JWTAuthSpec `json:"jwt,omitempty"`
// MTLS
}

// BasicAuthSpec defines the configuration for basic authentication
// Enforce EITHER inline creds OR secret ref
// +kubebuilder:validation:XValidation:rule="(has(self.credentialsSecretRef) && !has(self.username) && !has(self.password)) || (!has(self.credentialsSecretRef) && has(self.username) && has(self.password))",message="either credentialsSecretRef OR both username and password must be set, but not a mix"
type BasicAuthSpec struct {
// Username for basic auth
// Mutually exclusive with CredentialsSecretRef.
Username string `json:"username,omitempty"`
// Password for basic auth
// Mutually exclusive with CredentialsSecretRef.
Password string `json:"password,omitempty"`

// Reference to a Secret containing "username" and "password" keys to use for
// basic authentication when connecting to the Provider.
// Mutually exclusive with Username and Password.
CredentialsSecretRef *corev1.SecretKeySelector `json:"credentialsSecretRef,omitempty"`
}

// TokenAuthSpec defines the configuration for token-based authentication
// +kubebuilder:validation:XValidation:rule="has(self.token) != has(self.tokenSecretRef)",message="either token or tokenSecretRef must be set, but not both"
type TokenAuthSpec struct {
// Scheme for the token, e.g. "Bearer"
// +kubebuilder:validation:MinLength=1
URL string `json:"url,omitempty"`
Scheme string `json:"scheme"`
// Token value for authentication
// Mutually exclusive with TokenSecretRef.
Token string `json:"token,omitempty"`
// Reference to a Secret containing a key with the token value to use for
// authentication when connecting to the Provider.
// Mutually exclusive with Token.
TokenSecretRef *corev1.SecretKeySelector `json:"tokenSecretRef,omitempty"`
}

// +kubebuilder(disabled):validation:XValidation:rule="!((has(self.token) || has(self.tokenSecretRef)) && (has(self.key) || has(self.signingKeySecretRef) || has(self.claims)))",message="static JWT token and generated JWT configuration cannot be combined"
// +kubebuilder(disabled):validation:XValidation:rule="!has(self.signingKeySecretRef) || self.algorithm != \"\"",message="algorithm must be specified when generating a JWT"
// type JWTAuthSpec struct {
// // Static pre-generated JWT
// Token string `json:"token,omitempty"`
// TokenSecretRef *corev1.SecretKeySelector `json:"tokenSecretRef,omitempty"`
// // Optional: generate JWT dynamically
// Claims map[string]string `json:"claims,omitempty"`
// Key string `json:"key,omitempty"`
// SigningKeySecretRef *corev1.SecretKeySelector `json:"signingKeySecretRef,omitempty"`
// // HS256, RS256, ES256, etc.
// Algorithm string `json:"algorithm,omitempty"`
// TTL *metav1.Duration `json:"ttl,omitempty"`
// }

// PaginationSpec defines the configuration for paginating through responses from providers
type PaginationSpec struct {
// Field name in the JSON response that contains the list of items (targets).
// Must refer to a top-level key in the response object.
// Example: "results"
ItemsField string `json:"itemsField,omitempty"`

// 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).
//
// Must refer to a top-level key in the response object.
// Example: "next" or "nextToken"
NextField string `json:"nextField,omitempty"`
}

// JSONPath-style expressions to extract target fields from the response
// and map them to the corresponding Target fields.
type ResponseMappingSpec struct {
// JSONPath expression to extract the target name from the response
// +kubebuilder:validation:Required
Name string `json:"name"`

// JSONPath expression to extract the target IP from the response
// +kubebuilder:validation:Required
IP string `json:"ip"`

// JSONPath expression to extract the target port from the response
// +kubebuilder:validation:Optional
Port string `json:"port,omitempty"`

// JSONPath expression to extract the target labels from the response
// 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"`

// JSONPath expression to extract the target profile from the response
// +kubebuilder:validation:Optional
TargetProfile string `json:"targetProfile,omitempty"`
}

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

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