-
Notifications
You must be signed in to change notification settings - Fork 1.8k
doc/migration: add sections for v0.8.x and v0.9.x #1891
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -144,7 +144,7 @@ The following sections outline the upgrade steps for each SDK version along with | |||||||
```TOML | ||||||||
[[constraint]] | ||||||||
name = "github.com/operator-framework/operator-sdk" | ||||||||
version = "=v0.4.1" | ||||||||
version = "=v0.6.0" | ||||||||
``` | ||||||||
|
||||||||
- The `operator-sdk olm-catalog` command now expects and generates manifests in the operator-registry [manifest format][manifest-format]. Generate your CSVs in the new layout by using `operator-sdk olm-catalog gen-csv` command, or modify the layout of your existing CSV manifests directory similar to the example below. | ||||||||
|
@@ -168,8 +168,179 @@ The following sections outline the upgrade steps for each SDK version along with | |||||||
version = "=v0.7.1" | ||||||||
``` | ||||||||
|
||||||||
## `v0.8.x` | ||||||||
|
||||||||
The SDK version `v0.8.x` supports scaffolding projects to use Go modules by default. It is recommended that you migrate your operator project to use modules for dependency management, however you can choose to keep using `dep`. The upgrade steps for both are outlined below: | ||||||||
|
||||||||
### `dep` | ||||||||
|
||||||||
- Update the SDK constraint in `Gopkg.toml` to version `v0.8.2`. | ||||||||
```TOML | ||||||||
[[constraint]] | ||||||||
name = "github.com/operator-framework/operator-sdk" | ||||||||
version = "=v0.8.2" | ||||||||
``` | ||||||||
- Pin the controller-tools dependency to the following revision. See the release notes or [#1278](https://github.com/operator-framework/operator-sdk/pull/1278/) for why this is needed. | ||||||||
```TOML | ||||||||
[[override]] | ||||||||
name = "sigs.k8s.io/controller-tools" | ||||||||
revision = "9d55346c2bde73fb3326ac22eac2e5210a730207" | ||||||||
``` | ||||||||
- Run `dep ensure` to update the vendor directory. | ||||||||
|
||||||||
### `modules` | ||||||||
|
||||||||
To get familiar with Go modules read the [modules wiki][modules-wiki]. In particular the section on [migrating to modules][migrating-to-modules]. | ||||||||
|
||||||||
- Ensure that you have Go 1.12+ and [Mercurial][mercurial] 3.9+ installed. | ||||||||
- Activate Go modules support for your project in `$GOPATH/src` by setting the env `GO111MODULES=on`. See [activating modules][activating-modules] for more details. | ||||||||
- Initialize a new `go.mod` file by running `go mod init`. | ||||||||
- Append the following to the end of your `go.mod` file to pin the operator-sdk and other upstream dependencies to the required versions. | ||||||||
``` | ||||||||
// Pinned to kubernetes-1.13.1 | ||||||||
replace ( | ||||||||
k8s.io/api => k8s.io/api v0.0.0-20181213150558-05914d821849 | ||||||||
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.0.0-20181213153335-0fe22c71c476 | ||||||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20181127025237-2b1284ed4c93 | ||||||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20181213151034-8d9ed539ba31 | ||||||||
) | ||||||||
|
||||||||
replace ( | ||||||||
github.com/coreos/prometheus-operator => github.com/coreos/prometheus-operator v0.29.0 | ||||||||
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20181117043124-c2090bec4d9b | ||||||||
k8s.io/kube-openapi => k8s.io/kube-openapi v0.0.0-20180711000925-0cf8f7e6ed1d | ||||||||
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.1.10 | ||||||||
sigs.k8s.io/controller-tools => sigs.k8s.io/controller-tools v0.1.11-0.20190411181648-9d55346c2bde | ||||||||
) | ||||||||
|
||||||||
replace github.com/operator-framework/operator-sdk => github.com/operator-framework/operator-sdk v0.8.2 | ||||||||
``` | ||||||||
camilamacedo86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
- Run `go mod tidy` to clean up the `go.mod` file. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WDYT about we tell to the user's use the make commands in order to add use the GOPROXY? See Line 31 in 8bdd7c5
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Users don't have a Makefile in their projects, so |
||||||||
- In case of any go module loading errors, consult the default [`v0.8.2` go.mod dependencies][v0.8.2-go-mod] scaffolded by the operator-sdk to resolve any differences. You can also view this file by scaffolding a new project with operator-sdk `v0.8.2`. | ||||||||
- Ensure that you can build the project with `operator-sdk build` | ||||||||
- Finally remove `Gopkg.lock`, `Gopkg.toml` and the vendor directory. | ||||||||
|
||||||||
### Breaking changes | ||||||||
|
||||||||
Upon updating the project to `v0.8.2` the following breaking changes apply: | ||||||||
|
||||||||
- On running the command `operator-sdk generate openapi`, the CRD manifests at `deploy/crds/<group>_<version>_<kind>.crd` for all API types will now be regenerated based on their source files `pkg/apis/..._types.go`. So if you have made any manual edits to the default generated CRD manifest, e.g manually written the validation block or specified the naming (`spec.names`), then that information be overwritten when the CRD is regenerated. | ||||||||
|
||||||||
The correct way to specify CRD fields like naming, validation, subresources etc is by using `// +kubebuilder` marker comments. Consult the [legacy kubebuilder documentation][legacy-kubebuilder-doc-crd] to see what CRD fields can be generated via `// +kubebuilder` marker comments. | ||||||||
|
||||||||
**Note:** The version of controller-tools tied to this release does not support settting the `spec.scope` field of the CRD. Use the marker comment `+genclient:nonNamespaced` to set `spec.scope=Cluster` if necessary. See the example below: | ||||||||
```Go | ||||||||
// MemcachedSpec defines the desired state of Memcached | ||||||||
type MemcachedSpec struct { | ||||||||
// +kubebuilder:validation:Maximum=5 | ||||||||
// +kubebuilder:validation:Minimum=1 | ||||||||
Size int32 `json:"size"` | ||||||||
} | ||||||||
|
||||||||
// MemcachedStatus defines the observed state of Memcached | ||||||||
type MemcachedStatus struct { | ||||||||
// +kubebuilder:validation:MaxItems=5 | ||||||||
// +kubebuilder:validation:MinItems=1 | ||||||||
Nodes []string `json:"nodes"` | ||||||||
} | ||||||||
|
||||||||
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object | ||||||||
|
||||||||
// Memcached is the Schema for the memcacheds API | ||||||||
// +kubebuilder:subresource:status | ||||||||
// +kubebuilder:resource:shortName="mc" | ||||||||
// +genclient:nonNamespaced | ||||||||
type Memcached struct { | ||||||||
metav1.TypeMeta `json:",inline"` | ||||||||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||||||||
|
||||||||
Spec MemcachedSpec `json:"spec,omitempty"` | ||||||||
Status MemcachedStatus `json:"status,omitempty"` | ||||||||
} | ||||||||
``` | ||||||||
|
||||||||
## `v0.9.x` | ||||||||
|
||||||||
- The function `ExposeMetricsPort()` has been replaced with `CreateMetricsService()` [#1560](https://github.com/operator-framework/operator-sdk/pull/1560). | ||||||||
camilamacedo86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
|
||||||||
Replace the following line in `cmd/manager/main.go` | ||||||||
```Go | ||||||||
_, err = metrics.ExposeMetricsPort(ctx, metricsPort) | ||||||||
``` | ||||||||
with | ||||||||
```Go | ||||||||
servicePorts := []v1.ServicePort{ | ||||||||
{Port: metricsPort, Name: metrics.OperatorPortName, Protocol: v1.ProtocolTCP, TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: metricsPort}}, | ||||||||
{Port: operatorMetricsPort, Name: metrics.CRPortName, Protocol: v1.ProtocolTCP, TargetPort: intstr.IntOrString{Type: intstr.Int, IntVal: operatorMetricsPort}}, | ||||||||
} | ||||||||
|
||||||||
_, err = metrics.CreateMetricsService(ctx, servicePorts) | ||||||||
``` | ||||||||
|
||||||||
### `dep` | ||||||||
|
||||||||
- Update the SDK constraint in `Gopkg.toml` to version `v0.9.0`, the kubernetes dependencies to `kubernetes-1.13.4` revisions, and the controller-runtime version to `v0.1.12`. | ||||||||
```TOML | ||||||||
[[override]] | ||||||||
name = "k8s.io/api" | ||||||||
# revision for tag "kubernetes-1.13.4" | ||||||||
revision = "5cb15d34447165a97c76ed5a60e4e99c8a01ecfe" | ||||||||
[[override]] | ||||||||
name = "k8s.io/apiextensions-apiserver" | ||||||||
# revision for tag "kubernetes-1.13.4" | ||||||||
revision = "d002e88f6236312f0289d9d1deab106751718ff0" | ||||||||
[[override]] | ||||||||
name = "k8s.io/apimachinery" | ||||||||
# revision for tag "kubernetes-1.13.4" | ||||||||
revision = "86fb29eff6288413d76bd8506874fddd9fccdff0" | ||||||||
[[override]] | ||||||||
name = "k8s.io/client-go" | ||||||||
# revision for tag "kubernetes-1.13.4" | ||||||||
revision = "b40b2a5939e43f7ffe0028ad67586b7ce50bb675" | ||||||||
[[override]] | ||||||||
name = "github.com/coreos/prometheus-operator" | ||||||||
version = "=v0.29.0" | ||||||||
[[override]] | ||||||||
name = "sigs.k8s.io/controller-runtime" | ||||||||
version = "=v0.1.12" | ||||||||
[[constraint]] | ||||||||
name = "github.com/operator-framework/operator-sdk" | ||||||||
version = "=v0.9.0" | ||||||||
``` | ||||||||
- Append the contraint for `k8s.io/kube-state-metrics`. | ||||||||
```TOML | ||||||||
[[override]] | ||||||||
name = "k8s.io/kube-state-metrics" | ||||||||
version = "v1.6.0" | ||||||||
``` | ||||||||
- Run `dep ensure` to update the vendor directory. | ||||||||
|
||||||||
### modules | ||||||||
|
||||||||
- Update the `replace` directives in your `go.mod` file for the SDK, kubernetes, controller-runtime and kube-state metrics dependencies to the following versions. | ||||||||
``` | ||||||||
// Pinned to kubernetes-1.13.4 | ||||||||
replace ( | ||||||||
k8s.io/api => k8s.io/api v0.0.0-20190222213804-5cb15d344471 | ||||||||
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.0.0-20190228180357-d002e88f6236 | ||||||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20190221213512-86fb29eff628 | ||||||||
k8s.io/client-go => k8s.io/client-go v0.0.0-20190228174230-b40b2a5939e4 | ||||||||
) | ||||||||
replace ( | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May it needs to be updated as #1899 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My first thought is probably not. I don't want to add it to the guide since this isn't an issue specifically with the SDK and something that's easily if you run into the issue. Although it looks like https://status.apache.org/ is down quite often so maybe if we merge #1899 I can do a follow up. |
||||||||
github.com/coreos/prometheus-operator => github.com/coreos/prometheus-operator v0.29.0 | ||||||||
sigs.k8s.io/controller-runtime => sigs.k8s.io/controller-runtime v0.1.12 | ||||||||
sigs.k8s.io/controller-tools => sigs.k8s.io/controller-tools v0.1.11-0.20190411181648-9d55346c2bde | ||||||||
k8s.io/kube-state-metrics => k8s.io/kube-state-metrics v1.6.0 | ||||||||
) | ||||||||
replace github.com/operator-framework/operator-sdk => github.com/operator-framework/operator-sdk v0.9.0 | ||||||||
``` | ||||||||
|
||||||||
[legacy-kubebuilder-doc-crd]: https://book-v1.book.kubebuilder.io/beyond_basics/generating_crd.html | ||||||||
[v0.8.2-go-mod]: https://github.com/operator-framework/operator-sdk/blob/28bd2b0d4fd25aa68e15d928ae09d3c18c3b51da/internal/pkg/scaffold/go_mod.go#L40-L94 | ||||||||
[activating-modules]: https://github.com/golang/go/wiki/Modules#how-to-install-and-activate-module-support | ||||||||
[mercurial]: https://www.mercurial-scm.org/downloads | ||||||||
[migrating-to-modules]: https://github.com/golang/go/wiki/Modules#migrating-to-modules | ||||||||
[modules-wiki]: https://github.com/golang/go/wiki/Modules#migrating-to-modules | ||||||||
[print-deps-cli]: ../sdk-cli-reference.md#print-deps | ||||||||
[changelog]: ../../CHANGELOG.md | ||||||||
[release-notes]: https://github.com/operator-framework/operator-sdk/releases | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, is required to:
group.go
For the Object Struct
For the Object Status and Spec
At least I need to check it too in the projects, so I'd recommend checking these points as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding
group.go
isn't really necessary since it's not a breaking change. It only suppresses a warning from gengo when running the gen-code commands.But you're right on the second point: I should highlight the need for
+kubebuilder
tags now that CRD manifests are overwritten inv0.8.x
and will remove any manual edits made by users to the CRD.From the CHANGELOG:
This probably should have been marked as breaking change to begin with. Well spotted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I can't recall if I had to setup mercurial when I used Go modules but it's definitely part of our pre-reqs:
https://github.com/operator-framework/operator-sdk#prerequisites
Although it might be one of git or mercurial:
https://github.com/golang/go/wiki/GoGetTools
I'll need to double check and remove it from the SDK's pre-reqs if that's not the case.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fairly sure mercurial was/is required. I'm pretty sure some transitive dependency somewhere comes from a mercurial repo.
Also, just be careful about which kubebuilder tags are mentioned about being needed/supported. We won't switch to controller-tools 0.2.x until the next release, so tags like
+kubebuilder:subresource:status
that were added in controller-tools 0.2.0 should not be mentioned.EDIT: Nevermind - looks like you have that covered in line 229 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I've linked to the legacy kubebuilder docs to show that not all marker comments are supported for the controller-tools version tied SDK release v0.8.2.
But
// +kubebuilder:subresource:status
specifically is supported pre controller-tools v0.2.0 so I've kept that in the example.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HI @joelanford, @hasbro17
I just would like to share that I have NO mercurial installed locally and all are working. Maybe it is specific to some kind of operator so. Also, I could not find anything in the code over it. If it is there let's keep but if possible, I'd like to understand to learn where it has been used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@camilamacedo86 The mercurial command is
hg
, so check if you have that.Here's the original issue: #1681
Looks like it affected 0.9 at least, not sure about 0.8 or 0.10.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I lot of shame now :-P Yes, I have it! All explained tks for the patient with me.