-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add kubernetes connection in exec connections (#1181)
* feat: add kubernetes connection in exec connections * feat: kubernetes Connection object * fromConfigItem in exec connection * feat: use the config's scraper * handle connection namespace * feat: use the scrape config directly to support not CRD based scrape configs * chore: address review comments
- Loading branch information
1 parent
5d03494
commit fbf1801
Showing
4 changed files
with
176 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package connection | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/flanksource/duty/models" | ||
"github.com/flanksource/duty/types" | ||
) | ||
|
||
// +kubebuilder:object:generate=true | ||
type KubernetesConnection struct { | ||
ConnectionName string `json:"connection,omitempty"` | ||
KubeConfig types.EnvVar `json:"kubeconfig,omitempty"` | ||
} | ||
|
||
func (t KubernetesConnection) ToModel() models.Connection { | ||
return models.Connection{ | ||
Type: models.ConnectionTypeKubernetes, | ||
Certificate: t.KubeConfig.ValueStatic, | ||
} | ||
} | ||
|
||
func (t *KubernetesConnection) Populate(ctx ConnectionContext) error { | ||
if t.ConnectionName != "" { | ||
connection, err := ctx.HydrateConnectionByURL(t.ConnectionName) | ||
if err != nil { | ||
return err | ||
} else if connection == nil { | ||
return fmt.Errorf("connection[%s] not found", t.ConnectionName) | ||
} | ||
|
||
t.KubeConfig.ValueStatic = connection.Certificate | ||
} | ||
|
||
if v, err := ctx.GetEnvValueFromCache(t.KubeConfig, ctx.GetNamespace()); err != nil { | ||
return err | ||
} else { | ||
t.KubeConfig.ValueStatic = v | ||
} | ||
|
||
return nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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