-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add watch filtering by applyset label
- Add "applyset.kubernetes.io/part-of" label to managed objects - Add "applyset.kubernetes.io/id" label to RootSyncs/RepoSyncs - Add "applyset.k8s.io/tooling" annotation to RootSyncs/RepoSyncs - Error if the RSync already has a tooling annotation for a different tool (unlikely, but required by KEP). - Generate ApplySet IDs using kubectl code for compatibility. - Update TestKubectlCreatesManagedNamespaceResourceMultiRepo & TestAddUpdateDeleteLabels with new labels & annotations
- Loading branch information
Showing
19 changed files
with
751 additions
and
249 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,78 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package applyset | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"k8s.io/apimachinery/pkg/api/meta" | ||
"k8s.io/cli-runtime/pkg/resource" | ||
kubectlapply "k8s.io/kubectl/pkg/cmd/apply" | ||
"kpt.dev/configsync/pkg/declared" | ||
"kpt.dev/configsync/pkg/kinds" | ||
"kpt.dev/configsync/pkg/metadata" | ||
) | ||
|
||
// IDFromSync generates an ApplySet ID for the RootSync or RepoSync as | ||
// an ApplySet parent. | ||
func IDFromSync(syncName string, syncScope declared.Scope) string { | ||
return FromSync(syncName, syncScope, nil, nil).ID() | ||
} | ||
|
||
// FromSync constructs a new ApplySet for the specified RootSync or RepoSync. | ||
// The RESTMapper & RESTClient are optional, depending on which methods you plan | ||
// to call. | ||
func FromSync(syncName string, syncScope declared.Scope, mapper meta.RESTMapper, client resource.RESTClient) *kubectlapply.ApplySet { | ||
tooling := kubectlapply.ApplySetTooling{ | ||
Name: metadata.ApplySetToolingName, | ||
Version: metadata.ApplySetToolingVersion, | ||
} | ||
parent := &kubectlapply.ApplySetParentRef{ | ||
Name: syncName, | ||
Namespace: syncScope.SyncNamespace(), | ||
} | ||
switch syncScope { | ||
case declared.RootScope: | ||
parent.RESTMapping = kinds.RootSyncRESTMapping() | ||
default: | ||
parent.RESTMapping = kinds.RepoSyncRESTMapping() | ||
} | ||
return kubectlapply.NewApplySet(parent, tooling, mapper, client) | ||
} | ||
|
||
// ParseTooling parses the tooling value with format NAME/VERSION. | ||
// Returns an error if the input does not contain at least one slash (`/`). | ||
func ParseTooling(toolingValue string) (kubectlapply.ApplySetTooling, error) { | ||
parts := strings.Split(toolingValue, "/") | ||
if len(parts) >= 2 { | ||
return kubectlapply.ApplySetTooling{ | ||
Name: strings.Join(parts[:len(parts)-1], "/"), | ||
Version: parts[len(parts)-1], | ||
}, nil | ||
} | ||
// Invalid | ||
return kubectlapply.ApplySetTooling{}, | ||
fmt.Errorf("invalid applyset tooling value: expected NAME/VERSION: %s", toolingValue) | ||
} | ||
|
||
// FormatTooling returns a formatted value for the ApplySet tooling annotation. | ||
func FormatTooling(name, version string) string { | ||
tooling := kubectlapply.ApplySetTooling{ | ||
Name: name, | ||
Version: version, | ||
} | ||
return tooling.String() | ||
} |
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
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,56 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package metadata | ||
|
||
import ( | ||
kubectlapply "k8s.io/kubectl/pkg/cmd/apply" | ||
"kpt.dev/configsync/pkg/api/configsync" | ||
) | ||
|
||
// Labels with the `applyset.kubernetes.io/` prefix. | ||
const ( | ||
// ApplySetPartOfLabel is the key of the label which indicates that the | ||
// object is a member of an ApplySet. The value of the label MUST match the | ||
// value of ApplySetParentIDLabel on the parent object. | ||
ApplySetPartOfLabel = kubectlapply.ApplysetPartOfLabel | ||
|
||
// ApplySetParentIDLabel is the key of the label that makes object an | ||
// ApplySet parent object. Its value MUST use the format specified in | ||
// k8s.io/kubectl/pkg/cmd/apply.V1ApplySetIdFormat. | ||
ApplySetParentIDLabel = kubectlapply.ApplySetParentIDLabel | ||
) | ||
|
||
// Annotations with the `applyset.kubernetes.io/` prefix. | ||
const ( | ||
// ApplySetToolingAnnotation is the key of the label that indicates which | ||
// tool is used to manage this ApplySet. Tooling should refuse to mutate | ||
// ApplySets belonging to other tools. The value must be in the format | ||
// <toolname>/<semver>. Example value: "kubectl/v1.27" or "helm/v3" or | ||
// "kpt/v1.0.0" | ||
ApplySetToolingAnnotation = kubectlapply.ApplySetToolingAnnotation | ||
|
||
// ApplySetToolingName is the name used to represent Config Sync in the | ||
// ApplySet tooling annotation. | ||
ApplySetToolingName = configsync.GroupName | ||
|
||
// ApplySetToolingVersion is the version used to represent Config Sync in | ||
// the ApplySet tooling annotation. | ||
// | ||
// The ApplySetKEP and kubectl require this to be a semantic version, | ||
// implying that it should be the version of the tool. But we're using a | ||
// static version instead, to allow listing all objects managed Config Sync, | ||
// regardless of version. | ||
ApplySetToolingVersion = "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
Oops, something went wrong.