-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Implement basic api for resourceManifests (#357)
Signed-off-by: Arnob kumar saha <[email protected]>
1 parent
2b514f3
commit b6b9cd4
Showing
2,223 changed files
with
620,631 additions
and
411 deletions.
There are no files selected for viewing
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,121 @@ | ||
/* | ||
Copyright AppsCode Inc. and Contributors | ||
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 resourcemanifests | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"strings" | ||
|
||
apierrors "k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"k8s.io/apiserver/pkg/registry/rest" | ||
kmapi "kmodules.xyz/client-go/api/v1" | ||
rsapi "kmodules.xyz/resource-metadata/apis/meta/v1alpha1" | ||
"kubepack.dev/lib-app/pkg/editor" | ||
"kubepack.dev/lib-helm/pkg/repo" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
releasesapi "x-helm.dev/apimachinery/apis/releases/v1alpha1" | ||
) | ||
|
||
type Storage struct { | ||
kc client.Client | ||
} | ||
|
||
var ( | ||
_ rest.GroupVersionKindProvider = &Storage{} | ||
_ rest.Scoper = &Storage{} | ||
_ rest.Storage = &Storage{} | ||
_ rest.Creater = &Storage{} | ||
_ rest.SingularNameProvider = &Storage{} | ||
) | ||
|
||
func NewStorage(kc client.Client) *Storage { | ||
return &Storage{ | ||
kc: kc, | ||
} | ||
} | ||
|
||
func (r *Storage) GroupVersionKind(_ schema.GroupVersion) schema.GroupVersionKind { | ||
return rsapi.SchemeGroupVersion.WithKind(rsapi.ResourceKindResourceManifests) | ||
} | ||
|
||
func (r *Storage) NamespaceScoped() bool { | ||
return false | ||
} | ||
|
||
func (r *Storage) GetSingularName() string { | ||
return strings.ToLower(rsapi.ResourceKindResourceManifests) | ||
} | ||
|
||
// Getter | ||
func (r *Storage) New() runtime.Object { | ||
return &rsapi.ResourceManifests{} | ||
} | ||
|
||
func (r *Storage) Destroy() {} | ||
|
||
var DefaultCache = repo.DefaultDiskCache() | ||
|
||
func NewRegistry(kc client.Client) repo.IRegistry { | ||
return repo.NewRegistry(kc, DefaultCache) | ||
} | ||
|
||
func (r *Storage) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) { | ||
manifests, ok := obj.(*rsapi.ResourceManifests) | ||
if !ok { | ||
return nil, fmt.Errorf("invalid object type: %T", obj) | ||
} | ||
if manifests.Request == nil { | ||
return nil, apierrors.NewBadRequest("missing apirequest") | ||
} | ||
|
||
reg := NewRegistry(r.kc) | ||
metadata := releasesapi.ModelMetadata{Metadata: releasesapi.Metadata{ | ||
Resource: kmapi.ResourceID{ | ||
Group: manifests.Request.Group, | ||
Version: manifests.Request.Version, | ||
Kind: manifests.Request.Kind, | ||
}, | ||
Release: releasesapi.ObjectMeta{ | ||
Name: manifests.Request.Name, | ||
Namespace: manifests.Request.Namespace, | ||
}, | ||
}} | ||
tpl, err := editor.LoadResourceEditorModel(r.kc, reg, metadata) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
mp := make(map[string]runtime.RawExtension) | ||
for _, resource := range tpl.Resources { | ||
kmapi.NewObjectID(resource.Data).OID() | ||
rawJSON, err := json.Marshal(resource.Data) | ||
if err != nil { | ||
fmt.Printf("Error marshalling unstructured object: %v\n", err) | ||
return nil, err | ||
} | ||
mp[string(kmapi.NewObjectID(resource.Data).OID())] = runtime.RawExtension{Raw: rawJSON} | ||
} | ||
manifests.Response = rsapi.ResourceManifestsResponse{ | ||
Objects: mp, | ||
} | ||
return manifests, nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
672 changes: 672 additions & 0 deletions
672
vendor/cloud.google.com/go/iam/apiv1/iampb/iam_policy.pb.go
Large diffs are not rendered by default.
Oops, something went wrong.
187 changes: 187 additions & 0 deletions
187
vendor/cloud.google.com/go/iam/apiv1/iampb/options.pb.go
Oops, something went wrong.
1,180 changes: 1,180 additions & 0 deletions
1,180
vendor/cloud.google.com/go/iam/apiv1/iampb/policy.pb.go
Large diffs are not rendered by default.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
vendor/cloud.google.com/go/iam/credentials/apiv1/auxiliary.go
Oops, something went wrong.
855 changes: 855 additions & 0 deletions
855
vendor/cloud.google.com/go/iam/credentials/apiv1/credentialspb/common.pb.go
Large diffs are not rendered by default.
Oops, something went wrong.
375 changes: 375 additions & 0 deletions
375
vendor/cloud.google.com/go/iam/credentials/apiv1/credentialspb/iamcredentials.pb.go
Large diffs are not rendered by default.
Oops, something went wrong.
122 changes: 122 additions & 0 deletions
122
vendor/cloud.google.com/go/iam/credentials/apiv1/doc.go
Oops, something went wrong.
747 changes: 747 additions & 0 deletions
747
vendor/cloud.google.com/go/iam/credentials/apiv1/iam_credentials_client.go
Large diffs are not rendered by default.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
vendor/cloud.google.com/go/iam/credentials/apiv1/version.go
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
2,952 changes: 2,952 additions & 0 deletions
2,952
vendor/cloud.google.com/go/internal/.repo-metadata-full.json
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
108 changes: 108 additions & 0 deletions
108
vendor/cloud.google.com/go/internal/optional/optional.go
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
vendor/cloud.google.com/go/internal/version/update_version.sh
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.