Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for Observe Only Resources #1744

Merged
merged 7 commits into from
Aug 7, 2023

Conversation

chlunde
Copy link
Collaborator

@chlunde chlunde commented Apr 27, 2023

Description of your changes

commits:

  • crossplane-{tools,runtime}@master, go generate
  • Add --enable-management-policies flag
  • Pass management policy flag to the controllers

Fixes #1726

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable test to ensure this PR is ready for review.

I got "too many open files" for make reviewable, so I'll check CI.

How has this code been tested

Not yet tested in any way.

@haarchri
Copy link
Member

@chlunde awesome - what are the openpoints because of Draft ?

@chlunde
Copy link
Collaborator Author

chlunde commented Jun 23, 2023

@haarchri I was waiting for what @turkenh would do with crossplane-contrib/provider-gcp#503, as I just mechanically reproduced his changes :)

@turkenh what are your thoughts?

@turkenh
Copy link
Collaborator

turkenh commented Jun 23, 2023

@chlunde I don't expect further changes and just waiting for an approval there.

@haarchri
Copy link
Member

haarchri commented Jul 3, 2023

so @chlunde can we rebase ? lookd great

@chlunde
Copy link
Collaborator Author

chlunde commented Jul 4, 2023

@haarchri I think we should wait for crossplane/crossplane-runtime#456

@adamjohnson01
Copy link
Contributor

@haarchri and @chlunde, this is great! Do you have a timeline for this? It is something that we are really interested in using.

@kaessert
Copy link

kaessert commented Aug 4, 2023

Great piece of work! Would be really great to have this :)

chlunde and others added 5 commits August 4, 2023 18:25
	go get github.com/crossplane/crossplane-tools@master
	go mod tidy
	make generate # failed

	go get github.com/crossplane/crossplane-runtime@master
	go mod tidy
	make generate # retry, OK

https://github.com/upbound/upjet/blob/main/docs/adding-support-for-observe-only.md

Signed-off-by: Carl Henrik Lunde <[email protected]>
Fixes crossplane-contrib#1726

hacked using emacs:

	for f in $(grep -lr 'func Setup' pkg/controller/  ); do emacs --load refactor.el "$f"; done

