-
Notifications
You must be signed in to change notification settings - Fork 991
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
Use code-generation for CRD API and deepcopy methods #369
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
11efe23
Use autogenerated code for CRDs.
alexeyklyukin b25b712
Use generated postgres shared informer.
alexeyklyukin 15edc82
Generate code for the OperatorConfiguration CRD.
alexeyklyukin 9581c78
Use generated code to set status of CRD objects as well.
alexeyklyukin 560cda8
Revert the status to be a single string field.
alexeyklyukin aaabf4e
Update client-go dependencies, run gofmt -s.
alexeyklyukin 879de5b
Merge branch 'master' into crd_autogeneration
alexeyklyukin e999846
Generate less code for the operator config.
alexeyklyukin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
Copyright YEAR Compose, Zalando SE | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/.. | ||
CODEGEN_PKG=${CODEGEN_PKG:-$(cd ${SCRIPT_ROOT}; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ${GOPATH}/src/k8s.io/code-generator)} | ||
|
||
vendor/k8s.io/code-generator/generate-groups.sh all \ | ||
github.com/zalando-incubator/postgres-operator/pkg/generated github.com/zalando-incubator/postgres-operator/pkg/apis \ | ||
acid.zalan.do:v1 \ | ||
--go-header-file ${SCRIPT_ROOT}/hack/custom-boilerplate.go.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")/.. | ||
DIFFROOT="${SCRIPT_ROOT}/pkg" | ||
TMP_DIFFROOT="${SCRIPT_ROOT}/_tmp/pkg" | ||
_tmp="${SCRIPT_ROOT}/_tmp" | ||
|
||
cleanup() { | ||
rm -rf "${_tmp}" | ||
} | ||
trap "cleanup" EXIT SIGINT | ||
|
||
cleanup | ||
|
||
mkdir -p "${TMP_DIFFROOT}" | ||
cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}" | ||
|
||
"${SCRIPT_ROOT}/hack/update-codegen.sh" | ||
echo "diffing ${DIFFROOT} against freshly generated codegen" | ||
ret=0 | ||
diff -Naupr "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$? | ||
cp -a "${TMP_DIFFROOT}"/* "${DIFFROOT}" | ||
if [[ $ret -eq 0 ]] | ||
then | ||
echo "${DIFFROOT} up to date." | ||
else | ||
echo "${DIFFROOT} is out of date. Please run hack/update-codegen.sh" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package acidzalando | ||
|
||
const ( | ||
GroupName = "acid.zalan.do" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package v1 | ||
|
||
const ( | ||
serviceNameMaxLength = 63 | ||
clusterNameMaxLength = serviceNameMaxLength - len("-repl") | ||
serviceNameRegexString = `^[a-z]([-a-z0-9]*[a-z0-9])?$` | ||
|
||
ClusterStatusUnknown ClusterStateType = "" | ||
ClusterStatusCreating ClusterStateType = "Creating" | ||
ClusterStatusUpdating ClusterStateType = "Updating" | ||
ClusterStatusUpdateFailed ClusterStateType = "UpdateFailed" | ||
ClusterStatusSyncFailed ClusterStateType = "SyncFailed" | ||
ClusterStatusAddFailed ClusterStateType = "CreateFailed" | ||
ClusterStatusRunning ClusterStateType = "Running" | ||
ClusterStatusInvalid ClusterStateType = "Invalid" | ||
|
||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// +k8s:deepcopy-gen=package,register | ||
|
||
// Package v1 is the v1 version of the API. | ||
// +groupName=acid.zalan.do | ||
|
||
package v1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package v1 | ||
|
||
import ( | ||
"encoding/json" | ||
"strings" | ||
"fmt" | ||
"time" | ||
) | ||
|
||
type postgresqlCopy Postgresql | ||
|
||
// MarshalJSON converts a maintenance window definition to JSON. | ||
func (m *MaintenanceWindow) MarshalJSON() ([]byte, error) { | ||
if m.Everyday { | ||
return []byte(fmt.Sprintf("\"%s-%s\"", | ||
m.StartTime.Format("15:04"), | ||
m.EndTime.Format("15:04"))), nil | ||
} | ||
|
||
return []byte(fmt.Sprintf("\"%s:%s-%s\"", | ||
m.Weekday.String()[:3], | ||
m.StartTime.Format("15:04"), | ||
m.EndTime.Format("15:04"))), nil | ||
} | ||
|
||
// UnmarshalJSON converts a JSON to the maintenance window definition. | ||
func (m *MaintenanceWindow) UnmarshalJSON(data []byte) error { | ||
var ( | ||
got MaintenanceWindow | ||
err error | ||
) | ||
|
||
parts := strings.Split(string(data[1:len(data)-1]), "-") | ||
if len(parts) != 2 { | ||
return fmt.Errorf("incorrect maintenance window format") | ||
} | ||
|
||
fromParts := strings.Split(parts[0], ":") | ||
switch len(fromParts) { | ||
case 3: | ||
got.Everyday = false | ||
got.Weekday, err = parseWeekday(fromParts[0]) | ||
if err != nil { | ||
return fmt.Errorf("could not parse weekday: %v", err) | ||
} | ||
|
||
got.StartTime, err = parseTime(fromParts[1] + ":" + fromParts[2]) | ||
case 2: | ||
got.Everyday = true | ||
got.StartTime, err = parseTime(fromParts[0] + ":" + fromParts[1]) | ||
default: | ||
return fmt.Errorf("incorrect maintenance window format") | ||
} | ||
if err != nil { | ||
return fmt.Errorf("could not parse start time: %v", err) | ||
} | ||
|
||
got.EndTime, err = parseTime(parts[1]) | ||
if err != nil { | ||
return fmt.Errorf("could not parse end time: %v", err) | ||
} | ||
|
||
if got.EndTime.Before(&got.StartTime) { | ||
return fmt.Errorf("'From' time must be prior to the 'To' time") | ||
} | ||
|
||
*m = got | ||
|
||
return nil | ||
} | ||
|
||
// UnmarshalJSON converts a JSON into the PostgreSQL object. | ||
func (p *Postgresql) UnmarshalJSON(data []byte) error { | ||
var tmp postgresqlCopy | ||
|
||
err := json.Unmarshal(data, &tmp) | ||
if err != nil { | ||
metaErr := json.Unmarshal(data, &tmp.ObjectMeta) | ||
if metaErr != nil { | ||
return err | ||
} | ||
|
||
tmp.Error = err.Error() | ||
tmp.Status = PostgresStatus{State: ClusterStatusInvalid} | ||
|
||
*p = Postgresql(tmp) | ||
|
||
return nil | ||
} | ||
tmp2 := Postgresql(tmp) | ||
|
||
if clusterName, err := extractClusterName(tmp2.ObjectMeta.Name, tmp2.Spec.TeamID); err != nil { | ||
tmp2.Error = err.Error() | ||
tmp2.Status = PostgresStatus{ClusterStatusInvalid} | ||
} else if err := validateCloneClusterDescription(&tmp2.Spec.Clone); err != nil { | ||
tmp2.Error = err.Error() | ||
tmp2.Status = PostgresStatus{ClusterStatusInvalid} | ||
} else { | ||
tmp2.Spec.ClusterName = clusterName | ||
} | ||
|
||
*p = tmp2 | ||
|
||
return nil | ||
} | ||
|
||
func (d *Duration) UnmarshalJSON(b []byte) error { | ||
var ( | ||
v interface{} | ||
err error | ||
) | ||
if err = json.Unmarshal(b, &v); err != nil { | ||
return err | ||
} | ||
switch val := v.(type) { | ||
case string: | ||
t, err := time.ParseDuration(val) | ||
if err != nil { | ||
return err | ||
} | ||
*d = Duration(t) | ||
return nil | ||
case float64: | ||
t := time.Duration(val) | ||
*d = Duration(t) | ||
return nil | ||
default: | ||
return fmt.Errorf("could not recognize type %T as a valid type to unmarshal to Duration", val) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This renaming was necessary because the older name with dashes broke the code generation process.