-
Notifications
You must be signed in to change notification settings - Fork 552
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enable gatewayapi and reduce profile structure
- Loading branch information
1 parent
1b2e900
commit 1e5dab2
Showing
29 changed files
with
19,763 additions
and
139 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright (c) 2022 Alibaba Group Holding Ltd. | ||
// | ||
// 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 installer | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io" | ||
"strings" | ||
|
||
"github.com/alibaba/higress/pkg/cmd/hgctl/helm" | ||
"github.com/alibaba/higress/pkg/cmd/hgctl/manifests" | ||
) | ||
|
||
const ( | ||
GatewayAPI ComponentName = "gatewayAPI" | ||
) | ||
|
||
type GatewayAPIComponent struct { | ||
profile *helm.Profile | ||
started bool | ||
opts *ComponentOptions | ||
renderer helm.Renderer | ||
writer io.Writer | ||
} | ||
|
||
func NewGatewayAPIComponent(profile *helm.Profile, writer io.Writer, opts ...ComponentOption) (Component, error) { | ||
newOpts := &ComponentOptions{} | ||
for _, opt := range opts { | ||
opt(newOpts) | ||
} | ||
|
||
if !strings.HasPrefix(newOpts.RepoURL, "embed://") { | ||
return nil, errors.New("GatewayAPI Url need start with embed://") | ||
} | ||
|
||
chartDir := strings.TrimPrefix(newOpts.RepoURL, "embed://") | ||
// GatewayAPI can only be installed by embed type | ||
renderer, err := helm.NewLocalFileRenderer( | ||
helm.WithName(newOpts.ChartName), | ||
helm.WithNamespace(newOpts.Namespace), | ||
helm.WithRepoURL(newOpts.RepoURL), | ||
helm.WithVersion(newOpts.Version), | ||
helm.WithFS(manifests.BuiltinOrDir("")), | ||
helm.WithDir(chartDir), | ||
) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
gatewayAPIComponent := &GatewayAPIComponent{ | ||
profile: profile, | ||
renderer: renderer, | ||
opts: newOpts, | ||
writer: writer, | ||
} | ||
return gatewayAPIComponent, nil | ||
} | ||
|
||
func (i *GatewayAPIComponent) ComponentName() ComponentName { | ||
return GatewayAPI | ||
} | ||
|
||
func (i *GatewayAPIComponent) Namespace() string { | ||
return i.opts.Namespace | ||
} | ||
|
||
func (i *GatewayAPIComponent) Enabled() bool { | ||
return true | ||
} | ||
|
||
func (i *GatewayAPIComponent) Run() error { | ||
if !i.opts.Quiet { | ||
fmt.Fprintf(i.writer, "🏄 Downloading GatewayAPI Yaml Files version: %s, url: %s\n", i.opts.Version, i.opts.RepoURL) | ||
} | ||
if err := i.renderer.Init(); err != nil { | ||
return err | ||
} | ||
i.started = true | ||
return nil | ||
} | ||
|
||
func (i *GatewayAPIComponent) RenderManifest() (string, error) { | ||
if !i.started { | ||
return "", nil | ||
} | ||
if !i.opts.Quiet { | ||
fmt.Fprintf(i.writer, "📦 Rendering GatewayAPI Yaml Files\n") | ||
} | ||
values := make(map[string]any) | ||
manifest, err := renderComponentManifest(values, i.renderer, false, i.ComponentName(), i.opts.Namespace) | ||
if err != nil { | ||
return "", err | ||
} | ||
return manifest, nil | ||
} |
Oops, something went wrong.