Skip to content

Commit

Permalink
Merge pull request #336 from ChristopherFry/cfry/applyset-tool
Browse files Browse the repository at this point in the history
fix: use apply set tooling in apply set applier
  • Loading branch information
k8s-ci-robot committed May 22, 2023
2 parents 78572f1 + 3e82b3e commit ea63b3b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
20 changes: 15 additions & 5 deletions applylib/applyset/applyset.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"reflect"
"strings"
"sync"

"k8s.io/apimachinery/pkg/api/meta"
Expand Down Expand Up @@ -70,7 +71,7 @@ type ApplySet struct {
// deployment manifests.
parent Parent
// If not given, the tooling value will be the `Parent` Kind.
tooling string
tooling kubectlapply.ApplySetTooling
}

// Options holds the parameters for building an ApplySet.
Expand All @@ -93,7 +94,16 @@ type Options struct {
func New(options Options) (*ApplySet, error) {
parent := options.Parent
parentRef := &kubectlapply.ApplySetParentRef{Name: parent.Name(), Namespace: parent.Namespace(), RESTMapping: parent.RESTMapping()}
kapplyset := kubectlapply.NewApplySet(parentRef, kubectlapply.ApplySetTooling{Name: options.Tooling}, options.RESTMapper)

// The tooling string slash cutting is to support the ApplySetTooling struct that kubectlapply.NewApplySet() expects.
// For instance, 'kpt/v1.0.0' will map to ApplySetTooling{Name: "kpt", Version: "v1.0.0"}.
toolName, toolVersion, _ := strings.Cut(options.Tooling, "/")
if toolName == "" {
toolName = parent.GetSubject().GetObjectKind().GroupVersionKind().Kind
}
tooling := kubectlapply.ApplySetTooling{Name: toolName, Version: toolVersion}

kapplyset := kubectlapply.NewApplySet(parentRef, tooling, options.RESTMapper)
if options.PatchOptions.FieldManager == "" {
options.PatchOptions.FieldManager = kapplyset.FieldManager()
}
Expand All @@ -105,7 +115,7 @@ func New(options Options) (*ApplySet, error) {
deleteOptions: options.DeleteOptions,
prune: options.Prune,
parent: parent,
tooling: options.Tooling,
tooling: tooling,
}
a.trackers = &objectTrackerList{}
return a, nil
Expand Down Expand Up @@ -149,7 +159,7 @@ func (a *ApplySet) ApplyOnce(ctx context.Context) (*ApplyResults, error) {
// single actuation and not for reconciliation.
// Note: The Kubectl ApplySet will share the RESTMapper with k-d-p/ApplySet, which caches all the manifests in the past.
parentRef := &kubectlapply.ApplySetParentRef{Name: a.parent.Name(), Namespace: a.parent.Namespace(), RESTMapping: a.parent.RESTMapping()}
kapplyset := kubectlapply.NewApplySet(parentRef, kubectlapply.ApplySetTooling{Name: a.tooling}, a.restMapper)
kapplyset := kubectlapply.NewApplySet(parentRef, a.tooling, a.restMapper)

// Cache the current RESTMappings to avoid re-fetching the bad ones.
restMappings := make(map[schema.GroupVersionKind]restMappingResult)
Expand Down Expand Up @@ -365,7 +375,7 @@ func (a *ApplySet) WithParent(ctx context.Context, kapplyset *kubectlapply.Apply
if annotations == nil {
annotations = make(map[string]string)
}
annotations[kubectlapply.ApplySetToolingAnnotation] = a.tooling
annotations[kubectlapply.ApplySetToolingAnnotation] = a.tooling.String()
if _, ok := annotations[kubectlapply.ApplySetGRsAnnotation]; !ok {
annotations[kubectlapply.ApplySetGRsAnnotation] = ""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,22 +257,6 @@ Date: (removed)

---

PUT http://kube-apiserver/apis/addons.example.org/v1alpha1/namespaces/ns1/simpletests/simple1
Accept: application/json, */*
Content-Type: application/json

{"apiVersion":"addons.example.org/v1alpha1","kind":"SimpleTest","metadata":{"annotations":{"applyset.kubernetes.io/additional-namespaces":"","applyset.kubernetes.io/contains-group-resources":"configmaps,deployments.apps","applyset.kubernetes.io/tooling":"SimpleTest/"},"creationTimestamp":"2022-01-01T00:00:01Z","labels":{"applyset.kubernetes.io/id":"applyset-xbxAWnAItX3p1Gxrs86F-ZQAGwGoys9xxQGK3IED7bY-v1"},"name":"simple1","namespace":"ns1","resourceVersion":"6","uid":"00000000-0000-0000-0000-000000000002"},"spec":{"channel":"stable"},"status":{"conditions":[{"lastTransitionTime":"2022-01-01T00:00:00Z","message":"all manifests are reconciled.","reason":"Normal","status":"True","type":"Ready"}],"healthy":true,"phase":"Current"}}

200 OK
Cache-Control: no-cache, private
Content-Length: 736
Content-Type: application/json
Date: (removed)

{"apiVersion":"addons.example.org/v1alpha1","kind":"SimpleTest","metadata":{"annotations":{"applyset.kubernetes.io/additional-namespaces":"","applyset.kubernetes.io/contains-group-resources":"configmaps,deployments.apps","applyset.kubernetes.io/tooling":"SimpleTest/"},"creationTimestamp":"2022-01-01T00:00:01Z","labels":{"applyset.kubernetes.io/id":"applyset-xbxAWnAItX3p1Gxrs86F-ZQAGwGoys9xxQGK3IED7bY-v1"},"name":"simple1","namespace":"ns1","resourceVersion":"6","uid":"00000000-0000-0000-0000-000000000002"},"spec":{"channel":"stable"},"status":{"conditions":[{"lastTransitionTime":"2022-01-01T00:00:00Z","message":"all manifests are reconciled.","reason":"Normal","status":"True","type":"Ready"}],"healthy":true,"phase":"Current"}}

---

PATCH http://kube-apiserver/api/v1/namespaces/ns1/configmaps/foo?fieldManager=kdp-test&force=true
Accept: application/json
Content-Type: application/apply-patch+yaml
Expand Down

0 comments on commit ea63b3b

Please sign in to comment.