Skip to content

Commit

Permalink
Merge branch 'main' into aacrawfi/rad-app-graph
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronCrawfis authored Oct 17, 2023
2 parents 069a71a + 32391b0 commit 8b1162d
Show file tree
Hide file tree
Showing 12 changed files with 417 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/functional-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest]
name: [ucp,shared,msgrp,daprrp,samples]
name: [ucp,kubernetes,shared,msgrp,daprrp,samples]
include:
# datastorerp functional tests need the larger VM.
- os: ubuntu-latest-m
Expand Down
2 changes: 1 addition & 1 deletion build/test.mk
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ test-get-envtools:
test-validate-cli: ## Run cli integration tests
CGO_ENABLED=1 $(GOTEST_TOOL) -coverpkg= ./pkg/cli/cmd/... ./cmd/rad/... -timeout ${TEST_TIMEOUT} -v -parallel 5 $(GOTEST_OPTS)

test-functional-all: test-functional-ucp test-functional-shared test-functional-msgrp test-functional-daprrp ## Runs all functional tests
test-functional-all: test-functional-ucp test-functional-kubernetes test-functional-shared test-functional-msgrp test-functional-daprrp ## Runs all functional tests

test-functional-kubernetes: ## Runs Kubernetes functional tests
CGO_ENABLED=1 $(GOTEST_TOOL) ./test/functional/kubernetes/... -timeout ${TEST_TIMEOUT} -v -parallel 5 $(GOTEST_OPTS)
Expand Down
7 changes: 4 additions & 3 deletions deploy/Chart/templates/controller/rbac.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: controller
name: radius-controller
labels:
app.kubernetes.io/name: controller
app.kubernetes.io/part-of: radius
Expand All @@ -11,6 +11,7 @@ rules:
resources:
- namespaces
- secrets
- events
verbs:
- create
- delete
Expand Down Expand Up @@ -55,14 +56,14 @@ rules:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: controller
name: radius-controller
labels:
app.kubernetes.io/name: controller
app.kubernetes.io/part-of: radius
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: controller
name: radius-controller
subjects:
- kind: ServiceAccount
name: controller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ In general you should ask for guidance before creating a new top-level folder in
| `aws/` | Utility code and library integrations for working with AWS |
| `azure/` | Utility code and library integrations for working with Azure |
| `cli/` | Implementation code for the `rad` CLI |
| `controllers/` | Kubernetes controllers for Radius |
| `corerp/` | Resource Provider implementation for `Applications.Core` resources |
| `daprrp/` | Resource Provider implementation for `Applications.Dapr` resources |
| `datastoresrp/` | Resource Provider implementation for `Applications.Datastores` resources |
Expand Down
6 changes: 4 additions & 2 deletions pkg/cli/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/radius-project/radius/pkg/cli/output"
radappiov1alpha3 "github.com/radius-project/radius/pkg/controller/api/radapp.io/v1alpha3"
"github.com/radius-project/radius/pkg/kubeutil"
)

Expand All @@ -49,6 +50,7 @@ func init() {
_ = apiextv1.AddToScheme(Scheme)
_ = clientgoscheme.AddToScheme(Scheme)
_ = contourv1.AddToScheme(Scheme)
_ = radappiov1alpha3.AddToScheme(Scheme)
}

// NewDynamicClient creates a new dynamic client by context name, otherwise returns an error.
Expand Down Expand Up @@ -82,13 +84,13 @@ func NewClientset(context string) (*k8s.Clientset, *rest.Config, error) {
}

