গুগল অ্যান্টিগ্র্যাভিটির সাহায্যে কেসিসি অপারেশন আয়ত্ত করা

১. ভূমিকা

এই কোডল্যাবে, আপনি গুগল অ্যান্টিগ্র্যাভিটি (এই ডকুমেন্টের বাকি অংশে যা অ্যান্টিগ্র্যাভিটি নামে পরিচিত) সম্পর্কে জানতে পারবেন, যা একটি এজেন্টিক ডেভেলপমেন্ট প্ল্যাটফর্ম এবং এটি IDE-কে এজেন্ট-ফার্স্ট যুগে রূপান্তরিত করছে।

সাধারণ কোডিং অ্যাসিস্ট্যান্টগুলো শুধু লাইন অটোকমপ্লিট করে, কিন্তু অ্যান্টিগ্র্যাভিটি একটি "মিশন কন্ট্রোল" প্রদান করে যা স্বয়ংক্রিয় এজেন্টদের পরিচালনা করে। এই এজেন্টরা আপনাকে নির্মাণে সাহায্য করার জন্য পরিকল্পনা করতে, কোড লিখতে এবং এমনকি ওয়েব ব্রাউজও করতে পারে।

অ্যান্টিগ্র্যাভিটি একটি এজেন্ট-ফার্স্ট প্ল্যাটফর্ম হিসেবে ডিজাইন করা হয়েছে। এটি এই ধারণা দেয় যে, এআই শুধুমাত্র কোড লেখার একটি টুল নয়, বরং এটি একটি স্বায়ত্তশাসিত সত্তা যা ন্যূনতম মানবিক হস্তক্ষেপে জটিল প্রকৌশল কাজ পরিকল্পনা, সম্পাদন, যাচাই এবং পুনরাবৃত্তি করতে সক্ষম।

আপনি যা শিখবেন

  • অ্যান্টিগ্র্যাভিটি ইনস্টল ও কনফিগার করা হচ্ছে।
  • অ্যান্টিগ্র্যাভিটির এজেন্ট ম্যানেজার, এডিটর, ব্রাউজার ইত্যাদির মতো মূল ধারণাগুলো অন্বেষণ করা হচ্ছে।
  • নিরাপত্তা ও নিয়মকানুন মেনে গুগল ক্লাউড রিসোর্স পরিচালনা করার জন্য একেবারে গোড়া থেকে একটি প্রোডাকশন-গ্রেড কেসিসি অপারেশনস স্কিল তৈরি করা

আপনার যা যা লাগবে

বর্তমানে অ্যান্টিগ্র্যাভিটি ব্যক্তিগত জিমেইল অ্যাকাউন্টের জন্য প্রিভিউ হিসেবে উপলব্ধ। এর সাথে প্রিমিয়ার মডেলগুলো ব্যবহারের জন্য একটি বিনামূল্যে কোটা রয়েছে।

অ্যান্টিগ্র্যাভিটি আপনার সিস্টেমে স্থানীয়ভাবে ইনস্টল করতে হবে। এই প্রোডাক্টটি ম্যাক, উইন্ডোজ এবং নির্দিষ্ট লিনাক্স ডিস্ট্রিবিউশনে পাওয়া যায়। আপনার নিজের মেশিন ছাড়াও, নিম্নলিখিত জিনিসগুলোর প্রয়োজন হবে:

  • একটি জিমেইল অ্যাকাউন্ট (ব্যক্তিগত জিমেইল অ্যাকাউন্ট)।
  • একটি গুগল ক্লাউড অ্যাকাউন্ট এবং গুগল ক্লাউড প্রজেক্ট
  • ক্রোমের মতো একটি ওয়েব ব্রাউজার যা গুগল ক্লাউড কনসোল এবং ক্লাউড শেল সমর্থন করে।

২. সেটআপ এবং প্রয়োজনীয়তা

প্রজেক্ট সেটআপ

একটি গুগল ক্লাউড প্রজেক্ট তৈরি করুন

  1. গুগল ক্লাউড কনসোলের প্রজেক্ট সিলেক্টর পেজে, একটি গুগল ক্লাউড প্রজেক্ট নির্বাচন করুন বা তৈরি করুন
  2. আপনার ক্লাউড প্রোজেক্টের জন্য বিলিং চালু আছে কিনা তা নিশ্চিত করুন। কোনো প্রোজেক্টে বিলিং চালু আছে কিনা তা কীভাবে পরীক্ষা করবেন, তা জেনে নিন।

এই কোডল্যাবটি সকল স্তরের (শিক্ষানবিশ সহ) ব্যবহারকারী এবং ডেভেলপারদের জন্য ডিজাইন করা হয়েছে।

৩. স্থাপন

আপনার যদি আগে থেকে Antigravity ইনস্টল করা না থাকে, তাহলে চলুন Antigravity ইনস্টল করা দিয়ে শুরু করা যাক। বর্তমানে পণ্যটি প্রিভিউয়ের জন্য উপলব্ধ এবং আপনি আপনার ব্যক্তিগত Gmail অ্যাকাউন্ট ব্যবহার করে এটি দিয়ে কাজ শুরু করতে পারেন।

ডাউনলোড পৃষ্ঠায় যান এবং আপনার ক্ষেত্রে প্রযোজ্য উপযুক্ত অপারেটিং সিস্টেম সংস্করণে ক্লিক করুন। অ্যাপ্লিকেশন ইনস্টলারটি চালু করুন এবং আপনার মেশিনে এটি ইনস্টল করুন। ইনস্টলেশন সম্পন্ন হলে, অ্যান্টিগ্র্যাভিটি অ্যাপ্লিকেশনটি চালু করুন।

সেটআপের সময় গুরুত্বপূর্ণ পদক্ষেপ:

  • সেটআপ পদ্ধতি নির্বাচন করুন: এই কোডল্যাবের জন্য আমরা নতুন করে শুরু করার পরামর্শ দিই।
  • পর্যালোচনা-ভিত্তিক উন্নয়ন (প্রস্তাবিত) : এই বিকল্পটি বেছে নিন। এটি এজেন্টকে কোনো সিদ্ধান্ত নিয়ে অনুমোদনের জন্য ব্যবহারকারীর কাছে ফিরে আসার সুযোগ দেয়, যা পরিকাঠামো পরিচালনার জন্য অত্যন্ত গুরুত্বপূর্ণ।

এরপর, আপনার এডিটর কনফিগার করুন এবং গুগলে সাইন ইন করুন। সবশেষে, ব্যবহারের শর্তাবলী গ্রহণ করুন।

৪. পরিকাঠামো স্থাপন: GKE ও কনফিগারেশন কানেক্টর

স্কিলটি তৈরি করার আগে, আপনার এমন একটি গুগল ক্লাউড এনভায়রনমেন্ট প্রয়োজন যেখানে কনফিগ কানেক্টর (KCC) ম্যানুয়ালি ইনস্টল করা এবং নেমস্পেসড মোডে কনফিগার করা আছে। এটি আপনাকে GCP রিসোর্সগুলোকে কুবারনেটিস অবজেক্ট হিসেবে পরিচালনা করার সুযোগ দেয়।

ধাপ ০: আপনার পরিবেশ প্রস্তুত করুন

১. ক্লাস্টারের পূর্বশর্তসমূহ

প্রয়োজনীয় বৈশিষ্ট্যগুলো সক্রিয় করে একটি নতুন GKE ক্লাস্টার তৈরি করুন:

# Set your variables
export PROJECT_ID=$(gcloud config get-value project)
export CLUSTER_NAME="kcc-ops-cluster"
export REGION="us-central1"

# Create the cluster
gcloud container clusters create ${CLUSTER_NAME} \
    --region ${REGION} \
    --release-channel "regular" \
    --workload-pool=${PROJECT_ID}.svc.id.goog \
    --logging=SYSTEM \
    --monitoring=SYSTEM

# Get cluster credentials
gcloud container clusters get-credentials ${CLUSTER_NAME} --region ${REGION}

২. কনফিগ কানেক্টর অপারেটর ইনস্টল করুন

অপারেটর আপনার ইনস্টলেশনটি হালনাগাদ রাখে।

# Download the latest Config Connector operator
gcloud storage cp gs://configconnector-operator/latest/release-bundle.tar.gz release-bundle.tar.gz

# Extract the bundle
tar zxvf release-bundle.tar.gz

# Install the operator (Standard Cluster)
kubectl apply -f operator-system/configconnector-operator.yaml

৩. নেমস্পেসড মোড কনফিগার করুন

অপারেটিং মোড নির্দিষ্ট করার জন্য একটি ConfigConnector রিসোর্স তৈরি করুন।

# configconnector.yaml
apiVersion: core.cnrm.cloud.google.com/v1beta1
kind: ConfigConnector
metadata:
  name: configconnector.core.cnrm.cloud.google.com
spec:
  mode: namespaced
  stateIntoSpec: Absent
kubectl apply -f configconnector.yaml

৪. একটি আইডেন্টিটি এবং নেমস্পেস তৈরি করুন

এই ল্যাবের জন্য আমরা default নেমস্পেস এবং একটি ডেডিকেটেড গুগল সার্ভিস অ্যাকাউন্ট (GSA) ব্যবহার করব।

