Skip to content
Permalink
Browse files
fix(external-deps): use Unstructured instead of builtin types
Signed-off-by: Ilya Lesikov <ilya@lesikov.com>
  • Loading branch information
ilya-lesikov committed Jun 23, 2022
1 parent 3ba997e commit afbb5b4f96b22e07c570a1c6a233b9addc93cebc
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 31 deletions.
2 go.mod
@@ -307,6 +307,6 @@ replace k8s.io/helm => github.com/werf/helm v0.0.0-20210202111118-81e74d46da0f

replace github.com/deislabs/oras => github.com/werf/third-party-oras v0.9.1-0.20210927171747-6d045506f4c8

replace helm.sh/helm/v3 => github.com/werf/3p-helm/v3 v3.0.0-20220617105011-83d89240b53f
replace helm.sh/helm/v3 => github.com/werf/3p-helm/v3 v3.0.0-20220623100852-5c5a193d6bc2

replace github.com/go-git/go-git/v5 => github.com/ZauberNerd/go-git/v5 v5.4.3-0.20220315170230-29ec1bc1e5db
4 go.sum
@@ -2036,8 +2036,8 @@ github.com/vmware/govmomi v0.20.3/go.mod h1:URlwyTFZX72RmxtxuaFL2Uj3fD1JTvZdx59b
github.com/weppos/publicsuffix-go v0.4.0/go.mod h1:z3LCPQ38eedDQSwmsSRW4Y7t2L8Ln16JPQ02lHAdn5k=
github.com/weppos/publicsuffix-go v0.5.0 h1:rutRtjBJViU/YjcI5d80t4JAVvDltS6bciJg2K1HrLU=
github.com/weppos/publicsuffix-go v0.5.0/go.mod h1:z3LCPQ38eedDQSwmsSRW4Y7t2L8Ln16JPQ02lHAdn5k=
github.com/werf/3p-helm/v3 v3.0.0-20220617105011-83d89240b53f h1:QSXL6tf60vf20g7SXCJvdIEZyP6/Y/VHw+op9AlnHHY=
github.com/werf/3p-helm/v3 v3.0.0-20220617105011-83d89240b53f/go.mod h1:NxtE2KObf2PrzDl6SIamPFPKyAqWi10iWuvKlQn/Yao=
github.com/werf/3p-helm/v3 v3.0.0-20220623100852-5c5a193d6bc2 h1:e9OHFNHObGoDhxAyac/9FfBqbrOb6txkbJp9Cy29NTk=
github.com/werf/3p-helm/v3 v3.0.0-20220623100852-5c5a193d6bc2/go.mod h1:NxtE2KObf2PrzDl6SIamPFPKyAqWi10iWuvKlQn/Yao=
github.com/werf/copy-recurse v0.2.4 h1:kEyGUKhgS8WdEOjInNQKgk4lqPWzP2AgR27F3dcGsVc=
github.com/werf/copy-recurse v0.2.4/go.mod h1:KVHSQ90p19xflWW0B7BJhLBwmSbEtuxIaBnjlUYRPhk=
github.com/werf/helm v0.0.0-20210202111118-81e74d46da0f h1:81YscYTF9mmTf0ULOsCmm42YWQp+qWDzWi1HjWniZrg=
@@ -7,25 +7,20 @@ import (
"helm.sh/helm/v3/pkg/phases/stages"
"helm.sh/helm/v3/pkg/phases/stages/externaldeps"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/cli-runtime/pkg/resource"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/restmapper"
)

func NewStagesExternalDepsGenerator(restClient *action.RESTClientGetter) *StagesExternalDepsGenerator {
return &StagesExternalDepsGenerator{
restClient: restClient,
metaAccessor: metadataAccessor,
scheme: scheme.Scheme,
}
}

type StagesExternalDepsGenerator struct {
restClient *action.RESTClientGetter
gvkBuilder externaldeps.GVKBuilder
metaAccessor meta.MetadataAccessor
scheme *runtime.Scheme
initialized bool
}

@@ -39,12 +34,7 @@ func (s *StagesExternalDepsGenerator) init() error {
return fmt.Errorf("error getting REST mapper: %w", err)
}

discoveryClient, err := (*s.restClient).ToDiscoveryClient()
if err != nil {
return fmt.Errorf("error getting discovery client: %w", err)
}

s.gvkBuilder = NewGVKBuilder(scheme.Scheme, restmapper.NewShortcutExpander(mapper, discoveryClient))
s.gvkBuilder = NewGVKBuilder(mapper)

s.initialized = true

@@ -94,7 +84,7 @@ func (s *StagesExternalDepsGenerator) resourceExternalDepsFromAnnotations(annota
}

for _, extDep := range extDepsList {
if err := extDep.GenerateInfo(s.gvkBuilder, s.scheme, s.metaAccessor); err != nil {
if err := extDep.GenerateInfo(s.gvkBuilder, s.metaAccessor); err != nil {
return nil, fmt.Errorf("error generating Info for external dependency: %w", err)
}
}
@@ -5,21 +5,17 @@ import (

"helm.sh/helm/v3/pkg/phases/stages/externaldeps"
"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/kubectl/pkg/scheme"
)

func NewGVKBuilder(scheme *runtime.Scheme, shortcutExpander meta.RESTMapper) externaldeps.GVKBuilder {
func NewGVKBuilder(discoveryShortcutExpander meta.RESTMapper) externaldeps.GVKBuilder {
return &GVKBuilder{
scheme: scheme,
shortcutExpander: shortcutExpander,
discoveryShortcutExpander: discoveryShortcutExpander,
}
}

type GVKBuilder struct {
scheme *runtime.Scheme
shortcutExpander meta.RESTMapper
discoveryShortcutExpander meta.RESTMapper
}

func (b *GVKBuilder) BuildFromResource(resource string) (*schema.GroupVersionKind, error) {
@@ -45,22 +41,15 @@ func (b *GVKBuilder) parseGVR(resource string) (*schema.GroupVersionResource, er
return nil, fmt.Errorf("resource type not specified")
}

if gr.Group != "" {
if !scheme.Scheme.IsGroupRegistered(gr.Group) {
return nil, fmt.Errorf("resource group %q is not registered", gr.Group)
}
groupVersionResource = scheme.Scheme.PrioritizedVersionsForGroup(gr.Group)[0].WithResource(gr.Resource)
} else {
groupVersionResource = gr.WithVersion("")
}
groupVersionResource = gr.WithVersion("")
}

return &groupVersionResource, nil
}

func (b *GVKBuilder) gvrToGvk(groupVersionResource schema.GroupVersionResource) (*schema.GroupVersionKind, error) {
var groupVersionKind schema.GroupVersionKind
if preferredKinds, err := b.shortcutExpander.KindsFor(groupVersionResource); err != nil {
if preferredKinds, err := b.discoveryShortcutExpander.KindsFor(groupVersionResource); err != nil {
return nil, fmt.Errorf("error matching a group/version/resource: %w", err)
} else if len(preferredKinds) == 0 {
return nil, fmt.Errorf("no matches for group/version/resource")
@@ -20,6 +20,7 @@ import (
v1 "k8s.io/api/core/v1"
extensions "k8s.io/api/extensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/cli-runtime/pkg/resource"
@@ -184,6 +185,7 @@ func (waiter *ResourcesWaiter) Wait(ctx context.Context, resources helm_kube.Res
if spec != nil {
specs.Canaries = append(specs.Canaries, *spec)
}
case *unstructured.Unstructured:
}
}

0 comments on commit afbb5b4

Please sign in to comment.