refactor.el:

	(defun last-macro ()
	  (interactive)
	  (atomic-change-group
		(search-forward "func Setup")
		(search-forward "managed.NewReconciler")
		(search-backward "m")
		(set-mark-command nil)
		(search-forward "(")
		(left-char 1)
		(forward-sexp 1 (point))

		(kill-region nil nil 'region)
		(insert "r")

		(search-backward "return")

		(previous-line 1 1)
		(end-of-line)
		(newline nil 1)
		(insert "r := ")
		(yank nil)
		(newline nil 1)
		(search-backward "r := ")
		(search-forward "resource.ManagedKind")
		(forward-sexp 1 (point))
		(move-end-of-line 1)

		(newline nil 1)
		(insert "reconcilerOpts...")
		(set-mark-command nil)
		(search-backward "managed.NewReconciler")
		(search-forward "(")
		(left-char 1)
		(forward-sexp 1 (point))
		(left-char 1)
		(kill-region nil nil 'region)

		(search-backward "r :=")
		(previous-line 1 1)
		(insert "

	reconcilerOpts := []managed.ReconcilerOption{")
		(yank nil)
		(insert ",
	}

	")
		(insert "if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
			reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
		}
	")

		(goto-line 1)
		(search-forward "github.com/crossplane-contrib/provider-aws")
		(end-of-line)
		(insert "\n\"github.com/crossplane-contrib/provider-aws/pkg/features\"")

		(save-buffer 1)
		))

	(add-hook 'go-mode-hook #'last-macro)

Signed-off-by: Carl Henrik Lunde <[email protected]>
Signed-off-by: Christopher Haar <[email protected]>
@haarchri haarchri marked this pull request as ready for review August 4, 2023 16:52
@haarchri
Copy link
Member

haarchri commented Aug 4, 2023

@chlunde i made two commits, rebased onto the master branch, and updated crossplane-runtime and crossplane-tools to their latest versions for more precise management policies. I also tested the provider with some resources:

kubectl get filesystem.efs.aws.crossplane.io/example   -o yaml
apiVersion: efs.aws.crossplane.io/v1alpha1
kind: FileSystem
metadata:
  annotations:
    crossplane.io/external-create-pending: "2023-08-04T18:45:39+02:00"
    crossplane.io/external-create-succeeded: "2023-08-04T18:45:40+02:00"
    crossplane.io/external-name: fs-038dc3b8e3c7d6cf6
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"efs.aws.crossplane.io/v1alpha1","kind":"FileSystem","metadata":{"annotations":{},"name":"example"},"spec":{"forProvider":{"region":"us-east-1","tags":[{"key":"customKey","value":"customValue"},{"key":"Name","value":"DisplayNameInAWS"}]},"providerConfigRef":{"name":"example"}}}
  creationTimestamp: "2023-08-04T16:45:39Z"
  finalizers:
  - finalizer.managedresource.crossplane.io
  generation: 1
  name: example
  resourceVersion: "97551"
  uid: 253a259f-b03b-4a0d-bc41-b803cda09fc8
spec:
  deletionPolicy: Delete
  forProvider:
    region: us-east-1
    tags:
    - key: customKey
      value: customValue
    - key: Name
      value: DisplayNameInAWS
  managementPolicies:
  - '*'
  providerConfigRef:
    name: example
status:
  atProvider:
    creationTime: "2023-08-04T16:45:39Z"
    creationToken: 253a259f-b03b-4a0d-bc41-b803cda09fc8
    fileSystemARN: arn:aws:elasticfilesystem:us-east-1:609897127049:file-system/fs-038dc3b8e3c7d6cf6
    fileSystemID: fs-038dc3b8e3c7d6cf6
    lifeCycleState: available
    name: DisplayNameInAWS
    numberOfMountTargets: 0
    ownerID: "609897127049"
    sizeInBytes:
      value: 6144
      valueInIA: 0
      valueInStandard: 6144
  conditions:
  - lastTransitionTime: "2023-08-04T16:46:41Z"
    reason: Available
    status: "True"
    type: Ready
  - lastTransitionTime: "2023-08-04T16:45:40Z"
    reason: ReconcileSuccess
    status: "True"
    type: Synced

@chlunde
Copy link
Collaborator Author

chlunde commented Aug 7, 2023

@haarchri nice!

@haarchri haarchri merged commit ee18522 into crossplane-contrib:master Aug 7, 2023
dee0 pushed a commit to dee0sap/provider-aws that referenced this pull request Aug 28, 2023
* crossplane-{tools,runtime}@master, go generate

	go get github.com/crossplane/crossplane-tools@master
	go mod tidy
	make generate # failed

	go get github.com/crossplane/crossplane-runtime@master
	go mod tidy
	make generate # retry, OK

https://github.com/upbound/upjet/blob/main/docs/adding-support-for-observe-only.md

Signed-off-by: Carl Henrik Lunde <[email protected]>

* Add --enable-management-policies flag

Signed-off-by: Carl Henrik Lunde <[email protected]>

* Pass management policy flag to the controllers

Fixes crossplane-contrib#1726

hacked using emacs:

	for f in $(grep -lr 'func Setup' pkg/controller/  ); do emacs --load refactor.el "$f"; done

refactor.el:

	(defun last-macro ()
	  (interactive)
	  (atomic-change-group
		(search-forward "func Setup")
		(search-forward "managed.NewReconciler")
		(search-backward "m")
		(set-mark-command nil)
		(search-forward "(")
		(left-char 1)
		(forward-sexp 1 (point))

		(kill-region nil nil 'region)
		(insert "r")

		(search-backward "return")

		(previous-line 1 1)
		(end-of-line)
		(newline nil 1)
		(insert "r := ")
		(yank nil)
		(newline nil 1)
		(search-backward "r := ")
		(search-forward "resource.ManagedKind")
		(forward-sexp 1 (point))
		(move-end-of-line 1)

		(newline nil 1)
		(insert "reconcilerOpts...")
		(set-mark-command nil)
		(search-backward "managed.NewReconciler")
		(search-forward "(")
		(left-char 1)
		(forward-sexp 1 (point))
		(left-char 1)
		(kill-region nil nil 'region)

		(search-backward "r :=")
		(previous-line 1 1)
		(insert "

	reconcilerOpts := []managed.ReconcilerOption{")
		(yank nil)
		(insert ",
	}

	")
		(insert "if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
			reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
		}
	")

		(goto-line 1)
		(search-forward "github.com/crossplane-contrib/provider-aws")
		(end-of-line)
		(insert "\n\"github.com/crossplane-contrib/provider-aws/pkg/features\"")

		(save-buffer 1)
		))

	(add-hook 'go-mode-hook #'last-macro)

Signed-off-by: Carl Henrik Lunde <[email protected]>

* feat(bump): bump crossplane-runtime and crospslane-tools

Signed-off-by: Christopher Haar <[email protected]>

* feat(bump): rebase and bump

Signed-off-by: Christopher Haar <[email protected]>

* feat(bump): set up_version v0.18.0 to fits build module

Signed-off-by: Christopher Haar <[email protected]>

* feat(bump): set golangci_version to v1.53.3

Signed-off-by: Christopher Haar <[email protected]>

---------

Signed-off-by: Carl Henrik Lunde <[email protected]>
Signed-off-by: Christopher Haar <[email protected]>
Co-authored-by: Christopher Haar <[email protected]>
threadproc pushed a commit to swisscom/provider-aws that referenced this pull request Sep 1, 2023
* crossplane-{tools,runtime}@master, go generate

	go get github.com/crossplane/crossplane-tools@master
	go mod tidy
	make generate # failed

	go get github.com/crossplane/crossplane-runtime@master
	go mod tidy
	make generate # retry, OK

https://github.com/upbound/upjet/blob/main/docs/adding-support-for-observe-only.md

Signed-off-by: Carl Henrik Lunde <[email protected]>

* Add --enable-management-policies flag

Signed-off-by: Carl Henrik Lunde <[email protected]>

* Pass management policy flag to the controllers

Fixes crossplane-contrib#1726

hacked using emacs:

	for f in $(grep -lr 'func Setup' pkg/controller/  ); do emacs --load refactor.el "$f"; done

refactor.el:

	(defun last-macro ()
	  (interactive)
	  (atomic-change-group
		(search-forward "func Setup")
		(search-forward "managed.NewReconciler")
		(search-backward "m")
		(set-mark-command nil)
		(search-forward "(")
		(left-char 1)
		(forward-sexp 1 (point))

		(kill-region nil nil 'region)
		(insert "r")

		(search-backward "return")

		(previous-line 1 1)
		(end-of-line)
		(newline nil 1)
		(insert "r := ")
		(yank nil)
		(newline nil 1)
		(search-backward "r := ")
		(search-forward "resource.ManagedKind")
		(forward-sexp 1 (point))
		(move-end-of-line 1)

		(newline nil 1)
		(insert "reconcilerOpts...")
		(set-mark-command nil)
		(search-backward "managed.NewReconciler")
		(search-forward "(")
		(left-char 1)
		(forward-sexp 1 (point))
		(left-char 1)
		(kill-region nil nil 'region)

		(search-backward "r :=")
		(previous-line 1 1)
		(insert "

	reconcilerOpts := []managed.ReconcilerOption{")
		(yank nil)
		(insert ",
	}

	")
		(insert "if o.Features.Enabled(features.EnableAlphaManagementPolicies) {
			reconcilerOpts = append(reconcilerOpts, managed.WithManagementPolicies())
		}
	")

		(goto-line 1)
		(search-forward "github.com/crossplane-contrib/provider-aws")
		(end-of-line)
		(insert "\n\"github.com/crossplane-contrib/provider-aws/pkg/features\"")

		(save-buffer 1)
		))

	(add-hook 'go-mode-hook #'last-macro)

Signed-off-by: Carl Henrik Lunde <[email protected]>

* feat(bump): bump crossplane-runtime and crospslane-tools

Signed-off-by: Christopher Haar <[email protected]>

* feat(bump): rebase and bump

Signed-off-by: Christopher Haar <[email protected]>

* feat(bump): set up_version v0.18.0 to fits build module

Signed-off-by: Christopher Haar <[email protected]>

* feat(bump): set golangci_version to v1.53.3

Signed-off-by: Christopher Haar <[email protected]>

---------

Signed-off-by: Carl Henrik Lunde <[email protected]>
Signed-off-by: Christopher Haar <[email protected]>
Co-authored-by: Christopher Haar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Support for Observe Only Resources
5 participants