# Set your variables
export PROJECT_ID=$(gcloud config get-value project)
export NAMESPACE="default"

# Create the Google Service Account
gcloud iam service-accounts create kcc-identity --project ${PROJECT_ID}

# Grant permissions on the project
gcloud projects add-iam-policy-binding ${PROJECT_ID} \
    --member="serviceAccount:kcc-identity@${PROJECT_ID}.iam.gserviceaccount.com" \
    --role="roles/owner"

# Grant Metric Writer permissions
gcloud projects add-iam-policy-binding ${PROJECT_ID} \
    --member="serviceAccount:kcc-identity@${PROJECT_ID}.iam.gserviceaccount.com" \
    --role="roles/monitoring.metricWriter"

# Bind GSA to KSA via Workload Identity
gcloud iam service-accounts add-iam-policy-binding \
    kcc-identity@${PROJECT_ID}.iam.gserviceaccount.com \
    --member="serviceAccount:${PROJECT_ID}.svc.id.goog[cnrm-system/cnrm-controller-manager-${NAMESPACE}]" \
    --role="roles/iam.workloadIdentityUser"

৫. নেমস্পেস কনফিগার করুন

নেমস্পেসটি পর্যবেক্ষণ করার জন্য একটি ConfigConnectorContext তৈরি করুন।

# configconnectorcontext.yaml
apiVersion: core.cnrm.cloud.google.com/v1beta1
kind: ConfigConnectorContext
metadata:
  name: configconnectorcontext.core.cnrm.cloud.google.com
  namespace: default
spec:
  googleServiceAccount: "kcc-identity@${PROJECT_ID}.iam.gserviceaccount.com"
  stateIntoSpec: Absent
kubectl apply -f configconnectorcontext.yaml

৬. ইনস্টলেশন যাচাই করুন

default নেমস্পেসের জন্য কন্ট্রোলারটি প্রস্তুত হওয়া পর্যন্ত অপেক্ষা করুন।

kubectl wait -n cnrm-system \
    --for=condition=Ready pod \
    -l cnrm.cloud.google.com/component=cnrm-controller-manager \
    -l cnrm.cloud.google.com/scoped-namespace=default

৫. এজেন্ট ম্যানেজার: মিশন কন্ট্রোল

অ্যান্টিগ্র্যাভিটি ওপেন-সোর্স ভিজ্যুয়াল স্টুডিও কোড (ভিএস কোড)-এর ভিত্তি ব্যবহার করে তৈরি, কিন্তু এটি টেক্সট এডিটিং-এর চেয়ে এজেন্ট ম্যানেজমেন্টকে বেশি প্রাধান্য দিতে ইউজার এক্সপেরিয়েন্সে আমূল পরিবর্তন আনে। এর ইন্টারফেসটি দুটি স্বতন্ত্র প্রধান উইন্ডোতে বিভক্ত: Editor এবং Agent Manager

এজেন্ট ম্যানেজার

অ্যান্টিগ্র্যাভিটি চালু করার পর, ব্যবহারকারীকে সাধারণত এজেন্ট ম্যানেজার স্বাগত জানায়। এই ইন্টারফেসটি একটি মিশন কন্ট্রোল ড্যাশবোর্ড হিসেবে কাজ করে। এটি উচ্চ-স্তরের অর্কেস্ট্রেশনের জন্য ডিজাইন করা হয়েছে, যা ডেভেলপারদের বিভিন্ন ওয়ার্কস্পেস বা টাস্ক জুড়ে অ্যাসিঙ্ক্রোনাসভাবে পরিচালিত একাধিক এজেন্টকে স্পন, মনিটর এবং তাদের সাথে ইন্টারঅ্যাক্ট করার সুযোগ দেয়।

এই দৃষ্টিকোণ থেকে, ডেভেলপার একজন স্থপতির ভূমিকা পালন করেন। তিনি উচ্চ-স্তরের উদ্দেশ্যগুলো নির্ধারণ করেন। এই অনুরোধগুলোর প্রত্যেকটি একটি নির্দিষ্ট এজেন্ট ইনস্ট্যান্স তৈরি করে। ইউজার ইন্টারফেস (UI) এই সমান্তরাল কর্মপ্রবাহগুলোর একটি দৃশ্যায়ন প্রদান করে, যেখানে প্রতিটি এজেন্টের অবস্থা, তাদের তৈরি করা আর্টিফ্যাক্টগুলো (পরিকল্পনা, ফলাফল, পার্থক্য), এবং মানুষের অনুমোদনের জন্য অপেক্ষাধীন কোনো অনুরোধ প্রদর্শিত হয়।

