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

Added Database V3 resource to operator #49856

Draft
wants to merge 3 commits into
base: branch/v17
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions examples/chart/teleport-cluster/templates/auth/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,19 @@ data:
- read
- update
- delete
- resources:
- db
verbs:
- list
- create
- read
- update
- delete
impersonate:
users:
- Db
roles:
- Db
deny: {}
version: v7
---
Expand Down
5 changes: 3 additions & 2 deletions integration/helpers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ func MakeTestDatabaseServer(t *testing.T, proxyAddr utils.NetAddr, token string,
cfg.Databases.Databases = dbs
cfg.Databases.ResourceMatchers = resMatchers
cfg.Log = utils.NewLoggerForTests()
cfg.DebugService.Enabled = false

db, err := service.NewTeleport(cfg)
require.NoError(t, err)
Expand All @@ -465,8 +466,8 @@ func MakeTestDatabaseServer(t *testing.T, proxyAddr utils.NetAddr, token string,
})

// Wait for database agent to start.
_, err = db.WaitForEventTimeout(30*time.Second, service.DatabasesReady)
require.NoError(t, err, "database server didn't start after 10s")
err = db.Start()
require.NoError(t, err, "database server didn't start after 30s")

return db
}
Expand Down
4 changes: 2 additions & 2 deletions integrations/operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ vet: ## Run go vet against code.
go vet ./...

.PHONY: test
test: manifests generate fmt vet $(ENVTEST) crdgen-test ## Run tests.
test: $(ENVTEST) ## Run tests.
test: export KUBEBUILDER_ASSETS=$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) -p path)
test:
go test ./... -coverprofile cover.out
go test -run ^TestTeleportDatabaseV3Creation$$ github.com/gravitational/teleport/integrations/operator/controllers/resources

.PHONY: echo-kubebuilder-assets
echo-kubebuilder-assets:
Expand Down
95 changes: 95 additions & 0 deletions integrations/operator/apis/resources/v1/databasev3_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Teleport
* Copyright (C) 2023 Gravitational, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package v1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/gravitational/teleport/api/types"
"github.com/gravitational/teleport/integrations/operator/apis/resources"
)

func init() {
SchemeBuilder.Register(&TeleportDatabaseV3{}, &TeleportDatabaseListV3{})
}

// TeleportDatabaseSpec defines the desired state of TeleportDatabase
type TeleportDatabaseSpec types.DatabaseSpecV3

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// TeleportDatabase is the Schema for the databases API
type TeleportDatabaseV3 struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec TeleportDatabaseSpec `json:"spec,omitempty"`
Status resources.Status `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// TeleportDatabaseList contains a list of TeleportDatabase
type TeleportDatabaseListV3 struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []TeleportDatabaseV3 `json:"items"`
}

func (r TeleportDatabaseV3) ToTeleport() types.Database {
return &types.DatabaseV3{
Kind: types.KindDatabase,
Version: types.V3,
Metadata: types.Metadata{
Name: r.Name,
Labels: r.Labels,
Description: r.Annotations[resources.DescriptionKey],
},
Spec: types.DatabaseSpecV3(r.Spec),
}
}

// Marshal serializes a spec into binary data.
func (spec *TeleportDatabaseSpec) Marshal() ([]byte, error) {
return (*types.DatabaseSpecV3)(spec).Marshal()
}

// Unmarshal deserializes a spec from binary data.
func (spec *TeleportDatabaseSpec) Unmarshal(data []byte) error {
return (*types.DatabaseSpecV3)(spec).Unmarshal(data)
}

// DeepCopyInto deep-copies one database spec into another.
// Required to satisfy runtime.Object interface.
func (spec *TeleportDatabaseSpec) DeepCopyInto(out *TeleportDatabaseSpec) {
data, err := spec.Marshal()
if err != nil {
panic(err)
}
*out = TeleportDatabaseSpec{}
if err = out.Unmarshal(data); err != nil {
panic(err)
}
}

// StatusConditions returns a pointer to Status.Conditions slice.
func (r *TeleportDatabaseV3) StatusConditions() *[]metav1.Condition {
return &r.Status.Conditions
}
69 changes: 69 additions & 0 deletions integrations/operator/apis/resources/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading