mirror of
https://github.com/1Password/onepassword-operator.git
synced 2025-10-25 00:40:49 +00:00
Upgrade the operator to use Operator SDK v1.33.0 (#182)
* Move controller package inside internal directory Based on the go/v4 project structure, the following changed: - Pakcage `controllers` is now named `controller` - Package `controller` now lives inside new `internal` directory * Move main.go in cmd directory Based on the new go/v4 project structure, `main.go` now lives in the `cmd` directory. * Change package import in main.go * Update go mod dependencies Update the dependencies based on the versions obtained by creating a new operator project using `kubebuilder init --domain onepassword.com --plugins=go/v4`. This is based on the migration steps provided to go from go/v3 to go/v4 (https://book.kubebuilder.io/migration/migration_guide_gov3_to_gov4) * Update vendor * Adjust code for breaking changes from pkg update sigs.k8s.io/controller-runtime package had breaking changes from v0.14.5 to v0.16.3. This commit brings the changes needed to achieve the same things using the new functionality avaialble. * Adjust paths to connect yaml files Since `main.go` is now in `cmd` directory, the paths to the files for deploying Connect have to be adjusted based on the new location `main.go` is executed from. * Update files based on new structure and scaffolding These changes are made based on the new project structure and scaffolding obtained when using the new go/v4 project structure. These were done based on the migration steps mentioned when migrating to go/v4 (https://book.kubebuilder.io/migration/migration_guide_gov3_to_gov4). * Update config files These updates are made based on the Kustomize v4 syntax. This is part of the upgrate to go/v4 (https://book.kubebuilder.io/migration/migration_guide_gov3_to_gov4) * Update dependencies and GO version * Update vendor * Update Kubernetes tools versions * Update operator version in Makefile Now the version in the Makefile matches the version of the operator * Update Operator SDK version in version.go * Adjust generated deepcopy It seems that the +build tag is no longer needed based on the latest generated scaffolding, therefore it's removed. * Update copyright year * Bring back missing changes from migration Some customization in Makefile was lost during the migration process. Specifically, the namespace customization for `make deploy` command. Also, we push changes to kustomization.yaml for making the deploy process smoother. * Add RBAC perms for coordination.k8s.io It seems that with the latest changes to Kubernetes and Kustomize, we need to add additional RBAC to the service account used so that it can properly access the `leases` resource. * Optimize Dockerfile Dockerfile had a step for caching dependencies (go mod download). However, this is already done by the vendor directory, which we include. Therefore, this step can be removed to make the image build time faster.
This commit is contained in:
2
vendor/k8s.io/apimachinery/pkg/labels/labels.go
generated
vendored
2
vendor/k8s.io/apimachinery/pkg/labels/labels.go
generated
vendored
@@ -77,6 +77,8 @@ func (ls Set) AsValidatedSelector() (Selector, error) {
|
||||
// perform any validation.
|
||||
// According to our measurements this is significantly faster
|
||||
// in codepaths that matter at high scale.
|
||||
// Note: this method copies the Set; if the Set is immutable, consider wrapping it with ValidatedSetSelector
|
||||
// instead, which does not copy.
|
||||
func (ls Set) AsSelectorPreValidated() Selector {
|
||||
return SelectorFromValidatedSet(ls)
|
||||
}
|
||||
|
||||
131
vendor/k8s.io/apimachinery/pkg/labels/selector.go
generated
vendored
131
vendor/k8s.io/apimachinery/pkg/labels/selector.go
generated
vendored
@@ -149,14 +149,12 @@ type Requirement struct {
|
||||
|
||||
// NewRequirement is the constructor for a Requirement.
|
||||
// If any of these rules is violated, an error is returned:
|
||||
// (1) The operator can only be In, NotIn, Equals, DoubleEquals, Gt, Lt, NotEquals, Exists, or DoesNotExist.
|
||||
// (2) If the operator is In or NotIn, the values set must be non-empty.
|
||||
// (3) If the operator is Equals, DoubleEquals, or NotEquals, the values set must contain one value.
|
||||
// (4) If the operator is Exists or DoesNotExist, the value set must be empty.
|
||||
// (5) If the operator is Gt or Lt, the values set must contain only one value, which will be interpreted as an integer.
|
||||
// (6) The key is invalid due to its length, or sequence
|
||||
//
|
||||
// of characters. See validateLabelKey for more details.
|
||||
// 1. The operator can only be In, NotIn, Equals, DoubleEquals, Gt, Lt, NotEquals, Exists, or DoesNotExist.
|
||||
// 2. If the operator is In or NotIn, the values set must be non-empty.
|
||||
// 3. If the operator is Equals, DoubleEquals, or NotEquals, the values set must contain one value.
|
||||
// 4. If the operator is Exists or DoesNotExist, the value set must be empty.
|
||||
// 5. If the operator is Gt or Lt, the values set must contain only one value, which will be interpreted as an integer.
|
||||
// 6. The key is invalid due to its length, or sequence of characters. See validateLabelKey for more details.
|
||||
//
|
||||
// The empty string is a valid value in the input values set.
|
||||
// Returned error, if not nil, is guaranteed to be an aggregated field.ErrorList
|
||||
@@ -213,22 +211,15 @@ func (r *Requirement) hasValue(value string) bool {
|
||||
|
||||
// Matches returns true if the Requirement matches the input Labels.
|
||||
// There is a match in the following cases:
|
||||
// (1) The operator is Exists and Labels has the Requirement's key.
|
||||
// (2) The operator is In, Labels has the Requirement's key and Labels'
|
||||
//
|
||||
// value for that key is in Requirement's value set.
|
||||
//
|
||||
// (3) The operator is NotIn, Labels has the Requirement's key and
|
||||
//
|
||||
// Labels' value for that key is not in Requirement's value set.
|
||||
//
|
||||
// (4) The operator is DoesNotExist or NotIn and Labels does not have the
|
||||
//
|
||||
// Requirement's key.
|
||||
//
|
||||
// (5) The operator is GreaterThanOperator or LessThanOperator, and Labels has
|
||||
//
|
||||
// the Requirement's key and the corresponding value satisfies mathematical inequality.
|
||||
// 1. The operator is Exists and Labels has the Requirement's key.
|
||||
// 2. The operator is In, Labels has the Requirement's key and Labels'
|
||||
// value for that key is in Requirement's value set.
|
||||
// 3. The operator is NotIn, Labels has the Requirement's key and
|
||||
// Labels' value for that key is not in Requirement's value set.
|
||||
// 4. The operator is DoesNotExist or NotIn and Labels does not have the
|
||||
// Requirement's key.
|
||||
// 5. The operator is GreaterThanOperator or LessThanOperator, and Labels has
|
||||
// the Requirement's key and the corresponding value satisfies mathematical inequality.
|
||||
func (r *Requirement) Matches(ls Labels) bool {
|
||||
switch r.operator {
|
||||
case selection.In, selection.Equals, selection.DoubleEquals:
|
||||
@@ -872,15 +863,14 @@ func (p *Parser) parseExactValue() (sets.String, error) {
|
||||
// "x in (foo,,baz),y,z notin ()"
|
||||
//
|
||||
// Note:
|
||||
//
|
||||
// (1) Inclusion - " in " - denotes that the KEY exists and is equal to any of the
|
||||
// VALUEs in its requirement
|
||||
// (2) Exclusion - " notin " - denotes that the KEY is not equal to any
|
||||
// of the VALUEs in its requirement or does not exist
|
||||
// (3) The empty string is a valid VALUE
|
||||
// (4) A requirement with just a KEY - as in "y" above - denotes that
|
||||
// the KEY exists and can be any VALUE.
|
||||
// (5) A requirement with just !KEY requires that the KEY not exist.
|
||||
// 1. Inclusion - " in " - denotes that the KEY exists and is equal to any of the
|
||||
// VALUEs in its requirement
|
||||
// 2. Exclusion - " notin " - denotes that the KEY is not equal to any
|
||||
// of the VALUEs in its requirement or does not exist
|
||||
// 3. The empty string is a valid VALUE
|
||||
// 4. A requirement with just a KEY - as in "y" above - denotes that
|
||||
// the KEY exists and can be any VALUE.
|
||||
// 5. A requirement with just !KEY requires that the KEY not exist.
|
||||
func Parse(selector string, opts ...field.PathOption) (Selector, error) {
|
||||
parsedSelector, err := parse(selector, field.ToPath(opts...))
|
||||
if err == nil {
|
||||
@@ -948,6 +938,8 @@ func ValidatedSelectorFromSet(ls Set) (Selector, error) {
|
||||
// SelectorFromValidatedSet returns a Selector which will match exactly the given Set.
|
||||
// A nil and empty Sets are considered equivalent to Everything().
|
||||
// It assumes that Set is already validated and doesn't do any validation.
|
||||
// Note: this method copies the Set; if the Set is immutable, consider wrapping it with ValidatedSetSelector
|
||||
// instead, which does not copy.
|
||||
func SelectorFromValidatedSet(ls Set) Selector {
|
||||
if ls == nil || len(ls) == 0 {
|
||||
return internalSelector{}
|
||||
@@ -969,3 +961,76 @@ func SelectorFromValidatedSet(ls Set) Selector {
|
||||
func ParseToRequirements(selector string, opts ...field.PathOption) ([]Requirement, error) {
|
||||
return parse(selector, field.ToPath(opts...))
|
||||
}
|
||||
|
||||
// ValidatedSetSelector wraps a Set, allowing it to implement the Selector interface. Unlike
|
||||
// Set.AsSelectorPreValidated (which copies the input Set), this type simply wraps the underlying
|
||||
// Set. As a result, it is substantially more efficient. A nil and empty Sets are considered
|
||||
// equivalent to Everything().
|
||||
//
|
||||
// Callers MUST ensure the underlying Set is not mutated, and that it is already validated. If these
|
||||
// constraints are not met, Set.AsValidatedSelector should be preferred
|
||||
//
|
||||
// None of the Selector methods mutate the underlying Set, but Add() and Requirements() convert to
|
||||
// the less optimized version.
|
||||
type ValidatedSetSelector Set
|
||||
|
||||
func (s ValidatedSetSelector) Matches(labels Labels) bool {
|
||||
for k, v := range s {
|
||||
if !labels.Has(k) || v != labels.Get(k) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (s ValidatedSetSelector) Empty() bool {
|
||||
return len(s) == 0
|
||||
}
|
||||
|
||||
func (s ValidatedSetSelector) String() string {
|
||||
keys := make([]string, 0, len(s))
|
||||
for k := range s {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
// Ensure deterministic output
|
||||
sort.Strings(keys)
|
||||
b := strings.Builder{}
|
||||
for i, key := range keys {
|
||||
v := s[key]
|
||||
b.Grow(len(key) + 2 + len(v))
|
||||
if i != 0 {
|
||||
b.WriteString(",")
|
||||
}
|
||||
b.WriteString(key)
|
||||
b.WriteString("=")
|
||||
b.WriteString(v)
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
|
||||
func (s ValidatedSetSelector) Add(r ...Requirement) Selector {
|
||||
return s.toFullSelector().Add(r...)
|
||||
}
|
||||
|
||||
func (s ValidatedSetSelector) Requirements() (requirements Requirements, selectable bool) {
|
||||
return s.toFullSelector().Requirements()
|
||||
}
|
||||
|
||||
func (s ValidatedSetSelector) DeepCopySelector() Selector {
|
||||
res := make(ValidatedSetSelector, len(s))
|
||||
for k, v := range s {
|
||||
res[k] = v
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func (s ValidatedSetSelector) RequiresExactMatch(label string) (value string, found bool) {
|
||||
v, f := s[label]
|
||||
return v, f
|
||||
}
|
||||
|
||||
func (s ValidatedSetSelector) toFullSelector() Selector {
|
||||
return SelectorFromValidatedSet(Set(s))
|
||||
}
|
||||
|
||||
var _ Selector = ValidatedSetSelector{}
|
||||
|
||||
Reference in New Issue
Block a user