৬. অ্যান্টিগ্র্যাভিটি ব্রাউজার ও আর্টিফ্যাক্টস

অ্যান্টিগ্র্যাভিটি পরিকল্পনা করার এবং তার কাজ সম্পন্ন করার সময় আর্টিফ্যাক্ট তৈরি করে। এগুলো হলো সমৃদ্ধ মার্কডাউন ফাইল, আর্কিটেকচার ডায়াগ্রাম, ছবি, ব্রাউজার রেকর্ডিং এবং কোড ডিফস।

প্রত্নবস্তুগুলো "বিশ্বাসের ব্যবধান" সমাধান করে।

যখন কোনো এজেন্ট দাবি করে, "আমি বাগটি ঠিক করে ফেলেছি," তখন তা যাচাই করার জন্য ডেভেলপারকে আগে কোডটি পড়তে হতো। অ্যান্টিগ্র্যাভিটিতে, এজেন্ট এটি প্রমাণ করার জন্য একটি আর্টিফ্যাক্ট তৈরি করে।

প্রত্নবস্তু

অ্যান্টিগ্র্যাভিটি দ্বারা উৎপাদিত প্রধান নিদর্শনগুলো হলো:

  • Task Lists : কোড লেখার আগে তৈরি করা একটি সুসংগঠিত পরিকল্পনা।
  • Implementation Plan : প্রযুক্তিগত বিবরণসহ পরিকল্পিত পরিবর্তনসমূহ।
  • Walkthrough : পরিবর্তনগুলোর সারসংক্ষেপ এবং সেগুলো কীভাবে পরীক্ষা করতে হয়।
  • Browser Recordings : UI যাচাইকরণের জন্য ব্রাউজার সেশনের ভিডিও রেকর্ড।

অ্যান্টিগ্র্যাভিটি ব্রাউজার

যখন এজেন্টের ওয়েবের সাথে যোগাযোগ করার প্রয়োজন হয়, তখন এটি একটি ব্রাউজার সাবএজেন্টকে আহ্বান করে। এই সাবএজেন্টটি ক্লিক করতে, স্ক্রল করতে, টাইপ করতে এবং কনসোল লগ পড়তে পারে। অ্যান্টিগ্র্যাভিটি-পরিচালিত ব্রাউজারের মধ্যে খোলা পৃষ্ঠাগুলিতে কাজ করার জন্য এটি একটি বিশেষায়িত মডেল ব্যবহার করে।

৭. সম্পাদকের অভিজ্ঞতা

এডিটরটি ভিএস কোডের পরিচিতি ধরে রেখেছে। এতে স্ট্যান্ডার্ড ফাইল এক্সপ্লোরার, সিনট্যাক্স হাইলাইটিং এবং এক্সটেনশন ইকোসিস্টেম অন্তর্ভুক্ত রয়েছে।

প্রধান সম্পাদক বৈশিষ্ট্য:

  • স্বয়ংক্রিয় সম্পূর্ণতা : ট্যাব চাপলে স্মার্ট সাজেশন গৃহীত হয়।
  • ইম্পোর্ট করার ট্যাব : অনুপস্থিত ডিপেন্ডেন্সিগুলো যোগ করার পরামর্শ দেয়।
  • কমান্ড ( Cmd + I ) : স্বাভাবিক ভাষা ব্যবহার করে ইনলাইন কমপ্লিশন চালু করুন।
  • এজেন্ট সাইড প্যানেল ( Cmd + L ) : প্রশ্ন জিজ্ঞাসা করতে বা @ ব্যবহার করে ফাইল উল্লেখ করতে এজেন্ট প্যানেলটি টগল করুন।

৮. মতামত প্রদান

অ্যান্টিগ্র্যাভিটির মূল বৈশিষ্ট্য হলো অনায়াসে আপনার মতামত সংগ্রহ করার ক্ষমতা। এই আর্টিফ্যাক্টগুলো হলো গুগল ডকস-এর কমেন্ট স্টাইলের মাধ্যমে এজেন্টকে মতামত জানানোর একটি উপায়।

যখনই আপনি কোনো পরিকল্পনা বা কাজে মন্তব্য যোগ করবেন, মন্তব্যটি জমা দিতে ভুলবেন না। এটি এজেন্টকে আপনার কাঙ্ক্ষিত পথে পরিচালিত করে।

৯. কেসিসি অপারেশনস দক্ষতা গড়ে তোলা

এখন যেহেতু আপনি প্ল্যাটফর্মটি বুঝতে পেরেছেন, চলুন KCC Ops Skill-টি তৈরি করা যাক।

