# application-api
How to push changes to [api-](https://github.com/redhat-appstudio/application-api/pull/12)
Documentation follows the changes for this file `Promotion_Types.go`
However, same (exactly the same) procedure was followed for the rest of the files that I've changed:
Changes:
* `ApplicationPromotionRun` struct rename --> `PromotionRun` (required a change in `PromotionRunList` as well as it's using it)
* `ApplicationPromotionRunList` struct rename --> `PromotionRunList`
* `ApplicationPromotionRunSpec` struct rename --> `PromotionRunSpec` (required a change to `PromotionRun` as well as it used this)
* `ApplicationPromotionRunStatus` rename --> `PromotionRunStatus` (required a change to `PromotionRun` as well as it used this)
* Also adds two member fields: `PromotionStartTime` and `Conditions` (including the `PromotionRunCondition` new type)
* Rename 3 `consts`: `ApplicationPromotionRunEnvironmentStatus_Success` --> `PromotionRunEnvironmentStatus_Success`
`ApplicationPromotionRunEnvironmentStatus_InProgress` --> `PromotionRunEnvironmentStatus_InProgress`
`ApplicationPromotionRunEnvironmentStatus_Failed` --> `PromotionRunEnvironmentStatus_Failed`
* Init function `SchemeBuilder.Register(&ApplicationPromotionRun{}, &ApplicationPromotionRunList{})` --> `SchemeBuilder.Register(&PromotionRun{}, &PromotionRunList{})` and it also required a `make generate` for the deepcopy to make it happy.
New stuff added:
* `PromotionRunCondition` and `PromotionRunReasonType` struct
* `PromotionRunConditionType` and `PromotionRunConditionStatus` string aliases
* 4 new consts: `PromotionRunConditionStatusTrue`, `PromotionRunConditionStatusFalse`, `PromotionRunConditionStatusUnknown`, `PromotionRunReasonErrorOccurred`
Now rename the file from `applicationpromotionrun_types.go` into `promotionrun_types.go`:
```bash
git mv applicationpromotionrun_types.go promotionrun_types.go
```
Next step is to generate a bunch of required manifests, and CRDs.
But the automation for doing this sucks, so in the best approach is to to see what Makefile is running underneath and execute the commands manually one-by-one. Here's an example:
Remove the already existing CRD YAML files as I have renamed the existing file (from `applicationpromotionrun_types.go` to `promotionrun_types.go`).
If you don't do it, the controller-gen will only generate new files and any old changes will remain as they are.
The problem is that kustomize will pick them up, look for these (e.g. it will try to read `applicationpromotionrun_types.go` in this specific case, and it will fail).
```bash
$ rm config/crd/bases/*
```
Now regegenerate these CRDs taking the command from the Makefile (see `make -n generate`).
In my case this is:
```bash
$ ./bin/controller-gen "crd:trivialVersions=true,preserveUnknownFields=false" rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
```
Now look for the removed file (you can check with `git status`, as it would be the only one missing and there will also be a new file):
```bash=
$ git status
On branch second_try
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
deleted: config/crd/bases/appstudio.redhat.com_applicationpromotionruns.yaml
Untracked files:
(use "git add <file>..." to include in what will be committed)
config/crd/bases/appstudio.redhat.com_promotionruns.yaml
Now check if any other file is expecting this old file to be present:
```bash
$ grep -rwn . -e 'appstudio.redhat.com_applicationpromotionruns.yaml'
./config/crd/kustomization.yaml:10:- bases/appstudio.redhat.com_applicationpromotionruns.yaml
```
Ok, so I am not aware of any way to generate `kustomization.yaml`.
It is supposed to happen with either `kubebuilder` or `operator-sdk` but I need correct version installed, the exact flags that were used for the project when it was bootstrapped, otherwise you are going for a wild goose hunt. I've decided to just modify this by hand:
Go to `./config/crd/kustomization.yaml` and remove this line that expected this old file to be present.
Then replace it with the new filename: `bases/appstudio.redhat.com_promotionruns.yaml`
For example:
```diff=
diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml
index b15b3a6..e16ce94 100644
--- a/config/crd/kustomization.yaml
+++ b/config/crd/kustomization.yaml
@@ -7,7 +7,7 @@ resources:
- bases/appstudio.redhat.com_componentdetectionqueries.yaml
- bases/appstudio.redhat.com_applicationsnapshotenvironmentbindings.yaml
- bases/appstudio.redhat.com_applicationsnapshots.yaml
-- bases/appstudio.redhat.com_applicationpromotionruns.yaml
+- bases/appstudio.redhat.com_promotionruns.yaml
- bases/appstudio.redhat.com_environments.yaml
#+kubebuilder:scaffold:crdkustomizeresource
```
Now, we should be ready to run the new kustomize command (taken from `make -n manifests`).
```bash
./bin/kustomize build config/crd > manifests/application-api-customresourcedefinitions.yaml
```
Did it work? Excellent. Now let's move on.
I've noticed it is running more stuff when doing `make -n manifests`, so continue doing so by hand:
```bash
/Library/Developer/CommandLineTools/usr/bin/make manifests-kcp
```
This will generate changes for these files:
- config/kcp/apiexport.yaml
- config/kcp/apiresourceschema.yam
Ok, proceed to the next command:
```bash
hack/generate-kcp-api.sh
```
It doesn't seem to introduce any new changes.
So commit all these and push :D
The CI is green now.
I will proceed with modifying the rest of the files.
----
## snapshot_types.go
Changes:
* `ApplicationSnapshotSpec` struct rename --> `SnapshotSpec` (required to introduce changes for `SnapshotComponent` as well)
* `ApplicationSnapshotComponent` struct rename --> `SnapshotComponent`
* `SnapshotStatus` struct rename --> `SnapshotStatus
* `ApplicationSnapshot` struct rename --> `Snapshot` (required to change `SnapshotSpec` and `SnapshotStatus` as well)
* `ApplicationSnapshotList` struct rename -- `SnapshotList`
* Init `chemeBuilder.Register(&ApplicationSnapshot{}, &ApplicationSnapshotList{})` --> ` SchemeBuilder.Register(&Snapshot{}, &SnapshotList{})` (required `make generate` to keep it happy)
## snapshotenvironmentbinding_types.go
Changes:
* `SnapshotEnvironmentBindingSpec` struct rename --> `SnapshotEnvironmentBindingSpec`
* `ApplicationSnapshotEnvironmentBindingStatus` struct rename --> `SnapshotEnvironmentBindingStatus`
* `ApplicationSnapshotEnvironmentBinding` struct name --> `SnapshotEnvironmentBinding` (require change for `SnapshotEnvironmentBindingSpec` and `SnapshotEnvironmentBindingStatus`)
* `ApplicationSnapshotEnvironmentBindingList` struct name --> `SnapshotEnvironmentBindingList` (require change for `SnapshotEnvironmentBinding` as well)
* Init ` SchemeBuilder.Register(&ApplicationSnapshotEnvironmentBinding{}, &ApplicationSnapshotEnvironmentBindingList{})
` --> ` SchemeBuilder.Register(&SnapshotEnvironmentBinding{}, &SnapshotEnvironmentBindingList{})` (required `make generate` to keep it happy for the deepcopy)
----
config/rbac -- they need +kubebuilder/rbac tags which are missing (!)
Same:
* environment_editor_role.yaml
* environment_viewer_role.yaml
Changes:
* applicationpromotionrun_editor_role.yaml --> promotionrun_editor_role.yaml
* applicationpromotionrun_viewer_role.yaml --> promotionrun_viewer_role.yaml
* snapshot_editor_role.yaml --> applicationsnapshot_editor_role.yaml
* applicationsnapshot_viewer_role.yaml --> snapshot_viewer_role.yaml
* applicationsnapshotenvironmentbinding_editor_role.yaml --> snapshotenvironmentbinding_editor_role.yaml
* applicationsnapshotenvironmentbinding_viewer_role.yaml --> snapshotenvironmentbinding_viewer_role.yaml
New files:
* kustomization.yaml
* leader_election_role.yaml
* leader_election_role_binding.yaml
* role_binding.yaml
* service_account.yaml
* auth_proxy_client_clusterrole.yaml
* auth_proxy_role.yaml
* auth_proxy_role_binding.yaml
* auth_proxy_service.yaml