Skip to content
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

kubeadm: code clean up about kustomize #82414

Merged
merged 1 commit into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions cmd/kubeadm/app/phases/upgrade/staticpods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,8 @@ func NewFakeStaticPodPathManager(moveFileFunc func(string, string) error) (Stati
return nil, err
}

kustomizeDir := ""

return &fakeStaticPodPathManager{
kubernetesDir: kubernetesDir,
kustomizeDir: kustomizeDir,
realManifestDir: realManifestDir,
tempManifestDir: upgradedManifestDir,
backupManifestDir: backupManifestDir,
Expand Down
11 changes: 6 additions & 5 deletions cmd/kubeadm/app/util/kustomize/kustomize.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,12 @@ func (km *Manager) Kustomize(data []byte) ([]byte, error) {
json6902 := km.json6902Patches.filterByResource(resource)

// if there are no patches, for the target resources, exit
if len(strategicMerge)+len(json6902) == 0 {
patchesCnt := len(strategicMerge) + len(json6902)
if patchesCnt == 0 {
return data, nil
}

fmt.Printf("[kustomize] Applying %d patches to %s Resource=%s/%s\n", len(strategicMerge)+len(json6902), resource.GroupVersionKind(), resource.GetNamespace(), resource.GetName())
fmt.Printf("[kustomize] Applying %d patches to %s Resource=%s/%s\n", patchesCnt, resource.GroupVersionKind(), resource.GetNamespace(), resource.GetName())

// create an in memory fs to use for the kustomization
memFS := fs.MakeFakeFS()
Expand All @@ -207,7 +208,7 @@ func (km *Manager) Kustomize(data []byte) ([]byte, error) {
return nil, err
}
name := "resource.yaml"
_ = memFS.WriteFile(filepath.Join(fakeDir, name), b)
memFS.WriteFile(filepath.Join(fakeDir, name), b)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I searched the code base, and it seemed that the return values can be ignored.
e.g. https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/cli-runtime/pkg/kustomize/builder_test.go#L136


km.kustomizationFile.Resources = []string{name}

Expand All @@ -219,7 +220,7 @@ func (km *Manager) Kustomize(data []byte) ([]byte, error) {
return nil, err
}
name := fmt.Sprintf("patch-%d.yaml", i)
_ = memFS.WriteFile(filepath.Join(fakeDir, name), b)
memFS.WriteFile(filepath.Join(fakeDir, name), b)

km.kustomizationFile.PatchesStrategicMerge = append(km.kustomizationFile.PatchesStrategicMerge, patch.StrategicMerge(name))
}
Expand All @@ -228,7 +229,7 @@ func (km *Manager) Kustomize(data []byte) ([]byte, error) {
km.kustomizationFile.PatchesJson6902 = []patch.Json6902{}
for i, p := range json6902 {
name := fmt.Sprintf("patchjson-%d.yaml", i)
_ = memFS.WriteFile(filepath.Join(fakeDir, name), []byte(p.Patch))
memFS.WriteFile(filepath.Join(fakeDir, name), []byte(p.Patch))

km.kustomizationFile.PatchesJson6902 = append(km.kustomizationFile.PatchesJson6902, patch.Json6902{Target: p.Target, Path: name})
}
Expand Down