// NewRuntimeClient creates a kubernetes client using a given context and scheme.
func NewRuntimeClient(context string, scheme *k8s_runtime.Scheme) (client.Client, error) {
func NewRuntimeClient(context string, scheme *k8s_runtime.Scheme) (client.WithWatch, error) {
merged, err := NewCLIClientConfig(context)
if err != nil {
return nil, err
}

c, err := client.New(merged, client.Options{Scheme: scheme})
c, err := client.NewWithWatch(merged, client.Options{Scheme: scheme})
if err != nil {
output.LogInfo("failed to create runtime client due to error: %v", err)
return nil, err
Expand Down
33 changes: 26 additions & 7 deletions pkg/controller/reconciler/deployment_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ func (r *DeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Request)
}
}

// If the Deployment is being deleted **or** if Radius is not enabled, then we should
// If the Deployment is being deleted **or** if Radius is no longer enabled, then we should
// clean up any Radius state.
if deployment.DeletionTimestamp != nil || annotations.Configuration == nil {
if deployment.DeletionTimestamp != nil || (annotations.Configuration == nil && annotations.Status != nil) {
return r.reconcileDelete(ctx, &deployment, annotations)
}

Expand Down Expand Up @@ -402,10 +402,16 @@ func (r *DeploymentReconciler) startPutOrDeleteOperationIfNeeded(ctx context.Con
poller, err := deleteContainer(ctx, r.Radius, annotations.Status.Container)
if err != nil {
return nil, nil, false, err
} else if poller != nil {
return nil, poller, false, nil
}

return nil, poller, false, err
} else if !annotations.IsUpToDate() {
// Deletion completed synchronously.
annotations.Status.Container = ""
}

// Note: we separate this check from the previous block, because it could complete synchronously.
if !annotations.IsUpToDate() {
logger.Info("Container configuration is out-of-date.")
} else if annotations.Status.Container != "" {
logger.Info("Container is already created and is up-to-date.")
Expand Down Expand Up @@ -448,8 +454,12 @@ func (r *DeploymentReconciler) startPutOrDeleteOperationIfNeeded(ctx context.Con
poller, err := createOrUpdateContainer(ctx, r.Radius, resourceID, &properties)
if err != nil {
return nil, nil, false, err
} else if poller != nil {
return poller, nil, false, nil
}

// Update completed synchronously
annotations.Status.Container = resourceID
return poller, nil, false, nil
}

Expand All @@ -461,7 +471,16 @@ func (r *DeploymentReconciler) startDeleteOperationIfNeeded(ctx context.Context,
}

logger.Info("Starting DELETE operation.")
return deleteContainer(ctx, r.Radius, annotations.Status.Container)
poller, err := deleteContainer(ctx, r.Radius, annotations.Status.Container)
if err != nil {
return nil, err
} else if poller != nil {
return poller, nil
}

// Deletion completed synchronously.
annotations.Status.Container = ""
return nil, nil
}

func (r *DeploymentReconciler) updateDeployment(ctx context.Context, deployment *appsv1.Deployment, annotations *deploymentAnnotations) error {
Expand Down Expand Up @@ -550,7 +569,7 @@ func (r *DeploymentReconciler) cleanupDeployment(ctx context.Context, deployment

secretName := client.ObjectKey{Namespace: deployment.Namespace, Name: fmt.Sprintf("%s-connections", deployment.Name)}
err := r.Client.Delete(ctx, &corev1.Secret{ObjectMeta: metav1.ObjectMeta{Namespace: secretName.Namespace, Name: secretName.Name}})
if err != nil {
if err != nil && !apierrors.IsNotFound(err) {
return fmt.Errorf("failed to delete secret %s: %w", secretName.Name, err)
}

Expand Down Expand Up @@ -614,7 +633,7 @@ func (r *DeploymentReconciler) SetupWithManager(mgr ctrl.Manager) error {
annotations, err := readAnnotations(deployment)
if err != nil {
return []string{}
} else if annotations.Configuration == nil {
} else if annotations == nil || annotations.Configuration == nil {
return []string{}
}

Expand Down
28 changes: 24 additions & 4 deletions pkg/controller/reconciler/recipe_reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,16 @@ func (r *RecipeReconciler) startPutOrDeleteOperationIfNeeded(ctx context.Context
poller, err := deleteResource(ctx, r.Radius, recipe.Status.Resource)
if err != nil {
return nil, nil, err
} else if poller != nil {
return nil, poller, nil
}

return nil, poller, err
} else if recipe.Status.Resource != "" {
// Deletion was synchronous
recipe.Status.Resource = ""
}

// Note: we separate this check from the previous block, because it could complete synchronously.
if recipe.Status.Resource != "" {
logger.Info("Resource is already created and is up-to-date.")
return nil, nil, nil
}
Expand All @@ -399,9 +405,13 @@ func (r *RecipeReconciler) startPutOrDeleteOperationIfNeeded(ctx context.Context
poller, err := createOrUpdateResource(ctx, r.Radius, resourceID, properties)
if err != nil {
return nil, nil, err
} else if poller != nil {
return poller, nil, nil
}

return poller, nil, nil
// Update was synchronous
recipe.Status.Resource = resourceID
return nil, nil, nil
}

func (r *RecipeReconciler) startDeleteOperationIfNeeded(ctx context.Context, recipe *radappiov1alpha3.Recipe) (Poller[generated.GenericResourcesClientDeleteResponse], error) {
Expand All @@ -412,7 +422,17 @@ func (r *RecipeReconciler) startDeleteOperationIfNeeded(ctx context.Context, rec
}

logger.Info("Starting DELETE operation.")
return deleteResource(ctx, r.Radius, recipe.Status.Resource)
poller, err := deleteResource(ctx, r.Radius, recipe.Status.Resource)
if err != nil {
return nil, err
} else if poller != nil {
return poller, err
}

// Deletion was synchronous

recipe.Status.Resource = ""
return nil, nil
}

func (r *RecipeReconciler) updateSecret(ctx context.Context, recipe *radappiov1alpha3.Recipe) error {
Expand Down
48 changes: 44 additions & 4 deletions pkg/controller/reconciler/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,17 @@ func deleteResource(ctx context.Context, radius RadiusClient, resourceID string)
return nil, err
}

return poller, nil
if !poller.Done() {
return poller, nil
}

// Handle synchronous completion
_, err = poller.Result(ctx)
if err != nil {
return nil, err
}

return nil, nil
}

func createOrUpdateResource(ctx context.Context, radius RadiusClient, resourceID string, properties map[string]any) (Poller[generated.GenericResourcesClientCreateOrUpdateResponse], error) {
Expand All @@ -185,7 +195,17 @@ func createOrUpdateResource(ctx context.Context, radius RadiusClient, resourceID
return nil, err
}

return poller, nil
if !poller.Done() {
return poller, nil
}

// Handle synchronous completion
_, err = poller.Result(ctx)
if err != nil {
return nil, err
}

return nil, nil
}

func fetchResource(ctx context.Context, radius RadiusClient, resourceID string) (generated.GenericResourcesClientGetResponse, error) {
Expand Down Expand Up @@ -214,7 +234,17 @@ func deleteContainer(ctx context.Context, radius RadiusClient, containerID strin
return nil, err
}

return poller, nil
if !poller.Done() {
return poller, nil
}

// Handle synchronous completion
_, err = poller.Result(ctx)
if err != nil {
return nil, err
}

return nil, nil
}

func createOrUpdateContainer(ctx context.Context, radius RadiusClient, containerID string, properties *corerpv20231001preview.ContainerProperties) (Poller[corerpv20231001preview.ContainersClientCreateOrUpdateResponse], error) {
Expand All @@ -236,5 +266,15 @@ func createOrUpdateContainer(ctx context.Context, radius RadiusClient, container
return nil, err
}

return poller, nil
if !poller.Done() {
return poller, nil
}

// Handle synchronous completion
_, err = poller.Result(ctx)
if err != nil {
return nil, err
}

return nil, nil
}
Loading

0 comments on commit 8b1162d

Please sign in to comment.