Kubernetes Config Connector (KCC) আপনাকে GCP রিসোর্সসমূহকে K8s অবজেক্ট হিসেবে পরিচালনা করার সুযোগ দেয়। তবে, কনফিগারেশনের পরিবর্তন, নিয়ম লঙ্ঘন এবং দুর্ঘটনাবশত রিসোর্স পুনরায় তৈরি হওয়া রোধ করার জন্য এতে সুরক্ষাব্যবস্থার প্রয়োজন হয়।

ধাপ ১: দক্ষতার কাঠামো তৈরি করুন

আপনার ওয়ার্কস্পেস রুটে, আপনার স্কিলের জন্য ডিরেক্টরি কাঠামো তৈরি করুন:

mkdir -p .agents/skills/kcc-ops/scripts
mkdir -p .agents/skills/kcc-ops/resources/policies/templates
mkdir -p .agents/skills/kcc-ops/resources/policies/constraints

ধাপ ২: SKILL.md (মস্তিষ্ক) তৈরি করুন।

SKILL.md ফাইলটি এজেন্টের মেটাডেটা এবং মূল "গোল্ডেন রুল" নির্ধারণ করে। .agents/skills/kcc-ops/SKILL.md তৈরি করুন:

---
name: kcc-ops
description: Assists with Config Connector (KCC) configuration, resource generation, and troubleshooting on Google Cloud.
---

# Config Connector (KCC) Operations Skill

Use this skill to manage Google Cloud resources using Kubernetes-style configuration (Config Connector).

## 🛑 GOLDEN RULE: Separate Generation from Application

**NEVER generate and apply a manifest in a single autonomous step.**

1. **Craft:** Write the generated manifest to a local file.
2. **Analyze:** Present the manifest to the user. Perform Impact Analysis and Dry Runs. Explain the consequences of the change (e.g., "If this topic is deleted, the attached subscription becomes orphaned").
3. **Wait:** Pause execution and explicitly wait for user permission to proceed.
4. **Apply:** Only run `kubectl apply` *after* the user has reviewed the manifest and the impact analysis, and then unequivocally confirmed you should proceed.

## Core Responsibilities

0. **Context Verification**: Verify the execution context (cluster, namespace, GCP project, user account) with the user before performing any operations.
1. **Installation & Health**: Verify KCC is properly installed and healthy on the target cluster.
2. **Resource Inventory**: Query and summarize existing KCC resources within a namespace.
3. **Brownfield Bulk Export (Adoption)**: Export existing GCP project resources into valid KCC YAML manifests.
4. **Manifest Generation**: Generate valid YAML manifests for GCP resources using KCC CRDs.
5. **Impact Analysis**: Identify ancillary services and resources (e.g., Cloud Run, Apps) that depend on a resource being modified.
6. **Change Differentiation**: Generate diff summaries for resource edits to support change control.
7. **Policy Compliance**: Vet KCC manifests against OPA/Gatekeeper policies.
8. **Troubleshooting**: Analyze resource status, and consult the troubleshooting guide to resolve reconciliation issues.

## Guidelines for Operations

### 0. Context Verification

Before performing **any operations or executing commands** (including health checks), you **MUST** verify the current execution context and obtain explicit user confirmation.

1. **Read Context:** Use commands like `kubectl config current-context`, `kubectl config view --minify -o jsonpath='{.contexts[0].context.namespace}'`, `gcloud config get-value project`, and `gcloud config get-value account` to determine the active environment.
2. **Present & Ask:** Show this information to the user clearly (e.g., "I see my context is X, namespace is Y, project is Z, and account is A. Is this correct?").
3. **Wait:** Do not proceed with any other steps or scripts until the user has confirmed or provided corrections.

### 1. Installation & Health Check

Before performing operations, ensure the environment is ready:

- **Automation**: You MUST use `./scripts/check-health.sh` to verify namespaces, controllers, and CRDs. Do not use manual kubectl commands for health checks, as the script enforces standard formatting and context verification.

### 2. Resource Inventory & Discovery

To understand the current state of infrastructure:

- **Automation**: You MUST use `./scripts/inventory.sh` to get a summary table of all KCC resources. Do not use manual kubectl queries, as the script is optimized to securely discover all CRDs with context validation.

### 3. Manifest Structure

- All KCC resources belong to the `cnrm.cloud.google.com` API group.
- Use the `cnrm.cloud.google.com/project-id` annotation for cross-project resource management if not using Namespaced Mode.
- Always include `apiVersion`, `kind`, `metadata`, and `spec`.

### 4. Official Resource Reference (Agent Action)

When generating or troubleshooting manifests, you **must not guess** the API schema. Always consult the [Official Config Connector Reference](https://cloud.google.com/config-connector/docs/reference/overview) for the exact API version, kind, and required fields for the specific resource and cross reference with the official [github repository](https://github.com/GoogleCloudPlatform/k8s-config-connector/tree/master/config/crds/resources).

### 5. Troubleshooting Checklist

When a resource is not reconciling (check `kubectl get <kind> <name> -o yaml`):

- **Ready Condition**: Look for `status.conditions` where `type: Ready` and `status: "False"`.
- **Reason/Message**: Check the `reason` and `message` fields in the status conditions.
- **Consult the Guide**: Immediately check `./resources/troubleshooting-guide.md` for definitions of the error reason (e.g. `DependencyInvalid`, `ManagementConflict`) and follow its resolution steps.
- **Common Issues**:
  - Permissions: The KCC service account lacks IAM roles.
  - Quotas: GCP project quota exceeded.
  - Conflicts: Resource already exists or is managed by another tool.
  - Immutable Fields: Attempting to change a field that requires resource recreation. Look for "Update failed" errors related to immutable fields.
  - Reference Resolution: Check if the resource is waiting for a dependency (e.g., `referenced project not found`).

### 6. Impact Analysis (Ancillary Services)

Before modifying a resource (e.g., GCS Bucket, Pub/Sub Topic), verify whatElse depends on it:

- **Reference Search (Cluster-wide)**: Search for other KCC resources that reference the item.

  ```bash
  # Example: Find resources referencing a bucket named 'my-data-bucket'
  kubectl get-all -n <namespace> -o yaml | grep -C 5 "my-data-bucket"
  ```

- **IAM-based Analysis**: Check for IAM Service Accounts that have roles on the specific resource. A Cloud Run job or GKE Workload Identity might be using those permissions.
- **Common Ancillary Dependencies**:
  - **Storage Buckets**: Look for Cloud Run/GKE mounts (CSI), Cloud Functions triggers, or Dataflow jobs.
  - **Networks**: Check for Firewall rules, Forwarding rules, and GKE cluster assignments.
  - **IAM Policies**: Changing a policy might break access for external applications not managed by KCC.
- **Resource Graph**: Use `gcloud asset search-all-resources` to find resources that might have implicit links.

### 3. Policy Compliance & Best Practices

Evaluate KCC manifests against security and governance policies. The vetting tool supports three source modes:

- **Built-in Mode (Default)**: Uses the skill's high-fidelity `v1beta1` library (300+ Anthos constraints).
  - `Usage: ./scripts/vet-policy.sh <manifest-path>`
- **Remote Mode**: Clones and vets against an external Git repository.
  - `Usage: ./scripts/vet-policy.sh <manifest-path> <repo-url> [git-ref]`
  - ⚠️ **Note**: External libraries like the legacy GCP Policy Library may be out-of-date and cause schema validation errors with modern `gator`.
- **Local Mode**: Vets against a local directory of policies.
  - `Usage: ./scripts/vet-policy.sh <manifest-path> /path/to/local/policies`

**Interaction Model:**

1. Call `./scripts/vet-policy.sh` with the appropriate arguments.
2. Interpret the `=== KCC Best Practices ===` and `=== OPA/Gatekeeper ===` reports.
3. Supplement automated findings with manual review for specific security features not yet covered by OPA (e.g., `publicAccessPrevention: enforced`, `versioning: {enabled: true}`).

  ```bash
  # Run the skill's helper script (repo URL and branch are optional)
  ./scripts/vet-policy.sh manifest.yaml [policy-repo-url] [policy-ref]
  ```

## Skill Assets

This skill includes additional resources to streamline operations:

- **`scripts/`**: Automation scripts (e.g., `vet-policy.sh`, `bulk-export.sh`).
- **`examples/`**: Reference KCC manifests (e.g., `restricted-bucket.yaml`).
- **`resources/`**: Common templates, documentation snippets, and troubleshooting guides (e.g., `troubleshooting-guide.md`).

### 4. Safety Rails for Applying Manifests

Before applying any KCC manifest update to an existing resource, you MUST:

- **Verify Immutable Fields**: Call `./scripts/verify-immutable.sh <manifest-path>` to detect updates to fields (like `location`, `name`, `project-id`) that trigger destructive resource recreation.
- **Explain Impact**: If destructive changes are detected, you MUST warn the user and explain the downtime/data loss implications before requesting approval.

### 5. Emergency Recovery & Troubleshooting

If a resource is stuck in a "Deletion" or "Error" state:

- **Check for Abondon Flag**: Check if the resource has the `cnrm.cloud.google.com/deletion-policy: abandon` annotation. If it does, you will need to remove the annotation and then force delete the resource.
- **Force Delete**: Call `./scripts/force-delete.sh <kind> <name> [namespace]` to bypass Kubernetes finalizers and remove the resource from the cluster.
- **Orphan Warning**: Inform the user that force-deleting a KCC object may leave an orphaned resource in Google Cloud that requires manual cleanup.

### 6. Change Differentiation

When editing an existing resource, always generate a diff to summarize the change for reviewers or Git history:

- **Local Diff**:

  ```bash
  # Diff a local file against the cluster state
  kubectl diff -f modified-resource.yaml
  ```

- **Commit Summary Template**:

  ```text
  [KCC Change] Update <ResourceName> (<Kind>)
  - Field 'spec.foo' changed from 'X' to 'Y'
  - Impact: Ancillary service <ServiceName> will see updated <Config>
  ```

### 9. Best Practices

- **Namespaced Mode**: Prefer namespaced mode for better isolation.
- **Sensitive Data**: Use `spec.credential.secretRef` or similar for sensitive fields.
- **Resource Naming**: Use consistent naming conventions that match your Kubernetes/GCP standards.
- **Annotations**:
  - `cnrm.cloud.google.com/deletion-policy: abandon`: Keep GCP resource on KCC deletion.
  - `cnrm.cloud.google.com/state-into-spec: absent`: Prevents KCC from syncing GCP state back into the Kubernetes object (useful for avoiding reconciliation loops on fields like node counts).

## Common Resource Examples

### Compute Instance

```yaml
apiVersion: compute.cnrm.cloud.google.com/v1beta1
kind: ComputeInstance
metadata:
  name: instance-sample
  annotations:
    cnrm.cloud.google.com/project-id: "my-project-id"
spec:
  machineType: n1-standard-1
  zone: us-central1-a
  bootDisk:
    initializeParams:
      sourceImage: projects/debian-cloud/global/images/family/debian-11
  networkInterface:
    - networkRef:
        name: default
```

### Storage Bucket

```yaml
apiVersion: storage.cnrm.cloud.google.com/v1beta1
kind: StorageBucket
metadata:
  name: bucket-sample
spec:
  location: US
```

### Pub/Sub Topic & Subscription

```yaml
apiVersion: pubsub.cnrm.cloud.google.com/v1beta1
kind: PubSubTopic
metadata:
  name: order-events-topic
---
apiVersion: pubsub.cnrm.cloud.google.com/v1beta1
kind: PubSubSubscription
metadata:
  name: order-processor-sub
spec:
  topicRef:
    name: order-events-topic
  ackDeadlineSeconds: 30
```

ধাপ ৩: ইনভেন্টরি টুলটি প্রয়োগ করুন

KCC রিসোর্সগুলি খুঁজে বের করার জন্য .agents/skills/kcc-ops/scripts/inventory.sh ফাইলটি তৈরি করুন:

#!/bin/bash
# List all resources in the cnrm.cloud.google.com group
KCC_KINDS=$(kubectl api-resources --no-headers | awk '/\.cnrm\.cloud\.google\.com/ {print $1}')
KCC_KINDS_CSV=$(echo "$KCC_KINDS" | paste -sd, -)

printf "%-40s %-30s %-10s %s\n" "KIND" "NAME" "READY" "STATUS/MESSAGE"
kubectl get "$KCC_KINDS_CSV" -A -o custom-columns="KIND:.kind,NAME:.metadata.name,READY:.status.conditions[?(@.type=='Ready')].status,MSG:.status.conditions[?(@.type=='Ready')].message" --ignore-not-found --no-headers

ধাপ ৪: পলিসি যাচাইয়ের লজিক যোগ করুন

.agents/skills/kcc-ops/scripts/vet-policy.sh তৈরি করুন। এই স্ক্রিপ্টটি OPA পলিসির সাথে ম্যানিফেস্টগুলো যাচাই করার জন্য gator ব্যবহার করবে:

#!/bin/bash
MANIFEST=$1
SKILL_ROOT=$(dirname "$(dirname "$0")")
POLICY_SRC="$SKILL_ROOT/resources/policies"

echo "=== OPA/Gatekeeper Policy Vetting ==="
if command -v gator >/dev/null 2>&1; then
    gator test -f "$MANIFEST" -f "$POLICY_SRC/templates" -f "$POLICY_SRC/constraints"
else
    echo "Gator not found. Skipping OPA audit."
fi

ধাপ ৫: অপরিবর্তনীয় ফিল্ড সুরক্ষা বাস্তবায়ন করুন

এটি একটি গুরুত্বপূর্ণ নিরাপত্তা রেল। .agents/skills/kcc-ops/scripts/verify-immutable.sh ফাইলটি তৈরি করুন:

#!/bin/bash
MANIFEST=$1
KIND=$(grep "^kind:" "$MANIFEST" | awk '{print $2}')
NAME=$(grep "name:" "$MANIFEST" | head -n 1 | awk '{print $2}')

# Check for changes in common immutable fields
IMMUTABLE_FIELDS=("location" "project-id" "name" "zone" "region")
TEMP_FILE=$(mktemp)
kubectl get "$KIND" "$NAME" -o yaml > "$TEMP_FILE" 2>/dev/null

for field in "${IMMUTABLE_FIELDS[@]}"; do
    NEW=$(grep "$field:" "$MANIFEST" | awk '{print $2}')
    OLD=$(grep "$field:" "$TEMP_FILE" | awk '{print $2}')
    if [ -n "$NEW" ] && [ -n "$OLD" ] && [ "$NEW" != "$OLD" ]; then
        echo "🚨 WARNING: Immutable field '$field' is changing! Potential resource recreation."
    fi
done
rm "$TEMP_FILE"

ধাপ ৬: জরুরি পুনরুদ্ধার (জোরপূর্বক মুছে ফেলা)

.agents/skills/kcc-ops/scripts/force-delete.sh তৈরি করুন:

#!/bin/bash
KIND=$1; NAME=$2; NS=${3:-default}
echo "Removing finalizers for $KIND/$NAME in $NS..."
kubectl patch "$KIND" "$NAME" -n "$NS" -p '{"metadata":{"finalizers":null}}' --type=merge
kubectl delete "$KIND" "$NAME" -n "$NS" --wait=false

ধাপ ৭: সম্পদ চূড়ান্ত করুন

সকল স্ক্রিপ্টকে নির্বাহযোগ্য করুন:

chmod +x .agents/skills/kcc-ops/scripts/*.sh

১০. আপনার নতুন দক্ষতা পরীক্ষা করা

এখন, একটি নতুন কথোপকথন শুরু করুন এবং আপনার দক্ষতা পরীক্ষা করুন:

  1. ডিসকভারি : @kcc-ops Show me all KCC resources in my cluster.
  2. সম্মতি : একটি StorageBucket সহ bucket.yaml নামে একটি ফাইল তৈরি করুন। অনুরোধ: @kcc-ops Vet my bucket.yaml manifest.
  3. নিরাপত্তা : bucket.yaml এ বিদ্যমান কোনো বাকেটের location আপডেট করার চেষ্টা করুন। জিজ্ঞাসা: @kcc-ops Verify my bucket.yaml for immutable changes.

লক্ষ্য করুন, এজেন্টটি কীভাবে বুদ্ধিমত্তার সাথে সঠিক স্ক্রিপ্টটি বেছে নেয় এবং আপনার SKILL.md থেকে "সোনালী নিয়ম" অনুসরণ করে।

১১. এজেন্টকে সুরক্ষিত করা

একটি এআই এজেন্টকে আপনার টার্মিনালে অ্যাক্সেস দেওয়া শক্তিশালী একটি বিষয়, কিন্তু এর জন্য নিয়ন্ত্রণ প্রয়োজন।

Antigravity - Settings - Terminal- এ যান এবং Allow ListDeny List দেখুন।

  • অনুমতি তালিকা : এখানে ls , kubectl get , এবং আপনার স্কিল স্ক্রিপ্টগুলো যোগ করুন।
  • ডিনাই লিস্ট : এজেন্ট যাতে সর্বদা অনুমতি চায়, তা নিশ্চিত করতে sudo , rm -rf বা অন্যান্য ক্ষতিকর কমান্ড যোগ করুন।

১২. উপসংহার

অভিনন্দন! আপনি অ্যান্টিগ্র্যাভিটি ইনস্টল করা থেকে একটি উচ্চ-মানের কেসিসি অপারেশনস স্কিল তৈরি করার পর্যায়ে পৌঁছেছেন।

আপনি শিখেছেন:

  • কাস্টম ব্যাশ টুল ব্যবহার করে এজেন্টকে কীভাবে সম্প্রসারিত করা যায়।
  • কিভাবে পরিচালনগত "সোনালী নিয়মাবলী" একটি SKILL.md ফাইলে অন্তর্ভুক্ত করা যায়।
  • জটিল অবকাঠামো ব্যবস্থাপনার জন্য কীভাবে নিরাপত্তা বেষ্টনী প্রদান করা যায়।

এরপর কী?

আপনার resources/policies ফোল্ডারটি আরও OPA সীমাবদ্ধতা দিয়ে প্রসারিত করুন, অথবা ক্লাস্টারের প্রস্তুতি পরীক্ষা স্বয়ংক্রিয় করতে একটি check-health.sh স্ক্রিপ্ট যোগ করুন!